Caching texture instead of textureSet in TextureManager
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / texture-manager / texture-cache-manager.cpp
index 01e43a4..87ef902 100644 (file)
@@ -167,22 +167,20 @@ TextureCacheManager::LoadState TextureCacheManager::GetTextureStateInternal(cons
   return loadState;
 }
 
-TextureSet TextureCacheManager::GetTextureSet(const TextureCacheManager::TextureId& textureId)
+Texture TextureCacheManager::GetTexture(const TextureCacheManager::TextureId& textureId, uint32_t textureIndex)
 {
-  TextureSet        textureSet; // empty handle
-  TextureCacheIndex cacheIndex = static_cast<TextureCacheIndex>(mTextureIdConverter[static_cast<std::uint32_t>(textureId)]);
+  Texture        texture; // empty handle
+  TextureCacheIndex cacheIndex = GetCacheIndexFromId(textureId);
 
   switch(static_cast<TextureCacheIndexType>(cacheIndex.detailValue.type))
   {
     case TextureCacheIndexType::TEXTURE_CACHE_INDEX_TYPE_LOCAL:
     {
       TextureInfo& cachedTextureInfo(mTextureInfoContainer[cacheIndex.GetIndex()]);
-      textureSet = cachedTextureInfo.textureSet;
-      break;
-    }
-    case TextureCacheIndexType::TEXTURE_CACHE_INDEX_TYPE_TEXTURE:
-    {
-      textureSet = mExternalTextures[cacheIndex.GetIndex()].textureSet;
+      if(textureIndex < static_cast<uint32_t>(cachedTextureInfo.textures.size()))
+      {
+        texture = cachedTextureInfo.textures[textureIndex];
+      }
       break;
     }
     default:
@@ -191,7 +189,7 @@ TextureSet TextureCacheManager::GetTextureSet(const TextureCacheManager::Texture
     }
   }
 
-  return textureSet;
+  return texture;
 }
 
 TextureSet TextureCacheManager::GetExternalTextureSet(const TextureCacheManager::TextureId& textureId)
@@ -484,17 +482,16 @@ TextureCacheManager::TextureHash TextureCacheManager::GenerateHash(
   const bool&                           cropToMask,
   const std::uint32_t&                  frameIndex)
 {
-  std::vector<std::uint8_t> hashTarget(url.GetUrl().begin(), url.GetUrl().end());
-  const size_t              urlLength = hashTarget.size();
-  const uint16_t            width     = size.GetWidth();
-  const uint16_t            height    = size.GetWidth();
+  std::vector<std::uint8_t> hashTarget;
+  const uint16_t            width  = size.GetWidth();
+  const uint16_t            height = size.GetWidth();
 
   // If either the width or height has been specified, include the resizing options in the hash
   if(width != 0 || height != 0)
   {
     // We are appending 5 bytes to the URL to form the hash input.
-    hashTarget.resize(urlLength + 5u);
-    std::uint8_t* hashTargetPtr = &(hashTarget[urlLength]);
+    hashTarget.resize(5u);
+    std::uint8_t* hashTargetPtr = &(hashTarget[0u]);
 
     // Pack the width and height (4 bytes total).
     *hashTargetPtr++ = size.GetWidth() & 0xff;
@@ -509,19 +506,19 @@ TextureCacheManager::TextureHash TextureCacheManager::GenerateHash(
   else
   {
     // We are not including sizing information, but we still need an extra byte for atlasing.
-    hashTarget.resize(urlLength + 1u);
+    hashTarget.resize(1u);
 
     // Add the atlasing to the hash input.
     switch(useAtlas)
     {
       case UseAtlas::NO_ATLAS:
       {
-        hashTarget[urlLength] = 'f';
+        hashTarget[0u] = 'f';
         break;
       }
       case UseAtlas::USE_ATLAS:
       {
-        hashTarget[urlLength] = 't';
+        hashTarget[0u] = 't';
         break;
       }
     }
@@ -560,7 +557,7 @@ TextureCacheManager::TextureHash TextureCacheManager::GenerateHash(
     }
   }
 
-  return Dali::CalculateHash(hashTarget);
+  return url.GetUrlHash() ^ Dali::CalculateHash(hashTarget);
 }
 
 TextureCacheManager::TextureCacheIndex TextureCacheManager::FindCachedTexture(
@@ -570,6 +567,7 @@ TextureCacheManager::TextureCacheIndex TextureCacheManager::FindCachedTexture(
   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,
@@ -594,6 +592,7 @@ TextureCacheManager::TextureCacheIndex TextureCacheManager::FindCachedTexture(
            (cropToMask == textureInfo.cropToMask) &&
            (size == textureInfo.desiredSize) &&
            (isAnimatedImage == textureInfo.isAnimatedImageFormat) &&
+           (storageType == textureInfo.storageType) &&
            (frameIndex == textureInfo.frameIndex) &&
            ((size.GetWidth() == 0 && size.GetHeight() == 0) ||
             (fittingMode == textureInfo.fittingMode &&