+ mCurrentFrameIndex = 0;
+}
+
+void AnimatedImageVisual::LoadFirstBatch()
+{
+ // Ensure the batch size and cache size are no bigger than the number of URLs,
+ // and that the cache is at least as big as the batch size.
+ uint16_t numUrls = 0;
+ uint16_t batchSize = 1;
+ uint16_t cacheSize = 1;
+
+ if( mImageUrls )
+ {
+ numUrls = mImageUrls->size();
+ }
+ else
+ {
+ numUrls = mFrameCount;
+ }
+
+ batchSize = std::min( mBatchSize, numUrls );
+ cacheSize = std::min( std::max( batchSize, mCacheSize ), numUrls );
+
+ DALI_LOG_INFO(gAnimImgLogFilter,Debug::Concise,"AnimatedImageVisual::LoadFirstBatch() batchSize:%d cacheSize:%d\n", batchSize, cacheSize);
+
+ mUrlIndex = 0;
+ TextureManager& textureManager = mFactoryCache.GetTextureManager();
+
+ if( mGifLoading != nullptr )
+ {
+ mImageCache = new RollingGifImageCache( textureManager, *mGifLoading, mFrameCount, *this, cacheSize, batchSize );
+ }
+ else if( mImageUrls )
+ {
+ if( batchSize > 0 && cacheSize > 0 )
+ {
+ if( cacheSize < numUrls )
+ {
+ mImageCache = new RollingImageCache( textureManager, *mImageUrls, *this, cacheSize, batchSize );
+ }
+ else
+ {
+ mImageCache = new FixedImageCache( textureManager, *mImageUrls, *this, batchSize );
+ }
+ }
+ else
+ {
+ mImageCache = new RollingImageCache( textureManager, *mImageUrls, *this, 1, 1 );
+ }
+ }
+
+ if (!mImageCache)
+ {
+ DALI_LOG_ERROR("mImageCache is null");
+ }
+}
+
+void AnimatedImageVisual::StartFirstFrame( TextureSet& textureSet )
+{
+ DALI_LOG_INFO(gAnimImgLogFilter,Debug::Concise,"AnimatedImageVisual::StartFirstFrame()\n");
+
+ mStartFirstFrame = false;
+ mImpl->mRenderer.SetTextures( textureSet );
+ Actor actor = mPlacementActor.GetHandle();
+ if( actor )
+ {
+ actor.AddRenderer( mImpl->mRenderer );
+ mPlacementActor.Reset();
+ }
+
+ mCurrentFrameIndex = 0;
+
+ if( mFrameCount > 1 )
+ {
+ int frameDelay = mFrameDelay; // from URL array
+ if( mFrameDelayContainer.Count() > 0 ) // from GIF
+ {
+ frameDelay = mFrameDelayContainer[0];
+ }
+
+ mFrameDelayTimer = Timer::New( frameDelay );
+ mFrameDelayTimer.TickSignal().Connect( this, &AnimatedImageVisual::DisplayNextFrame );
+ mFrameDelayTimer.Start();
+ }
+ DALI_LOG_INFO(gAnimImgLogFilter,Debug::Concise,"ResourceReady(ResourceStatus::READY)\n");
+ ResourceReady( Toolkit::Visual::ResourceStatus::READY );
+}
+
+TextureSet AnimatedImageVisual::PrepareTextureSet()
+{
+ TextureSet textureSet;
+ if (mImageCache)
+ textureSet = mImageCache->FirstFrame();
+ if( textureSet )
+ {
+ SetImageSize( textureSet );
+ }
+ else
+ {
+ DALI_LOG_INFO(gAnimImgLogFilter,Debug::Concise,"ResourceReady(ResourceStatus::FAILED)\n");
+ ResourceReady( Toolkit::Visual::ResourceStatus::FAILED );
+ }
+
+ return textureSet;
+}
+
+void AnimatedImageVisual::SetImageSize( TextureSet& textureSet )
+{
+ if( textureSet )
+ {
+ Texture texture = textureSet.GetTexture( 0 );
+ if( texture )
+ {
+ mImageSize.SetWidth( texture.GetWidth() );
+ mImageSize.SetHeight( texture.GetHeight() );
+ }
+ }
+}
+
+void AnimatedImageVisual::FrameReady( TextureSet textureSet )
+{
+ SetImageSize( textureSet );
+
+ if( mStartFirstFrame )
+ {
+ StartFirstFrame( textureSet );
+ }
+ else
+ {
+ mImpl->mRenderer.SetTextures( textureSet );
+ }