From e0a22e262eed4f4ed32fa3f88783e99a3380eb42 Mon Sep 17 00:00:00 2001 From: "Seungho, Baek" Date: Fri, 12 Jun 2020 21:43:23 +0900 Subject: [PATCH] Support WebP format - Modified animated-image-visual to support webp amimated image format - Added and removed some functions of image-cache to use rolling-animated-image-cache for the both of gif and webp - Checked whether mFrameDelayTimer is null or not for the case that Action::PLAY is entered but the system do not support animated webp Change-Id: I254c4c8e715772acb6c0725c58e64aba1a6dafc4 Signed-off-by: Seungho, Baek --- .../dali-toolkit/utc-Dali-AnimatedImageVisual.cpp | 2 +- dali-toolkit/internal/file.list | 2 +- .../animated-image/animated-image-visual.cpp | 35 +++++----- .../visuals/animated-image/animated-image-visual.h | 15 ++--- .../visuals/animated-image/fixed-image-cache.cpp | 26 +++----- .../visuals/animated-image/fixed-image-cache.h | 6 +- .../internal/visuals/animated-image/image-cache.h | 10 ++- ...-cache.cpp => rolling-animated-image-cache.cpp} | 78 +++++++++------------- ...mage-cache.h => rolling-animated-image-cache.h} | 42 ++++++------ .../visuals/animated-image/rolling-image-cache.cpp | 21 +----- .../visuals/animated-image/rolling-image-cache.h | 6 +- .../internal/visuals/visual-factory-impl.cpp | 2 + dali-toolkit/internal/visuals/visual-url.cpp | 12 +++- dali-toolkit/internal/visuals/visual-url.h | 3 +- 14 files changed, 112 insertions(+), 148 deletions(-) rename dali-toolkit/internal/visuals/animated-image/{rolling-gif-image-cache.cpp => rolling-animated-image-cache.cpp} (68%) rename dali-toolkit/internal/visuals/animated-image/{rolling-gif-image-cache.h => rolling-animated-image-cache.h} (72%) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp index bb591dd..bad5ea0 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp @@ -293,7 +293,7 @@ int UtcDaliAnimatedImageVisualStopBehavior(void) } -int UtcDaliAnimatedImageVisualGif01(void) +int UtcDaliAnimatedImageVisualAnimatedImage01(void) { ToolkitTestApplication application; TestGlAbstraction& gl = application.GetGlAbstraction(); diff --git a/dali-toolkit/internal/file.list b/dali-toolkit/internal/file.list index 8f3b2f2..246ba89 100644 --- a/dali-toolkit/internal/file.list +++ b/dali-toolkit/internal/file.list @@ -17,7 +17,7 @@ SET( toolkit_src_files ${toolkit_src_dir}/visuals/animated-image/image-cache.cpp ${toolkit_src_dir}/visuals/animated-image/fixed-image-cache.cpp ${toolkit_src_dir}/visuals/animated-image/rolling-image-cache.cpp - ${toolkit_src_dir}/visuals/animated-image/rolling-gif-image-cache.cpp + ${toolkit_src_dir}/visuals/animated-image/rolling-animated-image-cache.cpp ${toolkit_src_dir}/visuals/animated-vector-image/animated-vector-image-visual.cpp ${toolkit_src_dir}/visuals/animated-vector-image/vector-animation-task.cpp ${toolkit_src_dir}/visuals/animated-vector-image/vector-animation-thread.cpp 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 386013a..fdde260 100755 --- a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp +++ b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include #include @@ -111,7 +111,7 @@ Debug::Filter* gAnimImgLogFilter = Debug::Filter::New(Debug::NoLogging, false, " AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties ) { AnimatedImageVisualPtr visual( new AnimatedImageVisual( factoryCache, shaderFactory ) ); - visual->InitializeGif( imageUrl ); + visual->InitializeAnimatedImage( imageUrl ); visual->SetProperties( properties ); if( visual->mFrameCount > 0 ) @@ -149,7 +149,7 @@ AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCach AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl ) { AnimatedImageVisualPtr visual( new AnimatedImageVisual( factoryCache, shaderFactory ) ); - visual->InitializeGif( imageUrl ); + visual->InitializeAnimatedImage( imageUrl ); if( visual->mFrameCount > 0 ) { @@ -159,12 +159,11 @@ AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCach return visual; } -void AnimatedImageVisual::InitializeGif( const VisualUrl& imageUrl ) +void AnimatedImageVisual::InitializeAnimatedImage( const VisualUrl& imageUrl ) { mImageUrl = imageUrl; - mGifLoading = GifLoading::New( imageUrl.GetUrl(), imageUrl.IsLocalResource() ); - mFrameCount = mGifLoading->GetImageCount(); - mGifLoading->LoadFrameDelays( mFrameDelayContainer ); + mAnimatedImageLoading = AnimatedImageLoading::New( imageUrl.GetUrl(), imageUrl.IsLocalResource() ); + mFrameCount = mAnimatedImageLoading.GetImageCount(); } AnimatedImageVisual::AnimatedImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory ) @@ -174,7 +173,7 @@ AnimatedImageVisual::AnimatedImageVisual( VisualFactoryCache& factoryCache, Imag mImageVisualShaderFactory( shaderFactory ), mPixelArea( FULL_TEXTURE_RECT ), mImageUrl(), - mGifLoading( nullptr ), + mAnimatedImageLoading(), mCurrentFrameIndex( 0 ), mImageUrls( NULL ), mImageCache( NULL ), @@ -206,7 +205,7 @@ void AnimatedImageVisual::GetNaturalSize( Vector2& naturalSize ) { if( mImageUrl.IsValid() ) { - mImageSize = mGifLoading->GetImageSize(); + mImageSize = mAnimatedImageLoading.GetImageSize(); } else if( mImageUrls && mImageUrls->size() > 0 ) { @@ -270,7 +269,7 @@ void AnimatedImageVisual::OnDoAction( const Dali::Property::Index actionId, cons } case DevelAnimatedImageVisual::Action::PLAY: { - if( IsOnStage() && mActionStatus != DevelAnimatedImageVisual::Action::PLAY ) + if( mFrameDelayTimer && IsOnStage() && mActionStatus != DevelAnimatedImageVisual::Action::PLAY ) { mFrameDelayTimer.Start(); } @@ -542,9 +541,9 @@ void AnimatedImageVisual::LoadFirstBatch() mUrlIndex = 0; TextureManager& textureManager = mFactoryCache.GetTextureManager(); - if( mGifLoading != nullptr ) + if( mAnimatedImageLoading ) { - mImageCache = new RollingGifImageCache( textureManager, *mGifLoading, mFrameCount, *this, cacheSize, batchSize ); + mImageCache = new RollingAnimatedImageCache( textureManager, mAnimatedImageLoading, mFrameCount, *this, cacheSize, batchSize ); } else if( mImageUrls ) { @@ -592,11 +591,10 @@ void AnimatedImageVisual::StartFirstFrame( TextureSet& textureSet ) if( mFrameCount > 1 ) { int frameDelay = mFrameDelay; // from URL array - if( mFrameDelayContainer.Count() > 0 ) // from GIF + if( mAnimatedImageLoading && mImageCache ) { - frameDelay = mFrameDelayContainer[0]; + frameDelay = mImageCache->GetFrameInterval( 0 ); } - mFrameDelayTimer = Timer::New( frameDelay ); mFrameDelayTimer.TickSignal().Connect( this, &AnimatedImageVisual::DisplayNextFrame ); mFrameDelayTimer.Start(); @@ -706,11 +704,10 @@ bool AnimatedImageVisual::DisplayNextFrame() return DisplayNextFrame(); } } - - if( mFrameDelayContainer.Count() > 0 ) + // TODO : newly added one. + if( mAnimatedImageLoading && mImageCache ) { - unsigned int delay = mFrameDelayContainer[mCurrentFrameIndex]; - + unsigned int delay = mImageCache->GetFrameInterval( mCurrentFrameIndex ); if( mFrameDelayTimer.GetInterval() != delay ) { mFrameDelayTimer.SetInterval( delay ); diff --git a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.h b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.h index 0d21f97..7c0764e 100755 --- a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.h +++ b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include // INTERNAL INCLUDES #include @@ -92,7 +92,7 @@ public: * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object * @param[in] shaderFactory The ImageVisualShaderFactory object - * @param[in] imageUrl The URL to gif resource to use + * @param[in] imageUrl The URL to animated image resource to use * @param[in] properties A Property::Map containing settings for this visual * @return A smart-pointer to the newly allocated visual. */ @@ -224,10 +224,10 @@ private: bool DisplayNextFrame(); /** - * Initialize the gif variables. - * @param[in] imageUrl The url of the animated gif + * Initialize the animated image variables. + * @param[in] imageUrl The url of the animated image */ - void InitializeGif( const VisualUrl& imageUrl ); + void InitializeAnimatedImage( const VisualUrl& imageUrl ); // Undefined AnimatedImageVisual( const AnimatedImageVisual& animatedImageVisual ); @@ -241,11 +241,10 @@ private: WeakHandle mPlacementActor; ImageVisualShaderFactory& mImageVisualShaderFactory; - // Variables for GIF player - Dali::Vector mFrameDelayContainer; + // Variables for Animated Image player Vector4 mPixelArea; VisualUrl mImageUrl; - std::unique_ptr mGifLoading; // Only needed for animated gifs + Dali::AnimatedImageLoading mAnimatedImageLoading; // Only needed for animated image uint32_t mCurrentFrameIndex; // Frame index into textureRects // Variables for Multi-Image player 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 d71ee94..726cd39 100644 --- a/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp +++ b/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp @@ -58,8 +58,14 @@ TextureSet FixedImageCache::Frame( uint32_t frameIndex ) { while( frameIndex > mFront ) { - NextFrame(); + ++mFront; + if( mFront >= mImageUrls.size() ) + { + mFront = 0; + } + LoadBatch(); } + mFront = frameIndex; TextureSet textureSet; @@ -87,23 +93,9 @@ TextureSet FixedImageCache::FirstFrame() return textureSet; } -TextureSet FixedImageCache::NextFrame() +uint32_t FixedImageCache::GetFrameInterval( uint32_t frameIndex ) { - TextureSet textureSet; - ++mFront; - mFront %= mImageUrls.size(); - - if( IsFrontReady() == true ) - { - textureSet = GetFrontTextureSet(); - } - else - { - mWaitingForReadyFrame = true; - } - LoadBatch(); - - return textureSet; + return 0u; } bool FixedImageCache::IsFrontReady() const diff --git a/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.h b/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.h index d884e28..5063232 100644 --- a/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.h +++ b/dali-toolkit/internal/visuals/animated-image/fixed-image-cache.h @@ -61,11 +61,9 @@ public: TextureSet FirstFrame() override; /** - * Get the next frame. If it's not ready, this will trigger the - * sending of FrameReady() when the image becomes ready. - * This will trigger the loading of the next batch. + * Get the interval of Nth frame. */ - TextureSet NextFrame() override; + uint32_t GetFrameInterval( uint32_t frameIndex ) override; private: /** diff --git a/dali-toolkit/internal/visuals/animated-image/image-cache.h b/dali-toolkit/internal/visuals/animated-image/image-cache.h index 7354992..1d385c8 100644 --- a/dali-toolkit/internal/visuals/animated-image/image-cache.h +++ b/dali-toolkit/internal/visuals/animated-image/image-cache.h @@ -79,17 +79,15 @@ public: virtual TextureSet FirstFrame() = 0; /** - * Get the next frame. If it's not ready, this will trigger the + * Get the Nth frame. If it's not ready, this will trigger the * sending of FrameReady() when the image becomes ready. - * This will trigger the loading of the next batch. */ - virtual TextureSet NextFrame() = 0; + virtual TextureSet Frame( uint32_t frameIndex ) = 0; /** - * Get the Nth frame. If it's not ready, this will trigger the - * sending of FrameReady() when the image becomes ready. + * Get the interval of Nth frame. */ - virtual TextureSet Frame( uint32_t frameIndex ) = 0; + virtual uint32_t GetFrameInterval( uint32_t frameIndex ) = 0; private: diff --git a/dali-toolkit/internal/visuals/animated-image/rolling-gif-image-cache.cpp b/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.cpp similarity index 68% rename from dali-toolkit/internal/visuals/animated-image/rolling-gif-image-cache.cpp rename to dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.cpp index 04f0f1d..c421678 100644 --- a/dali-toolkit/internal/visuals/animated-image/rolling-gif-image-cache.cpp +++ b/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.cpp @@ -15,7 +15,7 @@ */ // CLASS HEADER -#include "rolling-gif-image-cache.h" +#include "rolling-animated-image-cache.h" // EXTERNAL HEADERS @@ -58,11 +58,11 @@ namespace Toolkit namespace Internal { -RollingGifImageCache::RollingGifImageCache( - TextureManager& textureManager, GifLoading& gifLoading, uint32_t frameCount, ImageCache::FrameReadyObserver& observer, +RollingAnimatedImageCache::RollingAnimatedImageCache( + TextureManager& textureManager, AnimatedImageLoading& animatedImageLoading, uint32_t frameCount, ImageCache::FrameReadyObserver& observer, uint16_t cacheSize, uint16_t batchSize ) : ImageCache( textureManager, observer, batchSize ), - mGifLoading( gifLoading ), + mAnimatedImageLoading( animatedImageLoading ), mFrameCount( frameCount ), mFrameIndex( 0 ), mCacheSize( cacheSize ), @@ -72,11 +72,11 @@ RollingGifImageCache::RollingGifImageCache( LoadBatch(); } -RollingGifImageCache::~RollingGifImageCache() +RollingAnimatedImageCache::~RollingAnimatedImageCache() { if( mTextureManagerAlive ) { - while( !mQueue.IsEmpty() ) + while( IsFrontReady() ) { ImageFrame imageFrame = mQueue.PopFront(); Dali::Toolkit::TextureManager::RemoveTexture( mImageUrls[ imageFrame.mFrameNumber ].mUrl ); @@ -84,64 +84,51 @@ RollingGifImageCache::~RollingGifImageCache() } } -TextureSet RollingGifImageCache::Frame( uint32_t frameIndex ) +TextureSet RollingAnimatedImageCache::Frame( uint32_t frameIndex ) { - // If a frame of frameIndex is not loaded, clear the queue and remove all loaded textures. - if( mImageUrls[ frameIndex ].mTextureId == TextureManager::INVALID_TEXTURE_ID ) + bool popExist = false; + while( IsFrontReady() && mQueue.Front().mFrameNumber != frameIndex ) { - mFrameIndex = frameIndex; - while( !mQueue.IsEmpty() ) - { - ImageFrame imageFrame = mQueue.PopFront(); - Dali::Toolkit::TextureManager::RemoveTexture( mImageUrls[ imageFrame.mFrameNumber ].mUrl ); - mImageUrls[ imageFrame.mFrameNumber ].mTextureId = TextureManager::INVALID_TEXTURE_ID; - } - LoadBatch(); + ImageFrame imageFrame = mQueue.PopFront(); + Dali::Toolkit::TextureManager::RemoveTexture( mImageUrls[ imageFrame.mFrameNumber ].mUrl ); + mImageUrls[ imageFrame.mFrameNumber ].mTextureId = TextureManager::INVALID_TEXTURE_ID; + popExist = true; } - // If the frame is already loaded, remove previous frames of the frame in the queue - // and load new frames amount of removed frames. - else + if( popExist || mImageUrls[ frameIndex ].mTextureId == TextureManager::INVALID_TEXTURE_ID ) { - bool popExist = false; - while( !mQueue.IsEmpty() && mQueue.Front().mFrameNumber != frameIndex ) + // If the frame of frameIndex was already loaded, load batch from the last frame of queue + if( IsFrontReady() ) { - ImageFrame imageFrame = mQueue.PopFront(); - Dali::Toolkit::TextureManager::RemoveTexture( mImageUrls[ imageFrame.mFrameNumber ].mUrl ); - mImageUrls[ imageFrame.mFrameNumber ].mTextureId = TextureManager::INVALID_TEXTURE_ID; - popExist = true; + mFrameIndex = ( mQueue.Back().mFrameNumber + 1 ) % mFrameCount; } - if( popExist ) + // If the queue is empty, load batch from the frame of frameIndex + else { - mFrameIndex = ( mQueue.Back().mFrameNumber + 1 ) % mFrameCount; - LoadBatch(); + mFrameIndex = frameIndex; } + LoadBatch(); } return GetFrontTextureSet(); } -TextureSet RollingGifImageCache::FirstFrame() +TextureSet RollingAnimatedImageCache::FirstFrame() { return Frame( 0u ); } -TextureSet RollingGifImageCache::NextFrame() +uint32_t RollingAnimatedImageCache::GetFrameInterval( uint32_t frameIndex ) { - ImageFrame imageFrame = mQueue.PopFront(); - Dali::Toolkit::TextureManager::RemoveTexture( mImageUrls[ imageFrame.mFrameNumber ].mUrl ); - mImageUrls[ imageFrame.mFrameNumber ].mTextureId = TextureManager::INVALID_TEXTURE_ID; - - LoadBatch(); - - return GetFrontTextureSet(); + Frame( frameIndex ); + return mAnimatedImageLoading.GetFrameInterval( frameIndex ); } -bool RollingGifImageCache::IsFrontReady() const +bool RollingAnimatedImageCache::IsFrontReady() const { return ( !mQueue.IsEmpty() ); } -void RollingGifImageCache::LoadBatch() +void RollingAnimatedImageCache::LoadBatch() { // Try and load up to mBatchSize images, until the cache is filled. // Once the cache is filled, as frames progress, the old frame is @@ -151,9 +138,8 @@ void RollingGifImageCache::LoadBatch() // Get the smallest number of frames we need to load int batchSize = std::min( std::size_t(mBatchSize), mCacheSize - mQueue.Count() ); - DALI_LOG_INFO( gAnimImgLogFilter, Debug::Concise, "RollingGifImageCache::LoadBatch() mFrameIndex:%d batchSize:%d\n", mFrameIndex, batchSize ); - - if( mGifLoading.LoadNextNFrames( mFrameIndex, batchSize, pixelDataList) ) + DALI_LOG_INFO( gAnimImgLogFilter, Debug::Concise, "RollingAnimatedImageCache::LoadBatch() mFrameIndex:%d batchSize:%d\n", mFrameIndex, batchSize ); + if( mAnimatedImageLoading.LoadNextNFrames( mFrameIndex, batchSize, pixelDataList) ) { unsigned int pixelDataListCount = pixelDataList.size(); @@ -203,15 +189,15 @@ void RollingGifImageCache::LoadBatch() LOG_CACHE; } -TextureSet RollingGifImageCache::GetFrontTextureSet() const +TextureSet RollingAnimatedImageCache::GetFrontTextureSet() const { - DALI_LOG_INFO( gAnimImgLogFilter, Debug::Concise, "RollingGifImageCache::GetFrontTextureSet() FrameNumber:%d\n", mQueue[ 0 ].mFrameNumber ); + DALI_LOG_INFO( gAnimImgLogFilter, Debug::Concise, "RollingAnimatedImageCache::GetFrontTextureSet() FrameNumber:%d\n", mQueue[ 0 ].mFrameNumber ); TextureManager::TextureId textureId = GetCachedTextureId( 0 ); return mTextureManager.GetTextureSet( textureId ); } -TextureManager::TextureId RollingGifImageCache::GetCachedTextureId( int index ) const +TextureManager::TextureId RollingAnimatedImageCache::GetCachedTextureId( int index ) const { return mImageUrls[ mQueue[ index ].mFrameNumber ].mTextureId; } diff --git a/dali-toolkit/internal/visuals/animated-image/rolling-gif-image-cache.h b/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.h similarity index 72% rename from dali-toolkit/internal/visuals/animated-image/rolling-gif-image-cache.h rename to dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.h index 91a1210..503f65e 100644 --- a/dali-toolkit/internal/visuals/animated-image/rolling-gif-image-cache.h +++ b/dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.h @@ -1,5 +1,5 @@ -#ifndef DALI_TOOLKIT_INTERNAL_ROLLING_GIF_IMAGE_CACHE_H -#define DALI_TOOLKIT_INTERNAL_ROLLING_GIF_IMAGE_CACHE_H +#ifndef DALI_TOOLKIT_INTERNAL_ROLLING_ANIMATED_IMAGE_CACHE_H +#define DALI_TOOLKIT_INTERNAL_ROLLING_ANIMATED_IMAGE_CACHE_H /* * Copyright (c) 2020 Samsung Electronics Co., Ltd. @@ -18,7 +18,7 @@ */ // EXTERNAL INCLUDES -#include +#include #include #include #include @@ -31,20 +31,20 @@ namespace Internal { /** - * Class to manage a rolling cache of GIF images, where the cache size + * Class to manage a rolling cache of Animated images, where the cache size * is smaller than the total number of images. * * Frames are always ready, so the observer.FrameReady callback is never triggered; * the FirstFrame and NextFrame APIs will always return a texture. */ -class RollingGifImageCache : public ImageCache +class RollingAnimatedImageCache : public ImageCache { public: /** * Constructor. * @param[in] textureManager The texture manager - * @param[in] gifLoader The loaded gif image - * @param[in] frameCount The number of frames in the gif + * @param[in] animatedImageLoader The loaded animated image + * @param[in] frameCount The number of frames in the animated image * @param[in] observer FrameReady observer * @param[in] cacheSize The size of the cache * @param[in] batchSize The size of a batch to load @@ -52,8 +52,8 @@ public: * This will start loading textures immediately, according to the * batch and cache sizes. */ - RollingGifImageCache( TextureManager& textureManager, - GifLoading& gifLoader, + RollingAnimatedImageCache( TextureManager& textureManager, + AnimatedImageLoading& animatedImageLoader, uint32_t frameCount, ImageCache::FrameReadyObserver& observer, uint16_t cacheSize, @@ -62,7 +62,7 @@ public: /** * Destructor */ - virtual ~RollingGifImageCache(); + virtual ~RollingAnimatedImageCache(); /** * Get the Nth frame. If it's not ready, this will trigger the @@ -77,11 +77,9 @@ public: TextureSet FirstFrame() override; /** - * Get the next frame. If it's not ready, this will trigger the - * sending of FrameReady() when the image becomes ready. - * This will trigger the loading of the next batch. + * Get the interval of Nth frame. */ - TextureSet NextFrame() override; + uint32_t GetFrameInterval( uint32_t frameIndex ) override; private: /** @@ -114,16 +112,18 @@ private: unsigned int mFrameNumber = 0u; }; - GifLoading& mGifLoading; - uint32_t mFrameCount; - int mFrameIndex; - std::vector mImageUrls; - uint16_t mCacheSize; - CircularQueue mQueue; + Dali::AnimatedImageLoading& mAnimatedImageLoading; + uint32_t mFrameCount; + int mFrameIndex; + std::vector mImageUrls; + uint16_t mCacheSize; + CircularQueue mQueue; }; } // namespace Internal + } // namespace Toolkit + } // namespace Dali -#endif +#endif //DALI_TOOLKIT_INTERNAL_ROLLING_ANIMATED_IMAGE_CACHE_H diff --git a/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.cpp b/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.cpp index 21f81b7..2284778 100644 --- a/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.cpp +++ b/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.cpp @@ -131,26 +131,9 @@ TextureSet RollingImageCache::FirstFrame() return Frame( 0u ); } -TextureSet RollingImageCache::NextFrame() +uint32_t RollingImageCache::GetFrameInterval( uint32_t frameIndex ) { - TextureSet textureSet; - - ImageFrame imageFrame = mQueue.PopFront(); - mTextureManager.Remove( mImageUrls[ imageFrame.mUrlIndex ].mTextureId, this ); - mImageUrls[ imageFrame.mUrlIndex ].mTextureId = TextureManager::INVALID_TEXTURE_ID; - - LoadBatch(); - - if( IsFrontReady() == true ) - { - textureSet = GetFrontTextureSet(); - } - else - { - mWaitingForReadyFrame = true; - } - - return textureSet; + return 0u; } bool RollingImageCache::IsFrontReady() const diff --git a/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.h b/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.h index 47a5155..f57b5c2 100644 --- a/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.h +++ b/dali-toolkit/internal/visuals/animated-image/rolling-image-cache.h @@ -72,11 +72,9 @@ public: TextureSet FirstFrame() override; /** - * Get the next frame. If it's not ready, this will trigger the - * sending of FrameReady() when the image becomes ready. - * This will trigger the loading of the next batch. + * Get the interval of Nth frame. */ - TextureSet NextFrame() override; + uint32_t GetFrameInterval( uint32_t frameIndex ) override; private: /** diff --git a/dali-toolkit/internal/visuals/visual-factory-impl.cpp b/dali-toolkit/internal/visuals/visual-factory-impl.cpp index 2531a84..9e5238d 100644 --- a/dali-toolkit/internal/visuals/visual-factory-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-factory-impl.cpp @@ -164,6 +164,7 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property break; } case VisualUrl::GIF: + case VisualUrl::WEBP: { visualPtr = AnimatedImageVisual::New( GetFactoryCache(), GetImageVisualShaderFactory(), visualUrl, propertyMap ); break; @@ -334,6 +335,7 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const std::string& url, Image break; } case VisualUrl::GIF: + case VisualUrl::WEBP: { visualPtr = AnimatedImageVisual::New( GetFactoryCache(), GetImageVisualShaderFactory(), visualUrl ); break; diff --git a/dali-toolkit/internal/visuals/visual-url.cpp b/dali-toolkit/internal/visuals/visual-url.cpp index 731ed20..451ac06 100644 --- a/dali-toolkit/internal/visuals/visual-url.cpp +++ b/dali-toolkit/internal/visuals/visual-url.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -99,9 +99,11 @@ VisualUrl::Type ResolveType( const std::string& url ) enum { SUFFIX, HASH, HASH_DOT } state = SUFFIX; char SVG[ 4 ] = { 'g', 'v', 's', '.' }; char GIF[ 4 ] = { 'f', 'i', 'g', '.' }; + char WEBP[ 5 ] = { 'p', 'b', 'e', 'w', '.' }; char JSON[ 5 ] = { 'n', 'o', 's', 'j', '.' }; unsigned int svgScore = 0; unsigned int gifScore = 0; + unsigned int webpScore = 0; unsigned int jsonScore = 0; int index = count; while( --index >= 0 ) @@ -124,6 +126,14 @@ VisualUrl::Type ResolveType( const std::string& url ) return VisualUrl::GIF; } } + if( ( offsetFromEnd < sizeof(WEBP) )&&( currentChar == WEBP[ offsetFromEnd ] ) ) + { + // early out if WEBP as can't be used in N patch for now + if( ++webpScore == sizeof(WEBP) ) + { + return VisualUrl::WEBP; + } + } if( ( offsetFromEnd < sizeof(JSON) )&&( currentChar == JSON[ offsetFromEnd ] ) ) { // early out if JSON as can't be used in N patch for now diff --git a/dali-toolkit/internal/visuals/visual-url.h b/dali-toolkit/internal/visuals/visual-url.h index f3af2e0..63ad5e4 100644 --- a/dali-toolkit/internal/visuals/visual-url.h +++ b/dali-toolkit/internal/visuals/visual-url.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_INTERNAL_VISUAL_URL_H /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -41,6 +41,7 @@ public: N_PATCH, SVG, GIF, + WEBP, JSON }; -- 2.7.4