(Vector) Ensure not to add duplicated task
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-vector-image / vector-animation-task.cpp
index 6072ce5..bae4fbc 100644 (file)
@@ -70,11 +70,11 @@ VectorAnimationTask::VectorAnimationTask( VisualFactoryCache& factoryCache, cons
   mAnimationDataIndex( 0 ),
   mLoopCount( LOOP_FOREVER ),
   mCurrentLoop( 0 ),
-  mResourceReady( false ),
   mForward( true ),
   mUpdateFrameNumber( false ),
   mNeedAnimationFinishedTrigger( true ),
-  mAnimationDataUpdated( false )
+  mAnimationDataUpdated( false ),
+  mDestroyTask( false )
 {
   Initialize();
 }
@@ -95,6 +95,8 @@ void VectorAnimationTask::Finalize()
   }
 
   mVectorRenderer.Finalize();
+
+  mDestroyTask = true;
 }
 
 void VectorAnimationTask::SetRenderer( Renderer renderer )
@@ -135,8 +137,6 @@ void VectorAnimationTask::SetSize( uint32_t width, uint32_t height )
     mWidth = width;
     mHeight = height;
 
-    mResourceReady = false;
-
     DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetSize: width = %d, height = %d [%p]\n", width, height, this );
   }
 }
@@ -145,6 +145,7 @@ void VectorAnimationTask::PlayAnimation()
 {
   if( mPlayState != PlayState::PLAYING )
   {
+    mNeedAnimationFinishedTrigger = true;
     mUpdateFrameNumber = false;
     mPlayState = PlayState::PLAYING;
 
@@ -263,12 +264,10 @@ void VectorAnimationTask::SetPlayRange( const Property::Array& playRange )
       if( mStartFrame > mCurrentFrame )
       {
         mCurrentFrame = mStartFrame;
-        mResourceReady = false;
       }
       else if( mEndFrame < mCurrentFrame )
       {
         mCurrentFrame = mEndFrame;
-        mResourceReady = false;
       }
 
       DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetPlayRange: [%d, %d] [%p]\n", mStartFrame, mEndFrame, this );
@@ -299,7 +298,6 @@ void VectorAnimationTask::SetCurrentFrameNumber( uint32_t frameNumber )
   {
     mCurrentFrame = frameNumber;
     mUpdateFrameNumber = false;
-    mResourceReady = false;
 
     DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetCurrentFrameNumber: frame number = %d [%p]\n", mCurrentFrame, this );
   }
@@ -372,6 +370,15 @@ bool VectorAnimationTask::Rasterize()
   bool stopped = false;
   uint32_t currentFrame;
 
+  {
+    ConditionalWait::ScopedLock lock( mConditionalWait );
+    if( mDestroyTask )
+    {
+      // The task will be destroyed. We don't need rasterization.
+      return false;
+    }
+  }
+
   ApplyAnimationData();
 
   if( mPlayState == PlayState::PLAYING && mUpdateFrameNumber )
@@ -382,10 +389,7 @@ bool VectorAnimationTask::Rasterize()
 
   currentFrame = mCurrentFrame;
 
-  // Reset values
-  mResourceReady = true;
   mUpdateFrameNumber = true;
-  mNeedAnimationFinishedTrigger = true;
 
   if( mPlayState == PlayState::STOPPING )
   {
@@ -450,11 +454,6 @@ bool VectorAnimationTask::Rasterize()
     {
       DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::Rasterize: Rendering failed. Try again later.[%d] [%p]\n", currentFrame, this );
       mUpdateFrameNumber = false;
-
-      if( !mResourceReady )
-      {
-        mResourceReady = false;
-      }
     }
   }