Merge "Do not observe when Reload" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / texture-manager / texture-manager-impl.h
index 54db840..a753099 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_TEXTURE_MANAGER_IMPL_H
 
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
 // EXTERNAL INCLUDES
 #include <dali/devel-api/adaptor-framework/animated-image-loading.h>
 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
+#include <dali/integration-api/processor-interface.h>
 #include <dali/public-api/adaptor-framework/encoded-image-buffer.h>
 #include <dali/public-api/adaptor-framework/round-robin-container-view.h>
 #include <dali/public-api/common/dali-vector.h>
@@ -51,7 +52,7 @@ class TextureAsyncLoadingHelper;
  * Texture caching is provided and performed by TextureCacheManager.
  * TextureUploadObserver.LoadComplete called when async load completed.
  */
-class TextureManager : public ConnectionTracker
+class TextureManager : public ConnectionTracker, public Integration::Processor
 {
 public:
   // Copy enum and types and const values that TextureManager will use.
@@ -185,7 +186,8 @@ public:
    * @param[in] samplingMode          The SamplingMode to use
    * @param[in, out] maskInfo         Mask info structure
    * @param[in] synchronousLoading    true if the URL should be loaded synchronously
-   * @param[out] textureId,           The textureId of the URL
+   * @param[in, out] textureId        The textureId of the URL. It is also be used to check the previous textureId
+   *                                  what requestor had. It will be used only ReloadPolicy::FORCED for now.
    * @param[out] textureRect          The rectangle within the texture atlas that this URL occupies,
    *                                  this is the rectangle in normalized coordinates.
    * @param[out] textureRectSize      The rectangle within the texture atlas that this URL occupies,
@@ -226,17 +228,6 @@ public:
     TextureManager::MultiplyOnLoad&     preMultiplyOnLoad);
 
   /**
-   * @brief Remove a Texture from the TextureManager.
-   *
-   * Textures are cached and therefore only the removal of the last
-   * occurrence of a Texture will cause its removal internally.
-   *
-   * @param[in] textureId The ID of the Texture to remove.
-   * @param[in] textureObserver The texture observer.
-   */
-  void Remove(const TextureManager::TextureId& textureId, TextureUploadObserver* textureObserver);
-
-  /**
    * Add an observer to the object.
    * @param[in] observer The observer to add.
    */
@@ -326,9 +317,9 @@ public:
   /**
    * @copydoc TextureCacheManager::AddExternalTexture
    */
-  inline std::string AddExternalTexture(const TextureSet& texture)
+  inline std::string AddExternalTexture(const TextureSet& texture, bool preMultiplied = false)
   {
-    return mTextureCacheManager.AddExternalTexture(texture);
+    return mTextureCacheManager.AddExternalTexture(texture, preMultiplied);
   }
 
   /**
@@ -375,6 +366,7 @@ public: // Load Request API
     TextureManager::MultiplyOnLoad&     preMultiplyOnLoad,
     const bool&                         synchronousLoading = false);
 
+private: // Internal Load Request API
   /**
    * @brief Requests an image load of the given URL, when the texture has
    * have loaded, it will perform a blend with the image mask, and upload
@@ -388,6 +380,7 @@ public: // Load Request API
    * @param[in] url                   The URL of the image to load
    * @param[in] maskTextureId         The texture id of an image to mask this with
    *                                  (can be INVALID if no masking required)
+   * @param[in] previousTextureId     The texture id of an image which the requestor already has before
    * @param[in] contentScale          The scale factor to apply to the image before masking
    * @param[in] desiredSize           The size the image is likely to appear at. This can be set to 0,0 for automatic
    * @param[in] fittingMode           The FittingMode to use
@@ -412,6 +405,7 @@ public: // Load Request API
   TextureId RequestLoad(
     const VisualUrl&                    url,
     const TextureManager::TextureId&    maskTextureId,
+    const TextureManager::TextureId&    previousTextureId,
     const float&                        contentScale,
     const ImageDimensions&              desiredSize,
     const Dali::FittingMode::Type&      fittingMode,
@@ -438,7 +432,6 @@ public: // Load Request API
     StorageType      storageType,
     const bool&      synchronousLoading = false);
 
-private:
   /**
    * @brief Requests an image load of the given URL, when the texture has
    * have loaded, if there is a valid maskTextureId, it will perform a
@@ -452,6 +445,8 @@ private:
    * @param[in] url                   The URL of the image to load
    * @param[in] maskTextureId         The texture id of an image to use as a mask. If no mask is required, then set
    *                                  to INVALID_TEXTURE_ID
+   * @param[in] previousTextureId     The texture id of an image which the requestor already has before. It will be used
+   *                                  when reloadPolicy is FORCED.
    * @param[in] contentScale          The scaling factor to apply to the content when masking
    * @param[in] desiredSize           The size the image is likely to appear at. This can be set to 0,0 for automatic
    * @param[in] fittingMode           The FittingMode to use
@@ -478,6 +473,7 @@ private:
   TextureId RequestLoadInternal(
     const VisualUrl&                    url,
     const TextureManager::TextureId&    maskTextureId,
+    const TextureManager::TextureId&    previousTextureId,
     const float&                        contentScale,
     const Dali::ImageDimensions&        desiredSize,
     const Dali::FittingMode::Type&      fittingMode,
@@ -515,6 +511,34 @@ private:
     const bool&                      loadYuvPlanes,
     std::vector<Devel::PixelBuffer>& pixelBuffers);
 
+public: // Remove Request API
+  /**
+   * @brief Request Remove a Texture from the TextureManager.
+   *
+   * Textures are cached and therefore only the removal of the last
+   * occurrence of a Texture will cause its removal internally.
+   *
+   * @param[in] textureId The ID of the Texture to remove.
+   * @param[in] textureObserver The texture observer.
+   */
+  void RequestRemove(const TextureManager::TextureId& textureId, TextureUploadObserver* textureObserver);
+
+private:
+  /**
+   * @brief Remove a Texture from the TextureManager.
+   *
+   * Textures are cached and therefore only the removal of the last
+   * occurrence of a Texture will cause its removal internally.
+   *
+   * @param[in] textureId The ID of the Texture to remove.
+   */
+  void Remove(const TextureManager::TextureId& textureId);
+
+  /**
+   * @brief Initiate remove of texture queued.
+   */
+  void ProcessRemoveQueue();
+
 private:
   // Load and queue
 
