(Vector) Call Finalize method instead of deleting VectorRenderer
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-vector-image / vector-animation-task.cpp
index 7af08ac..8258fb7 100644 (file)
@@ -92,6 +92,17 @@ VectorAnimationTask::~VectorAnimationTask()
   DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::~VectorAnimationTask: destructor [%p]\n", this );
 }
 
+void VectorAnimationTask::Finalize()
+{
+  // Release some objects in the main thread
+  if( mAnimationFinishedTrigger )
+  {
+    mAnimationFinishedTrigger.reset();
+  }
+
+  mVectorRenderer.Finalize();
+}
+
 void VectorAnimationTask::SetRenderer( Renderer renderer )
 {
   ConditionalWait::ScopedLock lock( mConditionalWait );
@@ -170,7 +181,10 @@ void VectorAnimationTask::RenderFrame()
 void VectorAnimationTask::SetAnimationFinishedCallback( EventThreadCallback* callback )
 {
   ConditionalWait::ScopedLock lock( mConditionalWait );
-  mAnimationFinishedTrigger = std::unique_ptr< EventThreadCallback >( callback );
+  if( callback )
+  {
+    mAnimationFinishedTrigger = std::unique_ptr< EventThreadCallback >( callback );
+  }
 }
 
 void VectorAnimationTask::SetLoopCount( int32_t count )
@@ -276,6 +290,7 @@ void VectorAnimationTask::SetCurrentFrameNumber( uint32_t frameNumber )
     mCurrentFrame = frameNumber;
     mCurrentFrameUpdated = true;
 
+    mUpdateFrameNumber = false;
     mResourceReady = false;
 
     DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetCurrentFrameNumber: frame number = %d [%p]\n", mCurrentFrame, this );
@@ -434,11 +449,15 @@ bool VectorAnimationTask::Rasterize()
   }
 
   // Rasterize
-  bool renderSuccess = mVectorRenderer.Render( currentFrame );
-  if( !renderSuccess )
+  bool renderSuccess = false;
+  if( mVectorRenderer )
   {
-    DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::Rasterize: Rendering failed. Try again later.[%d] [%p]\n", currentFrame, this );
-    mUpdateFrameNumber = false;
+    renderSuccess = mVectorRenderer.Render( currentFrame );
+    if( !renderSuccess )
+    {
+      DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::Rasterize: Rendering failed. Try again later.[%d] [%p]\n", currentFrame, this );
+      mUpdateFrameNumber = false;
+    }
   }
 
   if( stopped && renderSuccess )
@@ -500,7 +519,11 @@ uint32_t VectorAnimationTask::GetStoppedFrame( uint32_t startFrame, uint32_t end
 
 std::chrono::time_point< std::chrono::system_clock > VectorAnimationTask::CalculateNextFrameTime( bool renderNow )
 {
-  mNextFrameStartTime = mNextFrameStartTime + std::chrono::nanoseconds( mFrameDurationNanoSeconds );
+  // std::chrono::time_point template has second parameter duration which defaults to the std::chrono::system_clock supported
+  // duration. In some C++11 implementations it is a milliseconds duration, so it fails to compile unless mNextFrameStartTime
+  // is casted to use the default duration.
+  mNextFrameStartTime =  std::chrono::time_point_cast< std::chrono::time_point< std::chrono::system_clock >::duration >(
+      mNextFrameStartTime + std::chrono::nanoseconds( mFrameDurationNanoSeconds ) );
   auto current = std::chrono::system_clock::now();
   if( renderNow || mNextFrameStartTime < current )
   {