From 5840986c9915193333e5c823d101d4881e9905bf Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Fri, 19 Apr 2024 13:14:36 +0900 Subject: [PATCH] Less call mAnimatedImageLoading.GetImageCount() who might load file synchronously Since AnimatedImageLoading might not load imagefile if we use cached texture. In this case, If we try to call 'GetImageCount()' or similar API, it will try to load file synchronously, what user never notify. For example, when we call DoCreatePropertyMap, it will call that API what we can use some other cached value. Change-Id: I77d30b985efd86d09663dfd51e885ba6227adbc9 Signed-off-by: Eunki, Hong --- .../animated-image/animated-image-visual.cpp | 26 +++++++++++++++++++--- .../rolling-animated-image-cache.cpp | 10 ++++----- .../animated-image/rolling-animated-image-cache.h | 5 +++-- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp index f4a83dc..62a0574 100644 --- a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp +++ b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 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. @@ -19,8 +19,8 @@ #include // EXTERNAL INCLUDES -#include #include +#include #include #include #include @@ -344,7 +344,27 @@ void AnimatedImageVisual::DoCreatePropertyMap(Property::Map& map) const map.Insert(Toolkit::ImageVisual::Property::FRAME_DELAY, static_cast(mFrameDelay)); map.Insert(Toolkit::DevelImageVisual::Property::LOOP_COUNT, static_cast(mLoopCount)); map.Insert(Toolkit::DevelImageVisual::Property::CURRENT_FRAME_NUMBER, (mImageCache) ? static_cast(mImageCache->GetCurrentFrameIndex()) : -1); - map.Insert(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, (mImageCache) ? static_cast((mAnimatedImageLoading) ? mAnimatedImageLoading.GetImageCount() : mImageCache->GetTotalFrameCount()) : -1); + + // 1. Get cached mFrameCount if mFrameCount != 0. + // 2. If we are not using animated image loading, ask to image cache. + // 2-1. If image cache return SINGLE_IMAGE_COUNT or less, It might not a valid value + // (since default frameCount of image cache is SINGLE_IMAGE_COUNT) + // So, let we ask to animated image loader again. + // 2-1-1. If animated image loader return 0, it means that it is not a valid animated image. + // 2-1-2. Otherwise, we can assume that it is valid frame count. + // 2-2. Otherwise, we can assume that it is valid frame count. + uint32_t frameCount = mFrameCount; + if(mImageCache && frameCount == 0) + { + frameCount = mImageCache->GetTotalFrameCount(); + + if(frameCount <= SINGLE_IMAGE_COUNT && mAnimatedImageLoading) + { + frameCount = mAnimatedImageLoading.GetImageCount(); + } + } + + map.Insert(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, (frameCount >= SINGLE_IMAGE_COUNT) ? static_cast(frameCount) : -1); map.Insert(Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, mStopBehavior); diff --git a/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.cpp b/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.cpp index 370a678..c6e7fde 100644 --- a/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.cpp +++ b/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.cpp @@ -118,7 +118,7 @@ TextureSet RollingAnimatedImageCache::Frame(uint32_t frameIndex) synchronouslyLoaded = true; interval = mAnimatedImageLoading.GetFrameInterval(mQueue.Back().mFrameNumber); } - MakeFrameReady(synchronouslyLoaded, textureSet, interval, preMultiplyOnLoading == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD); + MakeFrameReady(synchronouslyLoaded, textureSet, mAnimatedImageLoading.GetImageCount(), interval, preMultiplyOnLoading == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD); } if(popExist || mQueue.IsEmpty() || synchronouslyLoaded) @@ -314,7 +314,7 @@ void RollingAnimatedImageCache::ClearCache() mLoadState = TextureManager::LoadState::NOT_STARTED; } -void RollingAnimatedImageCache::MakeFrameReady(bool loadSuccess, TextureSet textureSet, uint32_t interval, bool preMultiplied) +void RollingAnimatedImageCache::MakeFrameReady(bool loadSuccess, TextureSet textureSet, uint32_t frameCount, uint32_t interval, bool preMultiplied) { if(!loadSuccess) { @@ -327,9 +327,9 @@ void RollingAnimatedImageCache::MakeFrameReady(bool loadSuccess, TextureSet text mLoadState = TextureManager::LoadState::LOAD_FINISHED; // Reset size of Queue according to the real frame count. - if(mFrameCount != mAnimatedImageLoading.GetImageCount()) + if(mFrameCount != frameCount) { - mFrameCount = mAnimatedImageLoading.GetImageCount(); + mFrameCount = frameCount; mTextureIds.resize(mFrameCount); mIntervals.assign(mFrameCount, 0u); } @@ -360,7 +360,7 @@ void RollingAnimatedImageCache::LoadComplete(bool loadSuccess, TextureInformatio textureInformation.textureSet.SetSampler(0u, sampler); } - MakeFrameReady(loadSuccess, textureInformation.textureSet, textureInformation.interval, textureInformation.preMultiplied); + MakeFrameReady(loadSuccess, textureInformation.textureSet, textureInformation.frameCount, textureInformation.interval, textureInformation.preMultiplied); // TODO : We need to remove some below logics, since user can remove Visual during ResourceReady callback. diff --git a/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.h b/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.h index 5c63db5..dde53b8 100644 --- a/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.h +++ b/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_INTERNAL_ROLLING_ANIMATED_IMAGE_CACHE_H /* - * Copyright (c) 2023 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. @@ -169,10 +169,11 @@ private: * * @param[in] loadSuccess whether the loading is succeded or not. * @param[in] textureSet textureSet for this frame. + * @param[in] frameCount Total frame count for this image. * @param[in] interval interval between this frame and next frame. * @param[in] preMultiplied whether the texture is premultied alpha or not. */ - void MakeFrameReady(bool loadSuccess, TextureSet textureSet, uint32_t interval, bool preMultiplied); + void MakeFrameReady(bool loadSuccess, TextureSet textureSet, uint32_t frameCount, uint32_t interval, bool preMultiplied); /** * @brief Pop front entity of Cache. -- 2.7.4