From c7efc4f6dd8ca6ff94bc99acf92944b7f697e0bb Mon Sep 17 00:00:00 2001 From: sunghyun kim Date: Thu, 17 Mar 2022 15:11:41 +0900 Subject: [PATCH] Caching cropToMask in texture manager cropToMask need to be cahing, so i added this patch Change-Id: I6fecdfd8bc12a0c5d270c50da50340331ce0917f --- .../internal/texture-manager/texture-cache-manager.cpp | 10 +++++++--- dali-toolkit/internal/texture-manager/texture-cache-manager.h | 8 ++++++-- dali-toolkit/internal/texture-manager/texture-manager-impl.cpp | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/dali-toolkit/internal/texture-manager/texture-cache-manager.cpp b/dali-toolkit/internal/texture-manager/texture-cache-manager.cpp index 9524c44..cc90fd8 100644 --- a/dali-toolkit/internal/texture-manager/texture-cache-manager.cpp +++ b/dali-toolkit/internal/texture-manager/texture-cache-manager.cpp @@ -326,7 +326,8 @@ TextureCacheManager::TextureHash TextureCacheManager::GenerateHash( const Dali::FittingMode::Type& fittingMode, const Dali::SamplingMode::Type& samplingMode, const TextureCacheManager::UseAtlas& useAtlas, - const TextureCacheManager::TextureId& maskTextureId) + const TextureCacheManager::TextureId& maskTextureId, + const bool& cropToMask) { std::vector hashTarget(url.begin(), url.end()); const size_t urlLength = url.length(); @@ -374,7 +375,7 @@ TextureCacheManager::TextureHash TextureCacheManager::GenerateHash( if(maskTextureId != INVALID_TEXTURE_ID) { auto textureIdIndex = hashTarget.size(); - hashTarget.resize(hashTarget.size() + sizeof(TextureId)); + hashTarget.resize(hashTarget.size() + sizeof(TextureId) + 1u); std::uint8_t* hashTargetPtr = reinterpret_cast(&(hashTarget[textureIdIndex])); // Append the texture id to the end of the URL byte by byte: @@ -385,6 +386,7 @@ TextureCacheManager::TextureHash TextureCacheManager::GenerateHash( *hashTargetPtr++ = saltedMaskTextureId & 0xff; saltedMaskTextureId >>= 8u; } + *hashTargetPtr++ = (cropToMask ? 'C' : 'M'); } return Dali::CalculateHash(hashTarget); @@ -399,7 +401,8 @@ TextureCacheManager::TextureCacheIndex TextureCacheManager::FindCachedTexture( const TextureCacheManager::UseAtlas& useAtlas, const TextureCacheManager::TextureId& maskTextureId, const TextureCacheManager::MultiplyOnLoad& preMultiplyOnLoad, - bool isAnimatedImage) + bool isAnimatedImage, + const bool& cropToMask) { // Default to an invalid ID, in case we do not find a match. TextureCacheIndex cacheIndex = INVALID_CACHE_INDEX; @@ -416,6 +419,7 @@ TextureCacheManager::TextureCacheIndex TextureCacheManager::FindCachedTexture( if((url == textureInfo.url.GetUrl()) && (useAtlas == textureInfo.useAtlas) && (maskTextureId == textureInfo.maskTextureId) && + (cropToMask == textureInfo.cropToMask) && (size == textureInfo.desiredSize) && (isAnimatedImage == textureInfo.isAnimatedImageFormat) && ((size.GetWidth() == 0 && size.GetHeight() == 0) || diff --git a/dali-toolkit/internal/texture-manager/texture-cache-manager.h b/dali-toolkit/internal/texture-manager/texture-cache-manager.h index 7d941d1..3196e24 100644 --- a/dali-toolkit/internal/texture-manager/texture-cache-manager.h +++ b/dali-toolkit/internal/texture-manager/texture-cache-manager.h @@ -184,6 +184,7 @@ public: * @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] cropToMask True if crop to mask * @return A hash of the provided data for caching. */ TextureCacheManager::TextureHash GenerateHash( @@ -192,7 +193,8 @@ public: const Dali::FittingMode::Type& fittingMode, const Dali::SamplingMode::Type& samplingMode, const TextureCacheManager::UseAtlas& useAtlas, - const TextureCacheManager::TextureId& maskTextureId); + const TextureCacheManager::TextureId& maskTextureId, + const bool& cropToMask); /** * @brief Looks up a cached texture by its hash. @@ -206,6 +208,7 @@ public: * @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] isAnimatedImage True if the texture is from animated image. + * @param[in] cropToMask True if crop to mask * @return A TextureCacheId of a cached Texture if found. Or INVALID_CACHE_INDEX if not found. */ TextureCacheManager::TextureCacheIndex FindCachedTexture( @@ -217,7 +220,8 @@ public: const TextureCacheManager::UseAtlas& useAtlas, const TextureCacheManager::TextureId& maskTextureId, const TextureCacheManager::MultiplyOnLoad& preMultiplyOnLoad, - bool isAnimatedImage); + bool isAnimatedImage, + const bool& cropToMask); /** * @brief Append a Texture to the TextureCacheManager. diff --git a/dali-toolkit/internal/texture-manager/texture-manager-impl.cpp b/dali-toolkit/internal/texture-manager/texture-manager-impl.cpp index ff81b22..a3cb054 100644 --- a/dali-toolkit/internal/texture-manager/texture-manager-impl.cpp +++ b/dali-toolkit/internal/texture-manager/texture-manager-impl.cpp @@ -468,10 +468,10 @@ TextureManager::TextureId TextureManager::RequestLoadInternal( TextureCacheIndex cacheIndex = INVALID_CACHE_INDEX; if(storageType != StorageType::RETURN_PIXEL_BUFFER && useCache) { - textureHash = mTextureCacheManager.GenerateHash(url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId); + textureHash = mTextureCacheManager.GenerateHash(url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, cropToMask); // Look up the texture by hash. Note: The extra parameters are used in case of a hash collision. - cacheIndex = mTextureCacheManager.FindCachedTexture(textureHash, url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, preMultiplyOnLoad, (animatedImageLoading) ? true : false); + cacheIndex = mTextureCacheManager.FindCachedTexture(textureHash, url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, preMultiplyOnLoad, (animatedImageLoading) ? true : false, cropToMask); } TextureManager::TextureId textureId = INVALID_TEXTURE_ID; -- 2.7.4