Revert "[Tizen] Fix Animated Image Visual issue of using same file in multiple visual"
authorHeeyong Song <heeyong.song@samsung.com>
Thu, 19 Nov 2020 05:19:33 +0000 (14:19 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Thu, 19 Nov 2020 05:19:39 +0000 (14:19 +0900)
This reverts commit f8a0bad72290d54b39818818f2a05f741ddc2ac5.

Change-Id: I4feb8e19a36b07aba5354c0d3b2826afa3619b99

dali-toolkit/internal/visuals/texture-manager-impl.cpp
dali-toolkit/internal/visuals/texture-manager-impl.h

index 1de8a80..64bbb5b 100644 (file)
@@ -38,7 +38,6 @@
 namespace
 {
 
-constexpr auto INITIAL_CACHE_NUMBER = size_t{0u};
 constexpr auto DEFAULT_NUMBER_OF_LOCAL_LOADER_THREADS = size_t{4u};
 constexpr auto DEFAULT_NUMBER_OF_REMOTE_LOADER_THREADS = size_t{8u};
 
@@ -455,18 +454,14 @@ TextureManager::TextureId TextureManager::RequestLoadInternal(
 {
   // First check if the requested Texture is cached.
   bool isAnimatedImage = ( animatedImageLoading ) ? true : false;
-
-  TextureHash textureHash = INITIAL_CACHE_NUMBER;
-  int cacheIndex = INVALID_CACHE_INDEX;
-  if(!isAnimatedImage)
-  {
-    textureHash = GenerateHash(url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, storageType);
-
-    // Look up the texture by hash. Note: The extra parameters are used in case of a hash collision.
-    cacheIndex = FindCachedTexture(textureHash, url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, preMultiplyOnLoad, storageType);
-  }
+  const TextureHash textureHash = GenerateHash( url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas,
+                                                maskTextureId, storageType, isAnimatedImage, frameIndex );
 
   TextureManager::TextureId textureId = INVALID_TEXTURE_ID;
+  // Look up the texture by hash. Note: The extra parameters are used in case of a hash collision.
+  int cacheIndex = FindCachedTexture( textureHash, url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas,
+                                      maskTextureId, preMultiplyOnLoad, storageType, isAnimatedImage, frameIndex );
+
   // Check if the requested Texture exists in the cache.
   if( cacheIndex != INVALID_CACHE_INDEX )
   {
@@ -1168,7 +1163,9 @@ TextureManager::TextureHash TextureManager::GenerateHash(
   const Dali::SamplingMode::Type samplingMode,
   const UseAtlas                 useAtlas,
   TextureId                      maskTextureId,
-  StorageType                    storageType)
+  StorageType                    storageType,
+  bool                           isAnimationImage,
+  uint32_t                       frameIndex )
 {
   std::string hashTarget( url );
   const size_t urlLength = hashTarget.length();
@@ -1213,6 +1210,19 @@ TextureManager::TextureHash TextureManager::GenerateHash(
     }
   }
 
+  if( isAnimationImage )
+  {
+    auto textureIdIndex = hashTarget.length();
+    hashTarget.resize( hashTarget.length() + sizeof( uint32_t ) );
+    char* hashTargetPtr = &( hashTarget[ textureIdIndex ] );
+
+    for( size_t byteIter = 0; byteIter < sizeof( uint32_t ); ++byteIter )
+    {
+      *hashTargetPtr++ = frameIndex & 0xff;
+      frameIndex >>= 8u;
+    }
+  }
+
   if( maskTextureId != INVALID_TEXTURE_ID )
   {
     auto textureIdIndex = hashTarget.length();
@@ -1240,7 +1250,9 @@ int TextureManager::FindCachedTexture(
   const bool                        useAtlas,
   TextureId                         maskTextureId,
   TextureManager::MultiplyOnLoad    preMultiplyOnLoad,
-  StorageType                       storageType)
+  StorageType                       storageType,
+  bool                              isAnimatedImage,
+  uint32_t                          frameIndex )
 {
   // Default to an invalid ID, in case we do not find a match.
   int cacheIndex = INVALID_CACHE_INDEX;
@@ -1261,7 +1273,9 @@ int TextureManager::FindCachedTexture(
           ( ( size.GetWidth() == 0 && size.GetHeight() == 0 ) ||
             ( fittingMode == textureInfo.fittingMode &&
               samplingMode == textureInfo.samplingMode ) ) &&
-          ( storageType == textureInfo.storageType )  )
+          ( storageType == textureInfo.storageType ) &&
+          ( isAnimatedImage == ( ( textureInfo.animatedImageLoading ) ? true : false ) ) &&
+          ( frameIndex == textureInfo.frameIndex ) )
       {
         // 1. If preMultiplyOnLoad is MULTIPLY_ON_LOAD, then textureInfo.preMultiplyOnLoad should be true. The premultiplication result can be different.
         // 2. If preMultiplyOnLoad is LOAD_WITHOUT_MULTIPLY, then textureInfo.preMultiplied should be false.
index 2756558..f8500c7 100644 (file)
@@ -746,13 +746,14 @@ private:
    * @param[in] samplingMode     The SamplingMode to use
    * @param[in] useAtlas         True if atlased
    * @param[in] maskTextureId    The masking texture id (or INVALID_TEXTURE_ID)
-   * @param[in] storageType      Whether the pixel data is stored in the cache, returned with PixelBuffer or uploaded to the GPU
+   * @param[in] isAnimatedImage  The boolean value to know whether the request is for animated image or not
+   * @param[in] frameIndex       The frame index of a frame to be loaded frame
    * @return                     A hash of the provided data for caching.
    */
   TextureHash GenerateHash( const std::string& url, const ImageDimensions size,
                             const FittingMode::Type fittingMode,
                             const Dali::SamplingMode::Type samplingMode, const UseAtlas useAtlas,
-                            TextureId maskTextureId, StorageType storageType );
+                            TextureId maskTextureId, StorageType storageType, bool isAnimatedImage, uint32_t frameIndex );
 
   /**
    * @brief Looks up a cached texture by its hash.
@@ -766,6 +767,8 @@ private:
    * @param[in] maskTextureId     Optional texture ID to use to mask this image
    * @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] storageType       Whether the pixel data is stored in the cache, returned with PixelBuffer or uploaded to the GPU
+   * @param[in] isAnimatedImage   The boolean value to know whether the request is for animated image or not
+   * @param[in] frameIndex        The frame index of a frame to be loaded frame
    * @return                      A TextureId of a cached Texture if found. Or INVALID_TEXTURE_ID if not found.
    */
   TextureManager::TextureId FindCachedTexture(
@@ -777,7 +780,9 @@ private:
     const bool useAtlas,
     TextureId maskTextureId,
     MultiplyOnLoad preMultiplyOnLoad,
-    StorageType storageType );
+    StorageType storageType,
+    bool isAnimatedImage,
+    uint32_t frameIndex );
 
 private: