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=d60834f58b83dd187ad25d1db37f94dd326b4dcc;hpb=46322a558e537267a6d3c48630c45afca91b5e27;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 d60834f..96f0f3e 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) 2017 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. @@ -17,147 +17,211 @@ // CLASS HEADER #include +// INTERNAL HEADERS +#include // For ImageAtlasManagerPtr + +// EXTERNAL HEADERS +#include +#include + namespace Dali { namespace Toolkit { namespace Internal { - -FixedImageCache::FixedImageCache( - TextureManager& textureManager, UrlList& urlList, ImageCache::FrameReadyObserver& observer, - unsigned int batchSize ) -: ImageCache( textureManager, urlList, observer, batchSize ), - mFront(0u) +namespace +{ +constexpr bool ENABLE_ORIENTATION_CORRECTION(true); +constexpr uint32_t FIRST_FRAME_INDEX = 0u; +} // namespace + +FixedImageCache::FixedImageCache(TextureManager& textureManager, + ImageDimensions size, + Dali::FittingMode::Type fittingMode, + Dali::SamplingMode::Type samplingMode, + UrlList& urlList, + TextureManager::MaskingDataPointer& maskingData, + ImageCache::FrameReadyObserver& observer, + uint32_t batchSize, + uint32_t interval, + bool preMultiplyOnLoad) +: ImageCache(textureManager, size, fittingMode, samplingMode, maskingData, observer, batchSize, interval, preMultiplyOnLoad), + mImageUrls(urlList), + mCurrentFrameIndex(FIRST_FRAME_INDEX) { - mReadyFlags.reserve( mImageUrls.size() ); - LoadBatch(); + mReadyFlags.reserve(mImageUrls.size()); } FixedImageCache::~FixedImageCache() { - for( std::size_t i = 0; i < mImageUrls.size() ; ++i ) - { - mTextureManager.Remove( mImageUrls[i].mTextureId ); - } + ClearCache(); } -TextureSet FixedImageCache::FirstFrame() +TextureSet FixedImageCache::Frame(uint32_t frameIndex) { - TextureSet textureSet = GetFrontTextureSet(); - - if( ! textureSet ) + TextureSet textureSet; + if(frameIndex >= mImageUrls.size()) { - mWaitingForReadyFrame = true; + DALI_LOG_ERROR("Wrong frameIndex requested.\n"); + return textureSet; } - return textureSet; -} + mCurrentFrameIndex = frameIndex; -TextureSet FixedImageCache::NextFrame() -{ - TextureSet textureSet; - ++mFront; - mFront %= mImageUrls.size(); + bool batchRequested = false; - if( IsFrontReady() == true ) + // Make ensure that current frameIndex load requested. + while(mReadyFlags.size() <= frameIndex) { - textureSet = GetFrontTextureSet(); + batchRequested = true; + LoadBatch(); } - else + + // Request batch only 1 times for this function. + if(!batchRequested && mReadyFlags.size() < mImageUrls.size()) { - mWaitingForReadyFrame = true; + LoadBatch(); } - LoadBatch(); + if(IsFrameReady(mCurrentFrameIndex) && mLoadState != TextureManager::LoadState::LOAD_FAILED) + { + textureSet = GetTextureSet(mCurrentFrameIndex); + } return textureSet; } -bool FixedImageCache::IsFrontReady() const +TextureSet FixedImageCache::FirstFrame() +{ + TextureSet textureSet = Frame(FIRST_FRAME_INDEX); + + return textureSet; +} + +uint32_t FixedImageCache::GetFrameInterval(uint32_t frameIndex) const +{ + return mInterval; +} + +int32_t FixedImageCache::GetCurrentFrameIndex() const { - return ( mReadyFlags.size() > 0 && mReadyFlags[mFront] == true ); + return static_cast(mCurrentFrameIndex); +} + +int32_t FixedImageCache::GetTotalFrameCount() const +{ + return mImageUrls.size(); +} + +bool FixedImageCache::IsFrameReady(uint32_t frameIndex) const +{ + return ((mReadyFlags.size() > 0) && (mReadyFlags[frameIndex] == true)); } void FixedImageCache::LoadBatch() { // Try and load up to mBatchSize images, until the cache is filled. - // Once the cache is filled, mUrlIndex exceeds mImageUrls size and - // no more images are loaded. - bool frontFrameReady = IsFrontReady();; - - for( unsigned int i=0; i< mBatchSize && mUrlIndex < mImageUrls.size(); ++i ) + // Once the cache is filled, no more images are loaded. + for(unsigned int i = 0; i < mBatchSize && mReadyFlags.size() < mImageUrls.size(); ++i) { - std::string& url = mImageUrls[ mUrlIndex ].mUrl; + uint32_t frameIndex = mReadyFlags.size(); + VisualUrl& url = mImageUrls[frameIndex].mUrl; mReadyFlags.push_back(false); - // Note, if the image is already loaded, then UploadComplete will get called + // Note, if the image is already loaded, then LoadComplete will get called // from within this method. This means it won't yet have a texture id, so we - // need to account for this inside the UploadComplete method using mRequestingLoad. + // need to account for this inside the LoadComplete method using mRequestingLoad. mRequestingLoad = true; - - mImageUrls[ mUrlIndex ].mTextureId = - mTextureManager.RequestLoad( url, ImageDimensions(), FittingMode::SCALE_TO_FILL, - SamplingMode::BOX_THEN_LINEAR, TextureManager::NO_ATLAS, - this ); - mRequestingLoad = false; - ++mUrlIndex; + mLoadState = TextureManager::LoadState::LOADING; + + bool synchronousLoading = false; + bool atlasingStatus = false; + bool loadingStatus = false; + AtlasUploadObserver* atlasObserver = nullptr; + ImageAtlasManagerPtr imageAtlasManager = nullptr; + Vector4 textureRect; + Dali::ImageDimensions textureRectSize; + + auto preMultiplyOnLoading = mPreMultiplyOnLoad ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD + : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY; + + 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; } - - CheckFrontFrame( frontFrameReady ); } -void FixedImageCache::SetImageFrameReady( TextureManager::TextureId textureId ) +TextureSet FixedImageCache::GetTextureSet(uint32_t frameIndex) const { - for( std::size_t i = 0; i < mImageUrls.size() ; ++i ) - { - if( mImageUrls[i].mTextureId == textureId ) - { - mReadyFlags[i] = true; - break; - } - } + TextureSet textureSet = mTextureManager.GetTextureSet(mImageUrls[frameIndex].mTextureId); + return textureSet; } -TextureSet FixedImageCache::GetFrontTextureSet() const +void FixedImageCache::MakeReady(bool wasReady, uint32_t frameIndex, bool preMultiplied) { - return mTextureManager.GetTextureSet( mImageUrls[mFront].mTextureId ); + if(wasReady == false && IsFrameReady(frameIndex)) + { + mObserver.FrameReady(GetTextureSet(frameIndex), mInterval, preMultiplied); + } } -void FixedImageCache::CheckFrontFrame( bool wasReady ) +void FixedImageCache::ClearCache() { - if( mWaitingForReadyFrame && wasReady == false && IsFrontReady() ) + if(Dali::Adaptor::IsAvailable()) + { + for(std::size_t i = 0; i < mImageUrls.size(); ++i) + { + mTextureManager.RequestRemove(mImageUrls[i].mTextureId, this); + mImageUrls[i].mTextureId = TextureManager::INVALID_TEXTURE_ID; + } + } + mReadyFlags.clear(); + mLoadState = TextureManager::LoadState::NOT_STARTED; + if(mMaskingData) { - mWaitingForReadyFrame = false; - mObserver.FrameReady( GetFrontTextureSet() ); + mMaskingData->mAlphaMaskId = TextureManager::INVALID_TEXTURE_ID; } } -void FixedImageCache::UploadComplete( - bool loadSuccess, - int32_t textureId, - TextureSet textureSet, - bool useAtlasing, - const Vector4& atlasRect ) +void FixedImageCache::LoadComplete(bool loadSuccess, TextureInformation textureInformation) { - bool frontFrameReady = IsFrontReady(); - - if( ! mRequestingLoad ) + if(loadSuccess) { - SetImageFrameReady( textureId ); + mLoadState = TextureManager::LoadState::LOAD_FINISHED; + bool wasCurrentFrameReady = IsFrameReady(mCurrentFrameIndex); + if(!mRequestingLoad) + { + for(std::size_t i = 0; i < mImageUrls.size(); ++i) + { + if(mImageUrls[i].mTextureId == textureInformation.textureId) + { + mReadyFlags[i] = true; + break; + } + } + } + else + { + DALI_ASSERT_ALWAYS(mReadyFlags.size() > 0u && "Some FixedImageCache::LoadBatch() called mismatched!"); + size_t i = mReadyFlags.size() - 1u; - CheckFrontFrame( frontFrameReady ); + // texture id might not setup yet. Update it now. + mImageUrls[i].mTextureId = textureInformation.textureId; + mReadyFlags[i] = true; + } + MakeReady(wasCurrentFrameReady, mCurrentFrameIndex, textureInformation.preMultiplied); } else { - // UploadComplete has been called from within RequestLoad. TextureManager must - // therefore already have the texture cached, so make the texture ready. - // (Use the last texture, as the texture id hasn't been assigned yet) - mReadyFlags.back() = true; + mLoadState = TextureManager::LoadState::LOAD_FAILED; + // preMultiplied should be false because broken image don't premultiply alpha on load + mObserver.FrameReady(TextureSet(), 0, false); } } } //namespace Internal } //namespace Toolkit -} //namespace Dali +} //namespace Dali \ No newline at end of file