Caching texture instead of textureSet in TextureManager
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / texture-manager / texture-manager-impl.h
index ee06c53..777c4df 100644 (file)
@@ -80,6 +80,8 @@ public:
     TextureManager::TextureId mAlphaMaskId;
     float                     mContentScaleFactor;
     bool                      mCropToMask;
+    bool                      mPreappliedMasking;
+    bool                      mMaskImageLoadingFailed;
   };
   using MaskingDataPointer = std::unique_ptr<MaskingData>;
 
@@ -112,27 +114,29 @@ public:
    * The parameters are used to specify how the animated image is loaded.
    * The observer has the LoadComplete method called when the load is ready.
    *
-   * @param[in] animatedImageLoading  The AnimatedImageLoading that contain the animated image information
-   * @param[in] frameIndex            The frame index to load.
-   * @param[in] samplingMode          The SamplingMode to use
-   * @param[in] synchronousLoading    true if the frame should be loaded synchronously
-   * @param[out] textureId            The textureId of the frame
-   * @param[in] wrapModeU             Horizontal Wrap mode
-   * @param[in] wrapModeV             Vertical Wrap mode
-   * @param[in] textureObserver       The client object should inherit from this and provide the "UploadCompleted" virtual.
-   *                                  This is called when an image load completes (or fails).
+   * @param[in]  url                   The URL of the image to load
+   * @param[in]  animatedImageLoading  The AnimatedImageLoading that contain the animated image information
+   * @param[in]  frameIndex            The frame index to load.
+   * @param[out] textureId             The textureId of the frame
+   * @param[in, out] maskInfo          Mask info structure
+   * @param[in]  samplingMode          The SamplingMode to use
+   * @param[in]  synchronousLoading    true if the frame should be loaded synchronously
+   * @param[in]  textureObserver       The client object should inherit from this and provide the "LoadCompleted" virtual.
+   *                                   This is called when an image load completes (or fails).
+   * @param[in,out] preMultiplyOnLoad  True if the image color should be multiplied by it's alpha. Set to false if the
+   *                                   image has no alpha channel
    *
-   * @return                          The texture set containing the frame of animated image, or empty if still loading.
+   * @return                           The texture set containing the frame of animated image, or empty if still loading.
    */
-  TextureSet LoadAnimatedImageTexture(
-    Dali::AnimatedImageLoading      animatedImageLoading,
-    const std::uint32_t&            frameIndex,
-    const Dali::SamplingMode::Type& samplingMode,
-    const bool&                     synchronousLoading,
-    TextureManager::TextureId&      textureId,
-    const Dali::WrapMode::Type&     wrapModeU,
-    const Dali::WrapMode::Type&     wrapModeV,
-    TextureUploadObserver*          textureObserver);
+  TextureSet LoadAnimatedImageTexture(const VisualUrl&                url,
+                                      Dali::AnimatedImageLoading      animatedImageLoading,
+                                      const uint32_t&                 frameIndex,
+                                      TextureManager::TextureId&      textureId,
+                                      MaskingDataPointer&             maskInfo,
+                                      const Dali::SamplingMode::Type& samplingMode,
+                                      const bool&                     synchronousLoading,
+                                      TextureUploadObserver*          textureObserver,
+                                      TextureManager::MultiplyOnLoad& preMultiplyOnLoad);
 
   /**
    * @brief Requests an image load of the given URL to get PixelBuffer.
@@ -145,7 +149,7 @@ public:
    * @param[in] fittingMode           The FittingMode to use
    * @param[in] samplingMode          The SamplingMode to use
    * @param[in] synchronousLoading    true if the URL should be loaded synchronously
-   * @param[in] textureObserver       The client object should inherit from this and provide the "UploadCompleted" virtual.
+   * @param[in] textureObserver       The client object should inherit from this and provide the "LoadCompleted" virtual.
    *                                  This is called when an image load completes (or fails).
    * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
    * @param[in,out] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if the
@@ -186,12 +190,10 @@ public:
    *                                  be loaded, and marked successful, but this will be set to false.
    *                                  If atlasing succeeds, this will be set to true.
    * @param[out] loadingStatus        The loading status of the texture
-   * @param[in] wrapModeU             Horizontal Wrap mode
-   * @param[in] wrapModeV             Vertical Wrap mode
-   * @param[in] textureObserver       The client object should inherit from this and provide the "UploadCompleted" virtual.
+   * @param[in] textureObserver       The client object should inherit from this and provide the "LoadCompleted" virtual.
    *                                  This is called when an image load completes (or fails).
    * @param[in] atlasObserver         This is used if the texture is atlased, and will be called instead of
-   *                                  textureObserver.UploadCompleted
+   *                                  textureObserver.LoadCompleted
    * @param[in] imageAtlasManager     The atlas manager to use for atlasing textures
    * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
    * @param[in] reloadPolicy          Forces a reload of the texture even if already cached
@@ -212,8 +214,6 @@ public:
     Dali::ImageDimensions&              textureRectSize,
     bool&                               atlasingStatus,
     bool&                               loadingStatus,
-    const Dali::WrapMode::Type&         wrapModeU,
-    const Dali::WrapMode::Type&         wrapModeV,
     TextureUploadObserver*              textureObserver,
     AtlasUploadObserver*                atlasObserver,
     ImageAtlasManagerPtr                imageAtlasManager,
@@ -254,6 +254,20 @@ public:
    */
   Geometry GetRenderGeometry(const TextureManager::TextureId& textureId, std::uint32_t& frontElements, std::uint32_t& backElements);
 
