X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fanimated-image%2Fanimated-image-visual.cpp;h=09cad557adbcc4a40e9644d53489bbb6b6d31e18;hp=fdde2601f642c57c1d98af98dd346c50a8df8c14;hb=8c45458b64211285df3df591dfcb628126a1bc0e;hpb=da6b7205afe6a54fb1caf7a765008948a57f45eb 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 fdde260..09cad55 100755 --- a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp +++ b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp @@ -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) @@ -174,11 +174,11 @@ AnimatedImageVisual::AnimatedImageVisual( VisualFactoryCache& factoryCache, Imag mPixelArea( FULL_TEXTURE_RECT ), mImageUrl(), mAnimatedImageLoading(), - mCurrentFrameIndex( 0 ), + mFrameIndexForJumpTo( 0 ), mImageUrls( NULL ), mImageCache( NULL ), - mCacheSize( 1 ), - mBatchSize( 1 ), + mCacheSize( 2 ), + mBatchSize( 2 ), mFrameDelay( 100 ), mLoopCount( LOOP_FOREVER ), mCurrentLoopIndex( 0 ), @@ -221,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() ) @@ -246,6 +249,8 @@ void AnimatedImageVisual::DoCreatePropertyMap( Property::Map& map ) const map.Insert( Toolkit::ImageVisual::Property::CACHE_SIZE, static_cast(mCacheSize) ); 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(mImageCache->GetTotalFrameCount()) : -1 ); map.Insert( Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, mStopBehavior ); } @@ -269,7 +274,7 @@ void AnimatedImageVisual::OnDoAction( const Dali::Property::Index actionId, cons } case DevelAnimatedImageVisual::Action::PLAY: { - if( mFrameDelayTimer && IsOnStage() && mActionStatus != DevelAnimatedImageVisual::Action::PLAY ) + if( mFrameDelayTimer && IsOnScene() && mActionStatus != DevelAnimatedImageVisual::Action::PLAY ) { mFrameDelayTimer.Start(); } @@ -281,7 +286,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(); } @@ -299,8 +304,8 @@ void AnimatedImageVisual::OnDoAction( const Dali::Property::Index actionId, cons else { mIsJumpTo = true; - mCurrentFrameIndex = frameNumber; - if( IsOnStage() ) + mFrameIndexForJumpTo = frameNumber; + if( IsOnScene() ) { DisplayNextFrame(); } @@ -402,7 +407,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; } @@ -412,7 +424,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; } @@ -446,10 +465,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(); @@ -465,7 +499,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"); @@ -478,6 +512,7 @@ void AnimatedImageVisual::DoSetOffStage( Actor& actor ) actor.RemoveRenderer( mImpl->mRenderer ); mImpl->mRenderer.Reset(); mPlacementActor.Reset(); + mStartFirstFrame = false; } void AnimatedImageVisual::OnSetTransform() @@ -512,8 +547,6 @@ void AnimatedImageVisual::CreateRenderer() { mImpl->mRenderer.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, mPixelArea ); } - - mCurrentFrameIndex = 0; } void AnimatedImageVisual::LoadFirstBatch() @@ -543,7 +576,7 @@ void AnimatedImageVisual::LoadFirstBatch() if( mAnimatedImageLoading ) { - mImageCache = new RollingAnimatedImageCache( textureManager, mAnimatedImageLoading, mFrameCount, *this, cacheSize, batchSize ); + mImageCache = new RollingAnimatedImageCache( textureManager, mAnimatedImageLoading, mFrameCount, *this, cacheSize, batchSize, IsSynchronousLoadingRequired() ); } else if( mImageUrls ) { @@ -578,22 +611,21 @@ void AnimatedImageVisual::StartFirstFrame( TextureSet& textureSet ) if(mImpl->mRenderer) { mImpl->mRenderer.SetTextures( textureSet ); - } - Actor actor = mPlacementActor.GetHandle(); - if( actor ) - { - actor.AddRenderer( mImpl->mRenderer ); - mPlacementActor.Reset(); - } - mCurrentFrameIndex = 0; + Actor actor = mPlacementActor.GetHandle(); + if( actor ) + { + actor.AddRenderer( mImpl->mRenderer ); + mPlacementActor.Reset(); + } + } if( mFrameCount > 1 ) { - int frameDelay = mFrameDelay; // from URL array - if( mAnimatedImageLoading && mImageCache ) + int frameDelay = mImageCache->GetFrameInterval( 0 ); + if( frameDelay == 0u ) { - frameDelay = mImageCache->GetFrameInterval( 0 ); + frameDelay = mFrameDelay; // from URL array } mFrameDelayTimer = Timer::New( frameDelay ); mFrameDelayTimer.TickSignal().Connect( this, &AnimatedImageVisual::DisplayNextFrame ); @@ -607,16 +639,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; } @@ -636,99 +666,118 @@ 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() { - if( mIsJumpTo ) - { - mIsJumpTo = false; - } - else if( mActionStatus == DevelAnimatedImageVisual::Action::PAUSE ) - { - return false; - } - else if( mActionStatus == DevelAnimatedImageVisual::Action::STOP ) + bool continueTimer = false; + + if(mImageCache) { - mCurrentLoopIndex = 0; - if( mStopBehavior == DevelImageVisual::StopBehavior::FIRST_FRAME ) - { - mCurrentFrameIndex = 0; - } - else if( mStopBehavior == DevelImageVisual::StopBehavior::LAST_FRAME ) + bool nextFrame = false; + uint32_t frameIndex = mImageCache->GetCurrentFrameIndex(); + + if( mIsJumpTo ) { - mCurrentFrameIndex = mFrameCount - 1; + mIsJumpTo = false; + frameIndex = mFrameIndexForJumpTo; } - else + else if( mActionStatus == DevelAnimatedImageVisual::Action::PAUSE ) { - return false; // Do not draw already rendered scene twice. + return false; } - } - else - { - if( mFrameCount > 1 ) + else if( mActionStatus == DevelAnimatedImageVisual::Action::STOP ) { - // Wrap the frame index - bool finished = false; - ++mCurrentFrameIndex; - if( mCurrentFrameIndex >= mFrameCount ) + frameIndex = 0; + if( mStopBehavior == DevelImageVisual::StopBehavior::FIRST_FRAME ) { - ++mCurrentLoopIndex; - finished = true; + frameIndex = 0; } - - if( mLoopCount < 0 || mCurrentLoopIndex < mLoopCount) + else if( mStopBehavior == DevelImageVisual::StopBehavior::LAST_FRAME ) { - if( finished ) - { - mCurrentFrameIndex = 0; // Back to the first frame - } + frameIndex = mFrameCount - 1; } else { - // This will stop timer - mActionStatus = DevelAnimatedImageVisual::Action::STOP; - return DisplayNextFrame(); + return false; // Do not draw already rendered scene twice. } } - // TODO : newly added one. - if( mAnimatedImageLoading && mImageCache ) + else { - unsigned int delay = mImageCache->GetFrameInterval( mCurrentFrameIndex ); - if( mFrameDelayTimer.GetInterval() != delay ) + if( mFrameCount > 1 ) { - mFrameDelayTimer.SetInterval( delay ); + nextFrame = true; + frameIndex++; + if( frameIndex >= mFrameCount ) + { + frameIndex %= mFrameCount; + ++mCurrentLoopIndex; + } + + if(mLoopCount >= 0 && mCurrentLoopIndex >= mLoopCount) + { + // This will stop timer + mActionStatus = DevelAnimatedImageVisual::Action::STOP; + return DisplayNextFrame(); + } + } + + unsigned int delay = mImageCache->GetFrameInterval( frameIndex ); + if( delay > 0u ) + { + if( mFrameDelayTimer.GetInterval() != delay ) + { + mFrameDelayTimer.SetInterval( delay ); + } } } - } - 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(nextFrame) + { + textureSet = mImageCache->NextFrame(); + } + else + { + textureSet = mImageCache->Frame( frameIndex ); + } - TextureSet textureSet; - if( mImageCache ) - { - textureSet = mImageCache->Frame( mCurrentFrameIndex ); if( textureSet ) { SetImageSize( textureSet ); - mImpl->mRenderer.SetTextures( textureSet ); + if( mImpl->mRenderer ) + { + mImpl->mRenderer.SetTextures( textureSet ); + } } + + continueTimer = ( mActionStatus == DevelAnimatedImageVisual::Action::PLAY ) ? true : false; } - return ( mActionStatus == DevelAnimatedImageVisual::Action::PLAY ) ? true : false; + return continueTimer; }