X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fanimated-image%2Ffixed-image-cache.cpp;h=e751f902b495c52c3362e484936fcf863062971f;hb=HEAD;hp=854a7a0082f207934b30280377857bf665273bca;hpb=2694237e353ab72fd7804712cb88d5fc3836547a;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp b/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp index 854a7a0..e51870b 100644 --- a/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp +++ b/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 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. @@ -21,6 +21,7 @@ #include // For ImageAtlasManagerPtr // EXTERNAL HEADERS +#include #include namespace Dali @@ -47,7 +48,7 @@ FixedImageCache::FixedImageCache(TextureManager& textureMana bool preMultiplyOnLoad) : ImageCache(textureManager, size, fittingMode, samplingMode, maskingData, observer, batchSize, interval, preMultiplyOnLoad), mImageUrls(urlList), - mFront(FIRST_FRAME_INDEX) + mCurrentFrameIndex(FIRST_FRAME_INDEX) { mReadyFlags.reserve(mImageUrls.size()); } @@ -66,18 +67,26 @@ TextureSet FixedImageCache::Frame(uint32_t frameIndex) return textureSet; } - while(mReadyFlags.size() < mImageUrls.size() && - (frameIndex > mFront || mReadyFlags.empty())) + mCurrentFrameIndex = frameIndex; + + bool batchRequested = false; + + // Make ensure that current frameIndex load requested. + while(mReadyFlags.size() <= frameIndex) { - ++mFront; + batchRequested = true; LoadBatch(); } - mFront = frameIndex; + // Request batch only 1 times for this function. + if(!batchRequested && mReadyFlags.size() < mImageUrls.size()) + { + LoadBatch(); + } - if(IsFrontReady() && mLoadState != TextureManager::LoadState::LOAD_FAILED) + if(IsFrameReady(mCurrentFrameIndex) && mLoadState != TextureManager::LoadState::LOAD_FAILED) { - textureSet = GetFrontTextureSet(); + textureSet = GetTextureSet(mCurrentFrameIndex); } return textureSet; @@ -97,7 +106,7 @@ uint32_t FixedImageCache::GetFrameInterval(uint32_t frameIndex) const int32_t FixedImageCache::GetCurrentFrameIndex() const { - return static_cast(mFront); + return static_cast(mCurrentFrameIndex); } int32_t FixedImageCache::GetTotalFrameCount() const @@ -105,9 +114,9 @@ int32_t FixedImageCache::GetTotalFrameCount() const return mImageUrls.size(); } -bool FixedImageCache::IsFrontReady() const +bool FixedImageCache::IsFrameReady(uint32_t frameIndex) const { - return (mReadyFlags.size() > 0 && mReadyFlags[mFront] == true); + return ((mReadyFlags.size() > 0) && (mReadyFlags[frameIndex] == true)); } void FixedImageCache::LoadBatch() @@ -138,38 +147,34 @@ void FixedImageCache::LoadBatch() auto preMultiplyOnLoading = mPreMultiplyOnLoad ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; - mTextureManager.LoadTexture(url, mDesiredSize, mFittingMode, mSamplingMode, mMaskingData, synchronousLoading, mImageUrls[frameIndex].mTextureId, textureRect, textureRectSize, atlasingStatus, loadingStatus, this, atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED, preMultiplyOnLoading); - mRequestingLoad = false; + TextureManager::TextureId loadTextureId = TextureManager::INVALID_TEXTURE_ID; + mTextureManager.LoadTexture(url, mDesiredSize, mFittingMode, mSamplingMode, mMaskingData, synchronousLoading, loadTextureId, textureRect, textureRectSize, atlasingStatus, loadingStatus, this, atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED, preMultiplyOnLoading); + mImageUrls[frameIndex].mTextureId = loadTextureId; + mRequestingLoad = false; } } -TextureSet FixedImageCache::GetFrontTextureSet() const +TextureSet FixedImageCache::GetTextureSet(uint32_t frameIndex) const { - TextureSet textureSet = mTextureManager.GetTextureSet(mImageUrls[mFront].mTextureId); - if(textureSet) - { - Sampler sampler = Sampler::New(); - sampler.SetWrapMode(Dali::WrapMode::Type::DEFAULT, Dali::WrapMode::Type::DEFAULT); - textureSet.SetSampler(0u, sampler); - } + TextureSet textureSet = mTextureManager.GetTextureSet(mImageUrls[frameIndex].mTextureId); return textureSet; } -void FixedImageCache::CheckFrontFrame(bool wasReady, bool preMultiplied) +void FixedImageCache::MakeReady(bool wasReady, uint32_t frameIndex, bool preMultiplied) { - if(wasReady == false && IsFrontReady()) + if(wasReady == false && IsFrameReady(frameIndex)) { - mObserver.FrameReady(GetFrontTextureSet(), mInterval, preMultiplied); + mObserver.FrameReady(GetTextureSet(frameIndex), mInterval, preMultiplied); } } void FixedImageCache::ClearCache() { - if(mTextureManagerAlive) + if(Dali::Adaptor::IsAvailable()) { for(std::size_t i = 0; i < mImageUrls.size(); ++i) { - mTextureManager.Remove(mImageUrls[i].mTextureId, this); + mTextureManager.RequestRemove(mImageUrls[i].mTextureId, this); mImageUrls[i].mTextureId = TextureManager::INVALID_TEXTURE_ID; } } @@ -185,8 +190,8 @@ void FixedImageCache::LoadComplete(bool loadSuccess, TextureInformation textureI { if(loadSuccess) { - mLoadState = TextureManager::LoadState::LOAD_FINISHED; - bool frontFrameReady = IsFrontReady(); + mLoadState = TextureManager::LoadState::LOAD_FINISHED; + bool wasCurrentFrameReady = IsFrameReady(mCurrentFrameIndex); if(!mRequestingLoad) { for(std::size_t i = 0; i < mImageUrls.size(); ++i) @@ -200,9 +205,14 @@ void FixedImageCache::LoadComplete(bool loadSuccess, TextureInformation textureI } else { - mReadyFlags.back() = true; + DALI_ASSERT_ALWAYS(mReadyFlags.size() > 0u && "Some FixedImageCache::LoadBatch() called mismatched!"); + size_t i = mReadyFlags.size() - 1u; + + // texture id might not setup yet. Update it now. + mImageUrls[i].mTextureId = textureInformation.textureId; + mReadyFlags[i] = true; } - CheckFrontFrame(frontFrameReady, textureInformation.preMultiplied); + MakeReady(wasCurrentFrameReady, mCurrentFrameIndex, textureInformation.preMultiplied); } else {