+  /**
+   * @brief Returns the textureSet in texture manager.
+   * @param[in] textureId Id of the texture
+   * @return The textureSet in texture manager. These textures include YUV textures or images and masks.
+   */
+  TextureSet GetTextureSet(const TextureManager::TextureId& textureId);
+
+  /**
+   * @brief Returns the textureSet in texture manager.
+   * @param[in] textureInfo the information of the texture
+   * @return The textureSet in texture manager. These textures include YUV textures or images and masks.
+   */
+  TextureSet GetTextureSet(const TextureManager::TextureInfo& textureInfo);
+
 public:
   // API list that need to access TextureCacheManager.
 
@@ -266,11 +280,11 @@ public:
   }
 
   /**
-   * @copydoc TextureCacheManager::GetTextureSet
+   * @copydoc TextureCacheManager::GetTexture
    */
-  inline TextureSet GetTextureSet(const TextureManager::TextureId& textureId)
+  inline Texture GetTexture(const TextureManager::TextureId& textureId)
   {
-    return mTextureCacheManager.GetTextureSet(textureId);
+    return mTextureCacheManager.GetTexture(textureId);
   }
 
   /**
@@ -282,11 +296,11 @@ public:
   }
 
   /**
-   * @copydoc TextureCacheManager::RemoveExternalEncodedImageBuffer
+   * @copydoc TextureCacheManager::RemoveEncodedImageBuffer
    */
-  inline EncodedImageBuffer RemoveExternalEncodedImageBuffer(const std::string& url)
+  inline EncodedImageBuffer RemoveEncodedImageBuffer(const std::string& url)
   {
-    return mTextureCacheManager.RemoveExternalEncodedImageBuffer(url);
+    return mTextureCacheManager.RemoveEncodedImageBuffer(url);
   }
 
   /**
@@ -314,11 +328,11 @@ public:
   }
 
   /**
-   * @copydoc TextureCacheManager::AddExternalEncodedImageBuffer
+   * @copydoc TextureCacheManager::AddEncodedImageBuffer
    */
-  inline std::string AddExternalEncodedImageBuffer(const EncodedImageBuffer& encodedImageBuffer)
+  inline std::string AddEncodedImageBuffer(const EncodedImageBuffer& encodedImageBuffer)
   {
-    return mTextureCacheManager.AddExternalEncodedImageBuffer(encodedImageBuffer);
+    return mTextureCacheManager.AddEncodedImageBuffer(encodedImageBuffer);
   }
 
 public: // Load Request API
@@ -335,8 +349,8 @@ public: // Load Request API
    * @param[in] fittingMode           The FittingMode to use
    * @param[in] samplingMode          The SamplingMode to use
    * @param[in] useAtlasing           Set to USE_ATLAS to attempt atlasing. If atlasing fails, the image will still be loaded, and marked successful,
-   *                                  but "useAtlasing" will be set to false in the "UploadCompleted" callback from the TextureManagerUploadObserver.
-   * @param[in] observer              The client object should inherit from this and provide the "UploadCompleted" virtual.
+   *                                  but "useAtlasing" will be set to false in the "LoadCompleted" callback from the TextureManagerUploadObserver.
+   * @param[in] observer              The client object should inherit from this and provide the "LoadCompleted" virtual.
    *                                  This is called when an image load completes (or fails).
    * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
    * @param[in] reloadPolicy          Forces a reload of the texture even if already cached
@@ -345,7 +359,7 @@ public: // Load Request API
    *                                  default is false.
    * @return                          A TextureId to use as a handle to reference this Texture
    */
