X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fanimated-image%2Fanimated-image-visual.cpp;h=a6332c20bf670f65182147dd7af784ac52fd8d28;hb=88991ee4f4798e0faba0877c7379823892d9d7d4;hp=a0ebe451facbef332454a5e5ea62e5aae53274fa;hpb=2bdf1d4dc313e09be9bec6655d34f90d7afede59;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git 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 a0ebe45..a6332c2 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 @@ -82,7 +82,7 @@ Debug::Filter* gAnimImgLogFilter = Debug::Filter::New(Debug::NoLogging, false, " * | new cache * | cache->LoadBatch() * | - * | DoSetOnStage() + * | DoSetOnScene() * | PrepareTextureSet() * | cache->FirstFrame() * | CreateRenderer() (Doesn't become ready until first frame loads) @@ -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,27 +159,26 @@ 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 ) -: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ), +: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO, Toolkit::Visual::ANIMATED_IMAGE ), mFrameDelayTimer(), mPlacementActor(), mImageVisualShaderFactory( shaderFactory ), mPixelArea( FULL_TEXTURE_RECT ), mImageUrl(), - mGifLoading( nullptr ), - mCurrentFrameIndex( 0 ), + mAnimatedImageLoading(), + mFrameIndexForJumpTo( 0 ), mImageUrls( NULL ), mImageCache( NULL ), - mCacheSize( 1 ), - mBatchSize( 1 ), + mCacheSize( 2 ), + mBatchSize( 2 ), mFrameDelay( 100 ), mLoopCount( LOOP_FOREVER ), mCurrentLoopIndex( 0 ), @@ -206,7 +205,7 @@ void AnimatedImageVisual::GetNaturalSize( Vector2& naturalSize ) { if( mImageUrl.IsValid() ) { - mImageSize = mGifLoading->GetImageSize(); + mImageSize = mAnimatedImageLoading.GetImageSize(); } else if( mImageUrls && mImageUrls->size() > 0 ) { @@ -222,6 +221,9 @@ void AnimatedImageVisual::DoCreatePropertyMap( Property::Map& map ) const { map.Clear(); + bool sync = IsSynchronousLoadingRequired(); + map.Insert( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, sync ); + map.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::ANIMATED_IMAGE ); if( mImageUrl.IsValid() ) @@ -270,7 +272,7 @@ void AnimatedImageVisual::OnDoAction( const Dali::Property::Index actionId, cons } case DevelAnimatedImageVisual::Action::PLAY: { - if( IsOnStage() && mActionStatus != DevelAnimatedImageVisual::Action::PLAY ) + if( mFrameDelayTimer && IsOnScene() && mActionStatus != DevelAnimatedImageVisual::Action::PLAY ) { mFrameDelayTimer.Start(); } @@ -282,7 +284,7 @@ void AnimatedImageVisual::OnDoAction( const Dali::Property::Index actionId, cons // STOP reset functionality will actually be done in a future change // Stop will be executed on next timer tick mActionStatus = DevelAnimatedImageVisual::Action::STOP; - if( IsOnStage() ) + if( IsOnScene() ) { DisplayNextFrame(); } @@ -300,8 +302,8 @@ void AnimatedImageVisual::OnDoAction( const Dali::Property::Index actionId, cons else { mIsJumpTo = true; - mCurrentFrameIndex = frameNumber; - if( IsOnStage() ) + mFrameIndexForJumpTo = frameNumber; + if( IsOnScene() ) { DisplayNextFrame(); } @@ -403,7 +405,14 @@ void AnimatedImageVisual::DoSetProperty( Property::Index index, int batchSize; if( value.Get( batchSize ) ) { - mBatchSize = batchSize; + if( batchSize < 2 ) + { + DALI_LOG_ERROR( "The minimum value of batch size is 2." ); + } + else + { + mBatchSize = batchSize; + } } break; } @@ -413,7 +422,14 @@ void AnimatedImageVisual::DoSetProperty( Property::Index index, int cacheSize; if( value.Get( cacheSize ) ) { - mCacheSize = cacheSize; + if( cacheSize < 2 ) + { + DALI_LOG_ERROR( "The minimum value of cache size is 2." ); + } + else + { + mCacheSize = cacheSize; + } } break; } @@ -447,10 +463,25 @@ void AnimatedImageVisual::DoSetProperty( Property::Index index, } break; } + + case Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING: + { + bool sync = false; + value.Get( sync ); + if( sync ) + { + mImpl->mFlags |= Impl::IS_SYNCHRONOUS_RESOURCE_LOADING; + } + else + { + mImpl->mFlags &= ~Impl::IS_SYNCHRONOUS_RESOURCE_LOADING; + } + break; + } } } -void AnimatedImageVisual::DoSetOnStage( Actor& actor ) +void AnimatedImageVisual::DoSetOnScene( Actor& actor ) { mPlacementActor = actor; TextureSet textureSet = PrepareTextureSet(); @@ -466,7 +497,7 @@ void AnimatedImageVisual::DoSetOnStage( Actor& actor ) } } -void AnimatedImageVisual::DoSetOffStage( Actor& actor ) +void AnimatedImageVisual::DoSetOffScene( Actor& actor ) { DALI_ASSERT_DEBUG( (bool)mImpl->mRenderer && "There should always be a renderer whilst on stage"); @@ -513,8 +544,6 @@ void AnimatedImageVisual::CreateRenderer() { mImpl->mRenderer.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, mPixelArea ); } - - mCurrentFrameIndex = 0; } void AnimatedImageVisual::LoadFirstBatch() @@ -542,9 +571,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, IsSynchronousLoadingRequired() ); } else if( mImageUrls ) { @@ -587,16 +616,13 @@ void AnimatedImageVisual::StartFirstFrame( TextureSet& textureSet ) mPlacementActor.Reset(); } - mCurrentFrameIndex = 0; - 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(); @@ -609,16 +635,14 @@ 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; } @@ -638,26 +662,38 @@ void AnimatedImageVisual::SetImageSize( TextureSet& textureSet ) void AnimatedImageVisual::FrameReady( TextureSet textureSet ) { - SetImageSize( textureSet ); - - if( mStartFirstFrame ) + if(textureSet) { - StartFirstFrame( textureSet ); + SetImageSize(textureSet); + + if(mStartFirstFrame) + { + StartFirstFrame(textureSet); + } + else + { + if(mImpl->mRenderer) + { + mImpl->mRenderer.SetTextures(textureSet); + } + } } else { - if(mImpl->mRenderer) - { - mImpl->mRenderer.SetTextures( textureSet ); - } + DALI_LOG_INFO( gAnimImgLogFilter, Debug::Concise, "ResourceReady(ResourceStatus::FAILED)\n" ); + ResourceReady( Toolkit::Visual::ResourceStatus::FAILED ); } } bool AnimatedImageVisual::DisplayNextFrame() { + bool nextFrame = false; + uint32_t frameIndex = mImageCache->GetCurrentFrameIndex(); + if( mIsJumpTo ) { mIsJumpTo = false; + frameIndex = mFrameIndexForJumpTo; } else if( mActionStatus == DevelAnimatedImageVisual::Action::PAUSE ) { @@ -665,14 +701,14 @@ bool AnimatedImageVisual::DisplayNextFrame() } else if( mActionStatus == DevelAnimatedImageVisual::Action::STOP ) { - mCurrentLoopIndex = 0; + frameIndex = 0; if( mStopBehavior == DevelImageVisual::StopBehavior::FIRST_FRAME ) { - mCurrentFrameIndex = 0; + frameIndex = 0; } else if( mStopBehavior == DevelImageVisual::StopBehavior::LAST_FRAME ) { - mCurrentFrameIndex = mFrameCount - 1; + frameIndex = mFrameCount - 1; } else { @@ -683,34 +719,25 @@ bool AnimatedImageVisual::DisplayNextFrame() { if( mFrameCount > 1 ) { - // Wrap the frame index - bool finished = false; - ++mCurrentFrameIndex; - if( mCurrentFrameIndex >= mFrameCount ) + nextFrame = true; + frameIndex++; + if( frameIndex >= mFrameCount ) { + frameIndex %= mFrameCount; ++mCurrentLoopIndex; - finished = true; } - if( mLoopCount < 0 || mCurrentLoopIndex < mLoopCount) - { - if( finished ) - { - mCurrentFrameIndex = 0; // Back to the first frame - } - } - else + if(mLoopCount >= 0 && mCurrentLoopIndex >= mLoopCount) { // This will stop timer mActionStatus = DevelAnimatedImageVisual::Action::STOP; return DisplayNextFrame(); } } - - if( mFrameDelayContainer.Count() > 0 ) + // TODO : newly added one. + if( mAnimatedImageLoading && mImageCache ) { - unsigned int delay = mFrameDelayContainer[mCurrentFrameIndex]; - + unsigned int delay = mImageCache->GetFrameInterval( frameIndex ); if( mFrameDelayTimer.GetInterval() != delay ) { mFrameDelayTimer.SetInterval( delay ); @@ -718,12 +745,20 @@ bool AnimatedImageVisual::DisplayNextFrame() } } - DALI_LOG_INFO( gAnimImgLogFilter,Debug::Concise,"AnimatedImageVisual::DisplayNextFrame(this:%p) CurrentFrameIndex:%d\n", this, mCurrentFrameIndex); + DALI_LOG_INFO( gAnimImgLogFilter,Debug::Concise,"AnimatedImageVisual::DisplayNextFrame(this:%p) CurrentFrameIndex:%d\n", this, frameIndex); TextureSet textureSet; if( mImageCache ) { - textureSet = mImageCache->Frame( mCurrentFrameIndex ); + if(nextFrame) + { + textureSet = mImageCache->NextFrame(); + } + else + { + textureSet = mImageCache->Frame( frameIndex ); + } + if( textureSet ) { SetImageSize( textureSet );