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=456b89e34fde7673cac8b8dbda6b2a84de09b42a;hb=8c45458b64211285df3df591dfcb628126a1bc0e;hpb=dea624eb348a4926d8761c8a1364f03f9f71acf5 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 456b89e..09cad55 100755 --- a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp +++ b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp @@ -174,7 +174,7 @@ AnimatedImageVisual::AnimatedImageVisual( VisualFactoryCache& factoryCache, Imag mPixelArea( FULL_TEXTURE_RECT ), mImageUrl(), mAnimatedImageLoading(), - mCurrentFrameIndex( 0 ), + mFrameIndexForJumpTo( 0 ), mImageUrls( NULL ), mImageCache( NULL ), mCacheSize( 2 ), @@ -249,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 ); } @@ -302,7 +304,7 @@ void AnimatedImageVisual::OnDoAction( const Dali::Property::Index actionId, cons else { mIsJumpTo = true; - mCurrentFrameIndex = frameNumber; + mFrameIndexForJumpTo = frameNumber; if( IsOnScene() ) { DisplayNextFrame(); @@ -510,6 +512,7 @@ void AnimatedImageVisual::DoSetOffScene( Actor& actor ) actor.RemoveRenderer( mImpl->mRenderer ); mImpl->mRenderer.Reset(); mPlacementActor.Reset(); + mStartFirstFrame = false; } void AnimatedImageVisual::OnSetTransform() @@ -544,8 +547,6 @@ void AnimatedImageVisual::CreateRenderer() { mImpl->mRenderer.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, mPixelArea ); } - - mCurrentFrameIndex = 0; } void AnimatedImageVisual::LoadFirstBatch() @@ -610,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 ); @@ -642,15 +642,11 @@ TextureSet AnimatedImageVisual::PrepareTextureSet() { 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; } @@ -670,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 ) + bool nextFrame = false; + uint32_t frameIndex = mImageCache->GetCurrentFrameIndex(); + + if( mIsJumpTo ) { - mCurrentFrameIndex = 0; + mIsJumpTo = false; + frameIndex = mFrameIndexForJumpTo; } - else if( mStopBehavior == DevelImageVisual::StopBehavior::LAST_FRAME ) + else if( mActionStatus == DevelAnimatedImageVisual::Action::PAUSE ) { - mCurrentFrameIndex = mFrameCount - 1; + return false; } - else + else if( mActionStatus == DevelAnimatedImageVisual::Action::STOP ) { - return false; // Do not draw already rendered scene twice. - } - } - else - { - if( mFrameCount > 1 ) - { - // 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; }