Merge "Enum properties added for the text effects style." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-vector-image / vector-rasterize-thread.cpp
index 52c6541..536c208 100644 (file)
@@ -50,8 +50,10 @@ VectorRasterizeThread::VectorRasterizeThread( const std::string& url, Renderer r
   mVectorRenderer(),
   mConditionalWait(),
   mMutex(),
-  mResourceReadyTrigger( NULL ),
+  mResourceReadyTrigger(),
+  mAnimationFinishedTrigger(),
   mPlayRange( 0.0f, 1.0f ),
+  mPlayState( DevelImageVisual::PlayState::STOPPED ),
   mCurrentFrame( 0 ),
   mTotalFrame( 0 ),
   mStartFrame( 0 ),
@@ -61,8 +63,6 @@ VectorRasterizeThread::VectorRasterizeThread( const std::string& url, Renderer r
   mLoopCount( LOOP_FOREVER ),
   mCurrentLoop( 0 ),
   mNeedRender( false ),
-  mPlaying( false ),
-  mPaused( false ),
   mDestroyThread( false ),
   mResourceReady( false ),
   mLogFactory( Dali::Adaptor::Get().GetLogFactory() )
@@ -85,8 +85,6 @@ VectorRasterizeThread::~VectorRasterizeThread()
   DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::~VectorRasterizeThread: Join\n" );
 
   Join();
-
-  delete mResourceReadyTrigger;
 }
 
 void VectorRasterizeThread::Run()
@@ -114,10 +112,16 @@ void VectorRasterizeThread::SetSize( uint32_t width, uint32_t height )
 void VectorRasterizeThread::StartAnimation()
 {
   ConditionalWait::ScopedLock lock( mConditionalWait );
-  if( !mPlaying )
+  if( mPlayState != DevelImageVisual::PlayState::PLAYING )
   {
-    mPlaying = true;
-    mPaused = false;
+    if( mPlayState == DevelImageVisual::PlayState::STOPPED )
+    {
+      // Reset the current frame and the current loop
+      mCurrentFrame = mStartFrame;
+      mCurrentLoop = 0;
+    }
+
+    mPlayState = DevelImageVisual::PlayState::PLAYING;
     mConditionalWait.Notify( lock );
 
     DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::StartAnimation: Start\n" );
@@ -127,10 +131,9 @@ void VectorRasterizeThread::StartAnimation()
 void VectorRasterizeThread::StopAnimation()
 {
   ConditionalWait::ScopedLock lock( mConditionalWait );
-  if( mPlaying )
+  if( mPlayState != DevelImageVisual::PlayState::STOPPED )
   {
-    mPlaying = false;
-    mPaused = false;
+    mPlayState = DevelImageVisual::PlayState::STOPPED;
 
     DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::StopAnimation: Stop\n" );
   }
@@ -139,26 +142,14 @@ 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()
-{
-  ConditionalWait::ScopedLock lock( mConditionalWait );
-  if( mPlaying && mPaused )
-  {
-    mPaused = false;
-    mConditionalWait.Notify( lock );
-
-    DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::ResumeAnimation: Resume\n" );
-  }
-}
-
 void VectorRasterizeThread::RenderFrame()
 {
   ConditionalWait::ScopedLock lock( mConditionalWait );
@@ -171,7 +162,13 @@ 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 )
@@ -198,20 +195,19 @@ void VectorRasterizeThread::SetPlayRange( Vector2 range )
   }
 }
 
+DevelImageVisual::PlayState VectorRasterizeThread::GetPlayState()
+{
+  return mPlayState;
+}
+
 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 +239,7 @@ void VectorRasterizeThread::Rasterize()
   // Rasterize
   mVectorRenderer.Render( mCurrentFrame );
 
-  if( mPlaying && !mPaused )
+  if( mPlayState == DevelImageVisual::PlayState::PLAYING )
   {
     if( ++mCurrentFrame >= mEndFrame )
     {
@@ -258,7 +254,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
         {