-  TextureManager::TextureId RequestLoad(
+  TextureId RequestLoad(
     const VisualUrl&                    url,
     const ImageDimensions&              desiredSize,
     const Dali::FittingMode::Type&      fittingMode,
@@ -376,11 +390,11 @@ public: // Load Request API
    * @param[in] samplingMode          The SamplingMode to use
    * @param[in] useAtlasing           Set to USE_ATLAS to attempt atlasing. If atlasing fails, the image will still
    *                                  be loaded, and marked successful,
-   *                                  but "useAtlasing" will be set to false in the "UploadCompleted" callback from
+   *                                  but "useAtlasing" will be set to false in the "LoadCompleted" callback from
    *                                  the TextureManagerUploadObserver.
    * @param[in] cropToMask            Only used with masking, this will crop the scaled image to the mask size.
    *                                  If false, then the mask will be scaled to fit the image before being applied.
-   * @param[in] observer              The client object should inherit from this and provide the "UploadCompleted"
+   * @param[in] observer              The client object should inherit from this and provide the "LoadCompleted"
    *                                  virtual.
    *                                  This is called when an image load completes (or fails).
    * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
@@ -391,7 +405,7 @@ public: // Load Request API
    *                                  default is false.
    * @return                          A TextureId to use as a handle to reference this Texture
    */
-  TextureManager::TextureId RequestLoad(
+  TextureId RequestLoad(
     const VisualUrl&                    url,
     const TextureManager::TextureId&    maskTextureId,
     const float&                        contentScale,
@@ -410,12 +424,14 @@ public: // Load Request API
    * @brief Requests a masking image to be loaded. This mask is not uploaded to GL,
    * instead, it is stored in CPU memory, and can be used for CPU blending.
    * @param[in] maskUrl            The URL of the mask image to load
+   * @param[in] storageType,       Whether the pixel data is stored in the cache or uploaded to the GPU
    * @param[in] synchronousLoading True if the frame should be loaded synchronously. If you skip this parameter,
    *                               default is false.
    * @return                       A TextureId to use as a handle to reference this mask Texture
    */
-  TextureManager::TextureId RequestMaskLoad(
+  TextureId RequestMaskLoad(
     const VisualUrl& maskUrl,
+    StorageType      storageType,
     const bool&      synchronousLoading = false);
 
 private:
@@ -438,11 +454,11 @@ private:
    * @param[in] samplingMode          The SamplingMode to use
    * @param[in] useAtlasing           Set to USE_ATLAS to attempt atlasing. If atlasing fails, the image will still be
    *                                  loaded, and marked successful, but "useAtlasing" will be set to false in the
-   *                                  "UploadCompleted" callback from the TextureManagerUploadObserver.
+   *                                  "LoadCompleted" callback from the TextureManagerUploadObserver.
    * @param[in] cropToMask            Whether to crop the target after masking, or scale the mask to the image before
    *                                  masking.
    * @param[in] storageType,          Whether the pixel data is stored in the cache or uploaded to the GPU
-   * @param[in] observer              The client object should inherit from this and provide the "UploadCompleted"
+   * @param[in] observer              The client object should inherit from this and provide the "LoadCompleted"
    *                                  virtual.
    *                                  This is called when an image load completes (or fails).
    * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
@@ -455,7 +471,7 @@ private:
    *                                  default is false.
    * @return                          A TextureId to use as a handle to reference this Texture
    */
-  TextureManager::TextureId RequestLoadInternal(
+  TextureId RequestLoadInternal(
     const VisualUrl&                    url,
     const TextureManager::TextureId&    maskTextureId,
     const float&                        contentScale,
@@ -482,14 +498,18 @@ private:
    * @param[in] samplingMode          The SamplingMode to use
    * @param[in] orientationCorrection Whether to use image metadata to rotate or flip the image,
    *                                  e.g., from portrait to landscape
+   * @param[in] loadYuvPlanes         True if the image should be loaded as yuv planes
+   * @param[out] pixelBuffers         The image pixelBuffer
    * @return PixelBuffer of loaded image.
    */
-  Devel::PixelBuffer LoadImageSynchronously(
-    const VisualUrl&                url,
-    const Dali::ImageDimensions&    desiredSize,
-    const Dali::FittingMode::Type&  fittingMode,
-    const Dali::SamplingMode::Type& samplingMode,
-    const bool&                     orientationCorrection);
+  void LoadImageSynchronously(
+    const VisualUrl&                 url,
+    const Dali::ImageDimensions&     desiredSize,
+    const Dali::FittingMode::Type&   fittingMode,
+    const Dali::SamplingMode::Type&  samplingMode,
+    const bool&                      orientationCorrection,
+    const bool&                      loadYuvPlanes,
+    std::vector<Devel::PixelBuffer>& pixelBuffers);
 
 private:
   // Load and queue
@@ -533,7 +553,12 @@ private:
   /**
    * @brief Initiate load of textures queued whilst NotifyObservers invoking callbacks.
    */
-  void ProcessQueuedTextures();
+  void ProcessLoadQueue();
+
+  /**
+   * @brief Initiate remove of texture queued whilst NotifyObservers invoking callbacks.
+   */
+  void ProcessRemoveQueue();
 
   /**
    * Add the observer to the observer list
@@ -544,11 +569,11 @@ private:
 
   /**
    * @brief Performs Post-Load steps including atlasing.
-   * @param[in] textureInfo The struct associated with this Texture
-   * @param[in] pixelBuffer The image pixelBuffer
+   * @param[in] textureInfo  The struct associated with this Texture
+   * @param[in] pixelBuffers The image pixelBuffer
    * @return    True if successful
    */
-  void PostLoad(TextureManager::TextureInfo& textureInfo, Devel::PixelBuffer& pixelBuffer);
+  void PostLoad(TextureManager::TextureInfo& textureInfo, std::vector<Devel::PixelBuffer>& pixelBuffers);
 
   /**
    * Check if there is a texture waiting to be masked. If there
@@ -566,11 +591,10 @@ private:
 
   /**
    * Upload the texture specified in pixelBuffer to the appropriate location
-   * @param[in] pixelBuffer The image data to upload
-   * @param[in] textureInfo The texture info containing the location to
-   * store the data to.
+   * @param[in] pixelBuffers The image data to upload
+   * @param[in] textureInfo  The texture info containing the location to store the data to.
    */
-  void UploadTexture(Devel::PixelBuffer& pixelBuffer, TextureManager::TextureInfo& textureInfo);
+  void UploadTextures(std::vector<Devel::PixelBuffer>& pixelBuffers, TextureManager::TextureInfo& textureInfo);
 
   /**
    * Notify the current observers that the texture upload is complete,
@@ -580,14 +604,22 @@ private:
    */
   void NotifyObservers(TextureManager::TextureInfo& textureInfo, const bool& success);
 
+  /**
+   * Call LoadComplete to the observer.
+   * @param[in] observer    The client object should inherit from this and provide the "LoadCompleted"
+   * @param[in] textureInfo The struct associated with this Texture
+   * @param[in] success     If the pixel data was retrieved successfully and uploaded to GPU
+   */
+  void EmitLoadComplete(TextureUploadObserver* observer, TextureManager::TextureInfo& textureInfo, const bool& success);
+
 public:
   /**
    * @brief Common method to handle loading completion.
    * TextureAsyncLoadingHelper will call this API After async loading finished.
-   * @param[in] textureId   The ID of the texture load complete.
-   * @param[in] pixelBuffer The loaded image data
+   * @param[in] textureId    The ID of the texture load complete.
+   * @param[in] pixelBuffers The loaded image data
    */
-  void AsyncLoadComplete(const TextureManager::TextureId& textureId, Devel::PixelBuffer pixelBuffer);
+  void AsyncLoadComplete(const TextureManager::TextureId& textureId, std::vector<Devel::PixelBuffer>& pixelBuffers);
 
 private:
   /**
@@ -613,9 +645,11 @@ private:                                    // Member Variables:
   RoundRobinContainerView<TextureAsyncLoadingHelper> mAsyncLocalLoaders;  ///< The Asynchronous image loaders used to provide all local async loads
   RoundRobinContainerView<TextureAsyncLoadingHelper> mAsyncRemoteLoaders; ///< The Asynchronous image loaders used to provide all remote async loads
 
-  Dali::Vector<LifecycleObserver*> mLifecycleObservers; ///< Lifecycle observers of texture manager
-  Dali::Vector<LoadQueueElement>   mLoadQueue;          ///< Queue of textures to load after NotifyObservers
-  bool                             mQueueLoadFlag;      ///< Flag that causes Load Textures to be queued.
+  Dali::Vector<LifecycleObserver*>        mLifecycleObservers; ///< Lifecycle observers of texture manager
+  Dali::Vector<LoadQueueElement>          mLoadQueue;          ///< Queue of textures to load after NotifyObservers
+  Dali::Vector<TextureManager::TextureId> mRemoveQueue;        ///< Queue of textures to remove after NotifyObservers
+  bool                                    mQueueLoadFlag;      ///< Flag that causes Load Textures to be queued.
+  bool                                    mLoadYuvPlanes;      ///< A global flag to specify if the image should be loaded as yuv planes
 };
 
 } // namespace Internal