Merge "Do not observe when Reload" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / texture-manager / texture-cache-manager.h
index dbd3e62..75686a1 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_TEXTURE_CACHE_MANAGER_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.
@@ -70,13 +70,14 @@ public:
   static constexpr TextureId         INVALID_TEXTURE_ID  = TextureManagerType::INVALID_TEXTURE_ID;
   static constexpr TextureCacheIndex INVALID_CACHE_INDEX = TextureManagerType::INVALID_CACHE_INDEX;
 
-  using UseAtlas       = TextureManagerType::UseAtlas;
-  using StorageType    = TextureManagerType::StorageType;
-  using LoadType       = TextureManagerType::LoadType;
-  using LoadState      = TextureManagerType::LoadState;
-  using ReloadPolicy   = TextureManagerType::ReloadPolicy;
-  using MultiplyOnLoad = TextureManagerType::MultiplyOnLoad;
-  using TextureInfo    = TextureManagerType::TextureInfo;
+  using UseAtlas            = TextureManagerType::UseAtlas;
+  using StorageType         = TextureManagerType::StorageType;
+  using LoadType            = TextureManagerType::LoadType;
+  using LoadState           = TextureManagerType::LoadState;
+  using ReloadPolicy        = TextureManagerType::ReloadPolicy;
+  using MultiplyOnLoad      = TextureManagerType::MultiplyOnLoad;
+  using TextureInfo         = TextureManagerType::TextureInfo;
+  using ExternalTextureInfo = TextureManagerType::ExternalTextureInfo;
 
 public:
   /**
@@ -102,7 +103,7 @@ public:
   /**
    * @brief Get the current state of a texture
    * @note This API doesn't consider encodedimagebuffer.
-   * @param[in] textureId The texture id to query
+   * @param[in] textureId The texture id to query.defaul value is 0.
    * @return The loading state if the texture is valid, or NOT_STARTED if the textureId
    * is not valid.
    */
@@ -120,16 +121,17 @@ public:
   /**
    * @brief Get the associated texture set if the texture id is valid
    * @param[in] textureId The texture Id to look up
-   * @return the associated texture set, or an empty handle if textureId is not valid
+   * @param[in] textureIndex The texture index to query
+   * @return the associated texture, or an empty handle if textureId is not valid
    */
-  TextureSet GetTextureSet(const TextureCacheManager::TextureId& textureId);
+  Texture GetTexture(const TextureCacheManager::TextureId& textureId, uint32_t textureIndex = 0);
 
   /**
-   * @brief Get the external texture set if the texture id is valid
+   * @brief Get the external texture set information if the texture id is valid
    * @param[in] textureId The texture Id to look up
-   * @return the external texture set, or an empty handle if textureId is not valid
+   * @return the external texture information. Assert if textureId is not valid
    */
-  TextureSet GetExternalTextureSet(const TextureCacheManager::TextureId& textureId);
+  TextureCacheManager::ExternalTextureInfo& GetExternalTextureInfo(const TextureCacheManager::TextureId& textureId);
 
   /**
    * @brief Get the encoded image buffer
@@ -148,9 +150,10 @@ public:
   /**
    * Adds an external texture to the texture manager
    * @param[in] texture The texture to add
+   * @param[in] preMultiplied Whether this external texture preMultiplied or not. Default as false.
    * @return string containing the URL for the texture
    */
-  std::string AddExternalTexture(const TextureSet& texture);
+  std::string AddExternalTexture(const TextureSet& texture, bool preMultiplied);
 
   /**
    * Adds an encoded image buffer to the texture manager
@@ -208,6 +211,7 @@ public:
    * @param[in] useAtlas         True if atlased
    * @param[in] maskTextureId    The masking texture id (or INVALID_TEXTURE_ID)
    * @param[in] cropToMask       True if crop to mask
+   * @param[in] frameIndex       The frame index to use
    * @return                     A hash of the provided data for caching.
    */
   TextureCacheManager::TextureHash GenerateHash(
@@ -217,7 +221,8 @@ public:
     const Dali::SamplingMode::Type&       samplingMode,
     const TextureCacheManager::UseAtlas&  useAtlas,
     const TextureCacheManager::TextureId& maskTextureId,
-    const bool&                           cropToMask);
+    const bool&                           cropToMask,
+    const std::uint32_t&                  frameIndex);
 
   /**
    * @brief Looks up a cached texture by its hash.
@@ -228,10 +233,12 @@ public:
    * @param[in] fittingMode       The FittingMode to use
    * @param[in] samplingMode      The SamplingMode to use
    * @param[in] useAtlas          True if atlased
+   * @param[in] storageType       Whether the pixel data is stored in the cache or uploaded to the GPU
    * @param[in] maskTextureId     Optional texture ID to use to mask this image
+   * @param[in] cropToMask        True if crop to mask
    * @param[in] preMultiplyOnLoad if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha.
    * @param[in] isAnimatedImage   True if the texture is from animated image.
-   * @param[in] cropToMask        True if crop to mask
+   * @param[in] frameIndex        The frame index to use
    * @return                      A TextureCacheIndex of a cached Texture if found. Or INVALID_CACHE_INDEX if not found.
    */
   TextureCacheManager::TextureCacheIndex FindCachedTexture(
@@ -241,10 +248,12 @@ public:
     const Dali::FittingMode::Type&             fittingMode,
     const Dali::SamplingMode::Type&            samplingMode,
     const TextureCacheManager::UseAtlas&       useAtlas,
+    const StorageType&                         storageType,
     const TextureCacheManager::TextureId&      maskTextureId,
     const bool&                                cropToMask,
     const TextureCacheManager::MultiplyOnLoad& preMultiplyOnLoad,
-    const bool&                                isAnimatedImage);
+    const bool&                                isAnimatedImage,
+    const std::uint32_t&                       frameIndex);
 
   /**
    * @brief Append a Texture to the TextureCacheManager.
@@ -263,9 +272,9 @@ public:
    * 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 at Cache.
+   * @param[in] textureInfo TextureInfo that want to cache in container.
    */
-  void RemoveCache(const TextureCacheManager::TextureId& textureId);
+  void RemoveCache(TextureCacheManager::TextureInfo& textureInfo);
 
 public:
   /**
@@ -293,23 +302,6 @@ private:
   // Private defined structs.
 
   /**
-   * @brief This struct is used to manage the life-cycle of ExternalTexture url.
-   */
-  struct ExternalTextureInfo
-  {
-    ExternalTextureInfo(const TextureCacheManager::TextureId& textureId,
-                        const TextureSet&                     textureSet)
-    : textureId(textureId),
-      textureSet(textureSet),
-      referenceCount(1u)
-    {
-    }
-    TextureCacheManager::TextureId textureId;
-    TextureSet                     textureSet;
-    std::int16_t                   referenceCount;
-  };
-
-  /**
    * @brief This struct is used to manage the life-cycle of EncodedImageBuffer url.
    */
   struct EncodedImageBufferInfo