X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftexture-manager%2Ftexture-cache-manager.cpp;h=c0e7ac128fe5cf1b35dc6bacb19b45cd4144cd11;hb=ca51ee97baf5f41ecf741e22d865ff6c9e0bf769;hp=a56116113b0330b5bdb700302744ddd6375fa6f4;hpb=e347d602263eecad8e869a654a206e1418d2e510;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/texture-manager/texture-cache-manager.cpp b/dali-toolkit/internal/texture-manager/texture-cache-manager.cpp index a561161..c0e7ac1 100644 --- a/dali-toolkit/internal/texture-manager/texture-cache-manager.cpp +++ b/dali-toolkit/internal/texture-manager/texture-cache-manager.cpp @@ -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(mTextureIdConverter[static_cast(textureId)]); + Texture texture; // empty handle + TextureCacheIndex cacheIndex = GetCacheIndexFromId(textureId); switch(static_cast(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(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) @@ -481,19 +479,19 @@ TextureCacheManager::TextureHash TextureCacheManager::GenerateHash( const Dali::SamplingMode::Type& samplingMode, const TextureCacheManager::UseAtlas& useAtlas, const TextureCacheManager::TextureId& maskTextureId, - const bool& cropToMask) + const bool& cropToMask, + const std::uint32_t& frameIndex) { - std::vector 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 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; @@ -508,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; } } @@ -543,7 +541,23 @@ TextureCacheManager::TextureHash TextureCacheManager::GenerateHash( *hashTargetPtr++ = (cropToMask ? 'C' : 'M'); } - return Dali::CalculateHash(hashTarget); + // Append the frameIndex. We don't do additional job when frameIndex = 0u due to the non-animated image case. + if(frameIndex > 0u) + { + auto textureIdIndex = hashTarget.size(); + hashTarget.resize(hashTarget.size() + sizeof(std::uint32_t)); + std::uint8_t* hashTargetPtr = reinterpret_cast(&(hashTarget[textureIdIndex])); + + // Append the frame index to the end of the URL byte by byte: + std::uint32_t saltedFrameIndex = frameIndex; + for(size_t byteIter = 0; byteIter < sizeof(std::uint8_t); ++byteIter) + { + *hashTargetPtr++ = saltedFrameIndex & 0xff; + saltedFrameIndex >>= 8u; + } + } + + return url.GetUrlHash() ^ Dali::CalculateHash(hashTarget); } TextureCacheManager::TextureCacheIndex TextureCacheManager::FindCachedTexture( @@ -553,10 +567,12 @@ 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, - const bool& isAnimatedImage) + const bool& isAnimatedImage, + const std::uint32_t& frameIndex) { // Iterate through our hashes to find a match. const auto& hashIterator = mTextureHashContainer.find(hash); @@ -576,6 +592,8 @@ 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 && samplingMode == textureInfo.samplingMode))) @@ -625,61 +643,55 @@ TextureCacheManager::TextureCacheIndex TextureCacheManager::AppendCache(const Te return cacheIndex; } -void TextureCacheManager::RemoveCache(const TextureCacheManager::TextureId& textureId) +void TextureCacheManager::RemoveCache(TextureCacheManager::TextureInfo& textureInfo) { - TextureCacheIndex textureInfoIndex = GetCacheIndexFromId(textureId); - + TextureCacheIndex textureInfoIndex = GetCacheIndexFromId(textureInfo.textureId); bool removeTextureInfo = false; - if(textureInfoIndex != INVALID_CACHE_INDEX) - { - TextureInfo& textureInfo(mTextureInfoContainer[textureInfoIndex.GetIndex()]); + DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureCacheManager::Remove(textureId:%d) url:%s\n cacheIdx:%d loadState:%s reference count = %d\n", textureInfo.textureId, textureInfo.url.GetUrl().c_str(), textureInfoIndex.GetIndex(), GET_LOAD_STATE_STRING(textureInfo.loadState), textureInfo.referenceCount); - DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureCacheManager::Remove(textureId:%d) url:%s\n cacheIdx:%d loadState:%s reference count = %d\n", textureId, textureInfo.url.GetUrl().c_str(), textureInfoIndex.GetIndex(), GET_LOAD_STATE_STRING(textureInfo.loadState), textureInfo.referenceCount); + // Decrement the reference count and check if this is the last user of this Texture. + if(--textureInfo.referenceCount <= 0) + { + // This is the last remove for this Texture. + textureInfo.referenceCount = 0; - // Decrement the reference count and check if this is the last user of this Texture. - if(--textureInfo.referenceCount <= 0) + // If loaded, we can remove the TextureInfo and the Atlas (if atlased). + if(textureInfo.loadState == LoadState::UPLOADED) { - // This is the last remove for this Texture. - textureInfo.referenceCount = 0; - - // If loaded, we can remove the TextureInfo and the Atlas (if atlased). - if(textureInfo.loadState == LoadState::UPLOADED) - { - if(textureInfo.atlas) - { - textureInfo.atlas.Remove(textureInfo.atlasRect); - } - removeTextureInfo = true; - } - else if(textureInfo.loadState == LoadState::LOADING || textureInfo.loadState == LoadState::MASK_APPLYING) + if(textureInfo.atlas) { - // We mark the textureInfo for removal. - // Once the load has completed, this method will be called again. - textureInfo.loadState = LoadState::CANCELLED; - } - else - { - // In other states, we are not waiting for a load so we are safe to remove the TextureInfo data. - removeTextureInfo = true; + textureInfo.atlas.Remove(textureInfo.atlasRect); } + removeTextureInfo = true; + } + else if(textureInfo.loadState == LoadState::LOADING || textureInfo.loadState == LoadState::MASK_APPLYING) + { + // We mark the textureInfo for removal. + // Once the load has completed, this method will be called again. + textureInfo.loadState = LoadState::CANCELLED; + } + else + { + // In other states, we are not waiting for a load so we are safe to remove the TextureInfo data. + removeTextureInfo = true; + } - // If the state allows us to remove the TextureInfo data, we do so. - if(removeTextureInfo) + // If the state allows us to remove the TextureInfo data, we do so. + if(removeTextureInfo) + { + // If url location is BUFFER, decrease reference count of EncodedImageBuffer. + if(textureInfo.url.IsBufferResource()) { - // If url location is BUFFER, decrease reference count of EncodedImageBuffer. - if(textureInfo.url.IsBufferResource()) - { - RemoveEncodedImageBuffer(textureInfo.url.GetUrl()); - } + RemoveEncodedImageBuffer(textureInfo.url.GetUrl()); + } - // Permanently remove the textureInfo struct. + // Permanently remove the textureInfo struct. - // Step 1. remove current textureId information in mTextureHashContainer. - RemoveHashId(textureInfo.hash, textureId); - // Step 2. make textureId is not using anymore. After this job, we can reuse textureId. - mTextureIdConverter.Remove(textureId); - } + // Step 1. remove current textureId information in mTextureHashContainer. + RemoveHashId(textureInfo.hash, textureInfo.textureId); + // Step 2. make textureId is not using anymore. After this job, we can reuse textureId. + mTextureIdConverter.Remove(textureInfo.textureId); } }