*/
// CLASS HEADER
-#include "rolling-gif-image-cache.h"
+#include "rolling-animated-image-cache.h"
// EXTERNAL HEADERS
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 ),
LoadBatch();
}
-RollingGifImageCache::~RollingGifImageCache()
+RollingAnimatedImageCache::~RollingAnimatedImageCache()
{
if( mTextureManagerAlive )
{
- while( !mQueue.IsEmpty() )
+ while( IsFrontReady() )
{
ImageFrame imageFrame = mQueue.PopFront();
Dali::Toolkit::TextureManager::RemoveTexture( mImageUrls[ imageFrame.mFrameNumber ].mUrl );
}
}
-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
// 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();
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;
}