@@ -541,7 +565,7 @@ private:
   void LoadOrQueueTexture(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer);
 
   /**
-   * @brief Queue a texture load to be subsequently handled by ProcessQueuedTextures.
+   * @brief Queue a texture load to be subsequently handled by ProcessLoadQueue.
    * @param[in] textureInfo The TextureInfo struct associated with the Texture
    * @param[in] observer The observer wishing to observe the texture upload
    */
@@ -560,11 +584,6 @@ private:
   void ProcessLoadQueue();
 
   /**
-   * @brief Initiate remove of texture queued whilst NotifyObservers invoking callbacks.
-   */
-  void ProcessRemoveQueue();
-
-  /**
    * Add the observer to the observer list
    * @param[in] textureInfo The TextureInfo struct associated with the texture
    * @param[in] observer The observer wishing to observe the texture upload
@@ -633,6 +652,12 @@ public:
    */
   void AsyncLoadComplete(const TextureManager::TextureId& textureId, std::vector<Devel::PixelBuffer>& pixelBuffers);
 
+protected: // Implementation of Processor
+  /**
+   * @copydoc Dali::Integration::Processor::Process()
+   */
+  void Process(bool postProcessor) override;
+
 private:
   /**
    * Deleted copy constructor.
@@ -651,14 +676,19 @@ private:
    */
   void ObserverDestroyed(TextureUploadObserver* observer);
 
-private:                                                             // Member Variables:
-  TextureCacheManager                        mTextureCacheManager;   ///< Manager the life-cycle and caching of Textures
-  std::unique_ptr<TextureAsyncLoadingHelper> mAsyncLoader;           ///< The Asynchronous image loader used to provide all local async loads
-  Dali::Vector<LifecycleObserver*>           mLifecycleObservers;    ///< Lifecycle observers of texture manager
-  Dali::Vector<QueueElement>                 mLoadQueue;             ///< Queue of textures to load after NotifyObservers
-  Dali::Vector<QueueElement>                 mRemoveQueue;           ///< Queue of textures to remove after NotifyObservers
-  TextureManager::TextureId                  mLoadingQueueTextureId; ///< TextureId when it is loading. it causes Load Textures to be queued.
-  bool                                       mLoadYuvPlanes;         ///< A global flag to specify if the image should be loaded as yuv planes
+private:                                    // Member Variables:
+  TextureCacheManager mTextureCacheManager; ///< Manager the life-cycle and caching of Textures
+
+  std::unique_ptr<TextureAsyncLoadingHelper> mAsyncLoader;        ///< The Asynchronous image loader used to provide all local async loads
+  Dali::Vector<LifecycleObserver*>           mLifecycleObservers; ///< Lifecycle observers of texture manager
+
+  Dali::Vector<QueueElement> mLoadQueue;             ///< Queue of textures to load after NotifyObservers
+  TextureManager::TextureId  mLoadingQueueTextureId; ///< TextureId when it is loading. it causes Load Textures to be queued.
+
+  Dali::Vector<TextureManager::TextureId> mRemoveQueue; ///< Queue of textures to remove at PostProcess. It will be cleared after PostProcess.
+
+  bool mLoadYuvPlanes;             ///< A global flag to specify if the image should be loaded as yuv planes
+  bool mRemoveProcessorRegistered; ///< Flag if remove processor registered or not.
 };
 
 } // namespace Internal