X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fanimated-vector-image%2Fvector-rasterize-thread.cpp;h=49477eaae6d686dec684a4c137d6ce619cd5a65f;hb=refs%2Fchanges%2F87%2F196487%2F4;hp=52c65414f5cef8016a84e69b2118bd0c2694b1fe;hpb=79267e9786ebcba2b4d79e2f8f75d9b01610e29d;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/visuals/animated-vector-image/vector-rasterize-thread.cpp b/dali-toolkit/internal/visuals/animated-vector-image/vector-rasterize-thread.cpp index 52c6541..49477ea 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/vector-rasterize-thread.cpp +++ b/dali-toolkit/internal/visuals/animated-vector-image/vector-rasterize-thread.cpp @@ -45,29 +45,30 @@ Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New( Debug::NoLogging, } // unnamed namespace -VectorRasterizeThread::VectorRasterizeThread( const std::string& url, Renderer renderer, uint32_t width, uint32_t height ) +VectorRasterizeThread::VectorRasterizeThread( const std::string& url ) : mUrl( url ), mVectorRenderer(), mConditionalWait(), mMutex(), - mResourceReadyTrigger( NULL ), + mResourceReadyTrigger(), + mAnimationFinishedTrigger(), mPlayRange( 0.0f, 1.0f ), + mPlayState( DevelImageVisual::PlayState::STOPPED ), + mProgress( 0.0f ), mCurrentFrame( 0 ), mTotalFrame( 0 ), mStartFrame( 0 ), mEndFrame( 0 ), - mWidth( width ), - mHeight( height ), + mWidth( 0 ), + mHeight( 0 ), mLoopCount( LOOP_FOREVER ), mCurrentLoop( 0 ), mNeedRender( false ), - mPlaying( false ), - mPaused( false ), mDestroyThread( false ), mResourceReady( false ), mLogFactory( Dali::Adaptor::Get().GetLogFactory() ) { - mVectorRenderer = VectorAnimationRenderer::New( mUrl, renderer, width, height ); + mVectorRenderer = VectorAnimationRenderer::New( mUrl ); } VectorRasterizeThread::~VectorRasterizeThread() @@ -85,8 +86,6 @@ VectorRasterizeThread::~VectorRasterizeThread() DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::~VectorRasterizeThread: Join\n" ); Join(); - - delete mResourceReadyTrigger; } void VectorRasterizeThread::Run() @@ -103,34 +102,53 @@ void VectorRasterizeThread::Run() } } -void VectorRasterizeThread::SetSize( uint32_t width, uint32_t height ) +void VectorRasterizeThread::SetRenderer( Renderer renderer ) { ConditionalWait::ScopedLock lock( mConditionalWait ); - mVectorRenderer.SetSize( width, height ); - DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetSize: width = %d, height = %d\n", width, height ); + mVectorRenderer.SetRenderer( renderer ); + + DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetRenderer\n" ); } -void VectorRasterizeThread::StartAnimation() +void VectorRasterizeThread::SetSize( uint32_t width, uint32_t height ) +{ + if( mWidth != width || mHeight != height ) + { + ConditionalWait::ScopedLock lock( mConditionalWait ); + mVectorRenderer.SetSize( width, height ); + + mWidth = width; + mHeight = height; + + mResourceReady = false; + + DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetSize: width = %d, height = %d\n", width, height ); + } +} + +void VectorRasterizeThread::PlayAnimation() { ConditionalWait::ScopedLock lock( mConditionalWait ); - if( !mPlaying ) + if( mPlayState != DevelImageVisual::PlayState::PLAYING ) { - mPlaying = true; - mPaused = false; + mPlayState = DevelImageVisual::PlayState::PLAYING; mConditionalWait.Notify( lock ); - DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::StartAnimation: Start\n" ); + DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::PlayAnimation: Start\n" ); } } void VectorRasterizeThread::StopAnimation() { ConditionalWait::ScopedLock lock( mConditionalWait ); - if( mPlaying ) + if( mPlayState != DevelImageVisual::PlayState::STOPPED ) { - mPlaying = false; - mPaused = false; + mPlayState = DevelImageVisual::PlayState::STOPPED; + + // Reset the current frame and the current loop + mCurrentFrame = mStartFrame; + mCurrentLoop = 0; DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::StopAnimation: Stop\n" ); } @@ -139,79 +157,145 @@ void VectorRasterizeThread::StopAnimation() void VectorRasterizeThread::PauseAnimation() { ConditionalWait::ScopedLock lock( mConditionalWait ); - if( mPlaying && !mPaused ) + if( mPlayState == DevelImageVisual::PlayState::PLAYING ) { - mPaused = true; + mPlayState = DevelImageVisual::PlayState::PAUSED; DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::PauseAnimation: Pause\n" ); } } -void VectorRasterizeThread::ResumeAnimation() +void VectorRasterizeThread::RenderFrame() { ConditionalWait::ScopedLock lock( mConditionalWait ); - if( mPlaying && mPaused ) + + if( !mResourceReady ) { - mPaused = false; + mNeedRender = true; mConditionalWait.Notify( lock ); - DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::ResumeAnimation: Resume\n" ); + DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::RenderFrame: Render\n" ); } } -void VectorRasterizeThread::RenderFrame() +void VectorRasterizeThread::SetResourceReadyCallback( EventThreadCallback* callback ) { ConditionalWait::ScopedLock lock( mConditionalWait ); - mNeedRender = true; - mConditionalWait.Notify( lock ); - - DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::RenderFrame: Render\n" ); + mResourceReadyTrigger = std::unique_ptr< EventThreadCallback >( callback ); } -void VectorRasterizeThread::SetResourceReadyCallback( EventThreadCallback* callback ) +void VectorRasterizeThread::SetAnimationFinishedCallback( EventThreadCallback* callback ) { ConditionalWait::ScopedLock lock( mConditionalWait ); - mResourceReadyTrigger = callback; + mAnimationFinishedTrigger = std::unique_ptr< EventThreadCallback >( callback ); } -void VectorRasterizeThread::SetLoopCount( int16_t count ) +void VectorRasterizeThread::SetLoopCount( int32_t count ) { - ConditionalWait::ScopedLock lock( mConditionalWait ); + if( mLoopCount != count ) + { + ConditionalWait::ScopedLock lock( mConditionalWait ); - mLoopCount = count; + mLoopCount = count; - // Reset progress - mCurrentLoop = 0; - mCurrentFrame = mStartFrame; + // Reset progress + mCurrentLoop = 0; + } +} + +int32_t VectorRasterizeThread::GetLoopCount() const +{ + return mLoopCount; } void VectorRasterizeThread::SetPlayRange( Vector2 range ) { - ConditionalWait::ScopedLock lock( mConditionalWait ); + // Make sure the range specified is between 0.0 and 1.0 + if( range.x >= 0.0f && range.x <= 1.0f && range.y >= 0.0f && range.y <= 1.0f ) + { + Vector2 orderedRange( range ); + // If the range is not in order swap values + if( range.x > range.y ) + { + orderedRange = Vector2( range.y, range.x ); + } - mPlayRange = range; + if( mPlayRange != orderedRange ) + { + ConditionalWait::ScopedLock lock( mConditionalWait ); - if( mTotalFrame != 0 ) - { - mStartFrame = static_cast< uint32_t >( mPlayRange.x * mTotalFrame + 0.5f ); - mEndFrame = static_cast< uint32_t >( mPlayRange.y * mTotalFrame + 0.5f ); + mPlayRange = orderedRange; + + if( mTotalFrame != 0 ) + { + mStartFrame = static_cast< uint32_t >( mPlayRange.x * mTotalFrame + 0.5f ); + mEndFrame = static_cast< uint32_t >( mPlayRange.y * mTotalFrame + 0.5f ); + + // If the current frame is out of the range, change the current frame also. + if( mStartFrame > mCurrentFrame ) + { + mCurrentFrame = mStartFrame; + + mResourceReady = false; + } + else if( mEndFrame < mCurrentFrame ) + { + mCurrentFrame = mEndFrame; + + mResourceReady = false; + } + } + } } } -bool VectorRasterizeThread::IsThreadReady() +Vector2 VectorRasterizeThread::GetPlayRange() const +{ + return mPlayRange; +} + +void VectorRasterizeThread::SetCurrentProgress( float progress ) { ConditionalWait::ScopedLock lock( mConditionalWait ); - if( ( !mPlaying || mPaused ) && !mNeedRender && !mDestroyThread ) + if( progress >= mPlayRange.x && progress <= mPlayRange.y ) { - DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::IsThreadReady: Wait\n" ); + mProgress = progress; - if( !mPlaying ) + if( mTotalFrame != 0 ) { - mCurrentFrame = mStartFrame; - mCurrentLoop = 0; + mCurrentFrame = static_cast< uint32_t >( mTotalFrame * progress + 0.5f ); } + mResourceReady = false; + + DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetCurrentProgress: progress = %f (%d)\n", progress, mCurrentFrame ); + } +} + +float VectorRasterizeThread::GetCurrentProgress() const +{ + return ( static_cast< float >( mCurrentFrame ) / static_cast< float >( mTotalFrame ) ); +} + +DevelImageVisual::PlayState VectorRasterizeThread::GetPlayState() const +{ + return mPlayState; +} + +bool VectorRasterizeThread::IsResourceReady() const +{ + return mResourceReady; +} + +bool VectorRasterizeThread::IsThreadReady() +{ + ConditionalWait::ScopedLock lock( mConditionalWait ); + + if( mPlayState != DevelImageVisual::PlayState::PLAYING && !mNeedRender && !mDestroyThread ) + { + DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::IsThreadReady: Wait\n" ); + mConditionalWait.Wait( lock ); } @@ -229,7 +313,7 @@ bool VectorRasterizeThread::StartRender() mStartFrame = static_cast< uint32_t >( mPlayRange.x * mTotalFrame + 0.5f ); mEndFrame = static_cast< uint32_t >( mPlayRange.y * mTotalFrame + 0.5f ); - mCurrentFrame = mStartFrame; + mCurrentFrame = std::max( static_cast< uint32_t >( mTotalFrame * mProgress + 0.5f ), mStartFrame ); DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::StartRender: Renderer is started [%d (%d, %d)]\n", mTotalFrame, mStartFrame, mEndFrame ); @@ -240,10 +324,18 @@ void VectorRasterizeThread::Rasterize() { DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: [%d]\n", mCurrentFrame ); + bool needRender, resourceReady; + + { + ConditionalWait::ScopedLock lock( mConditionalWait ); + needRender = mNeedRender; + resourceReady = mResourceReady; + } + // Rasterize mVectorRenderer.Render( mCurrentFrame ); - if( mPlaying && !mPaused ) + if( mPlayState == DevelImageVisual::PlayState::PLAYING ) { if( ++mCurrentFrame >= mEndFrame ) { @@ -258,7 +350,15 @@ void VectorRasterizeThread::Rasterize() if( mCurrentLoop >= mLoopCount ) { // Animation is finished - mPlaying = false; + mPlayState = DevelImageVisual::PlayState::STOPPED; + + // Reset the current frame and the current loop + mCurrentFrame = mStartFrame; + mCurrentLoop = 0; + + mAnimationFinishedTrigger->Trigger(); + + DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Animation is finished\n" ); } else { @@ -268,9 +368,12 @@ void VectorRasterizeThread::Rasterize() } } - mNeedRender = false; + if( needRender ) + { + mNeedRender = false; + } - if( !mResourceReady ) + if( !resourceReady ) { DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Resource ready trigger\n" );