X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fanimated-vector-image%2Fvector-rasterize-thread.cpp;h=35f485f952577353732c47ca976931c395eb2f4d;hp=52c65414f5cef8016a84e69b2118bd0c2694b1fe;hb=7c1ca2d9ab3bc63f3dc164c4f5d4ea0d8bf5ba3e;hpb=3ca7994488b0b5e21bbb0d262c5fa2e4c731308b 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..35f485f 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,59 +102,69 @@ 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 ) { - ConditionalWait::ScopedLock lock( mConditionalWait ); - if( !mPlaying ) + if( mWidth != width || mHeight != height ) { - mPlaying = true; - mPaused = false; - mConditionalWait.Notify( lock ); + ConditionalWait::ScopedLock lock( mConditionalWait ); + mVectorRenderer.SetSize( width, height ); - DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::StartAnimation: Start\n" ); + mWidth = width; + mHeight = height; + + mResourceReady = false; + + DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::SetSize: width = %d, height = %d\n", width, height ); } } -void VectorRasterizeThread::StopAnimation() +void VectorRasterizeThread::PlayAnimation() { ConditionalWait::ScopedLock lock( mConditionalWait ); - if( mPlaying ) + if( mPlayState != DevelImageVisual::PlayState::PLAYING ) { - mPlaying = false; - mPaused = false; + if( 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" ); + mPlayState = DevelImageVisual::PlayState::PLAYING; + mConditionalWait.Notify( lock ); + + DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::PlayAnimation: Start\n" ); } } -void VectorRasterizeThread::PauseAnimation() +void VectorRasterizeThread::StopAnimation() { ConditionalWait::ScopedLock lock( mConditionalWait ); - if( mPlaying && !mPaused ) + if( mPlayState != DevelImageVisual::PlayState::STOPPED ) { - mPaused = true; + mPlayState = DevelImageVisual::PlayState::STOPPED; - DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::PauseAnimation: Pause\n" ); + DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::StopAnimation: Stop\n" ); } } -void VectorRasterizeThread::ResumeAnimation() +void VectorRasterizeThread::PauseAnimation() { ConditionalWait::ScopedLock lock( mConditionalWait ); - if( mPlaying && mPaused ) + if( mPlayState == DevelImageVisual::PlayState::PLAYING ) { - mPaused = false; - mConditionalWait.Notify( lock ); + mPlayState = DevelImageVisual::PlayState::PAUSED; - DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::ResumeAnimation: Resume\n" ); + DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::PauseAnimation: Pause\n" ); } } @@ -171,10 +180,16 @@ void VectorRasterizeThread::RenderFrame() void VectorRasterizeThread::SetResourceReadyCallback( EventThreadCallback* callback ) { ConditionalWait::ScopedLock lock( mConditionalWait ); - mResourceReadyTrigger = callback; + mResourceReadyTrigger = std::unique_ptr< EventThreadCallback >( callback ); +} + +void VectorRasterizeThread::SetAnimationFinishedCallback( EventThreadCallback* callback ) +{ + ConditionalWait::ScopedLock lock( mConditionalWait ); + mAnimationFinishedTrigger = std::unique_ptr< EventThreadCallback >( callback ); } -void VectorRasterizeThread::SetLoopCount( int16_t count ) +void VectorRasterizeThread::SetLoopCount( int32_t count ) { ConditionalWait::ScopedLock lock( mConditionalWait ); @@ -185,33 +200,58 @@ void VectorRasterizeThread::SetLoopCount( int16_t count ) mCurrentFrame = mStartFrame; } +int32_t VectorRasterizeThread::GetLoopCount() const +{ + return mLoopCount; +} + void VectorRasterizeThread::SetPlayRange( Vector2 range ) { ConditionalWait::ScopedLock lock( mConditionalWait ); - mPlayRange = range; - - if( mTotalFrame != 0 ) + // 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 ) { - mStartFrame = static_cast< uint32_t >( mPlayRange.x * mTotalFrame + 0.5f ); - mEndFrame = static_cast< uint32_t >( mPlayRange.y * mTotalFrame + 0.5f ); + Vector2 orderedRange( range ); + // If the range is not in order swap values + if( range.x > range.y ) + { + orderedRange = Vector2( range.y, range.x ); + } + + 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 ); + } } } +Vector2 VectorRasterizeThread::GetPlayRange() const +{ + return mPlayRange; +} + +DevelImageVisual::PlayState VectorRasterizeThread::GetPlayState() const +{ + return mPlayState; +} + +bool VectorRasterizeThread::IsResourceReady() const +{ + return mResourceReady; +} + bool VectorRasterizeThread::IsThreadReady() { ConditionalWait::ScopedLock lock( mConditionalWait ); - if( ( !mPlaying || mPaused ) && !mNeedRender && !mDestroyThread ) + if( mPlayState != DevelImageVisual::PlayState::PLAYING && !mNeedRender && !mDestroyThread ) { DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::IsThreadReady: Wait\n" ); - if( !mPlaying ) - { - mCurrentFrame = mStartFrame; - mCurrentLoop = 0; - } - mConditionalWait.Wait( lock ); } @@ -243,7 +283,7 @@ void VectorRasterizeThread::Rasterize() // Rasterize mVectorRenderer.Render( mCurrentFrame ); - if( mPlaying && !mPaused ) + if( mPlayState == DevelImageVisual::PlayState::PLAYING ) { if( ++mCurrentFrame >= mEndFrame ) { @@ -258,7 +298,11 @@ void VectorRasterizeThread::Rasterize() if( mCurrentLoop >= mLoopCount ) { // Animation is finished - mPlaying = false; + mPlayState = DevelImageVisual::PlayState::STOPPED; + + mAnimationFinishedTrigger->Trigger(); + + DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Animation is finished\n" ); } else {