(Vector) Ensure to release VectorRenderer in the main thread 33/216133/4
authorHeeyong Song <heeyong.song@samsung.com>
Mon, 21 Oct 2019 08:41:14 +0000 (17:41 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Tue, 5 Nov 2019 05:58:34 +0000 (14:58 +0900)
Change-Id: Ie7a6798f92a55124a14b04df622b62549347ecfa

dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.cpp
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.cpp

index ea4dee54f5db456aa543f934b1ab04bfcfe472ae..122d407920a7ca59279998dd2f41f40e49a16375 100644 (file)
@@ -119,6 +119,8 @@ AnimatedVectorImageVisual::AnimatedVectorImageVisual( VisualFactoryCache& factor
 
 AnimatedVectorImageVisual::~AnimatedVectorImageVisual()
 {
+  // Finalize animation task in the main thread
+  mVectorAnimationTask->Finalize();
 }
 
 void AnimatedVectorImageVisual::GetNaturalSize( Vector2& naturalSize )
@@ -462,11 +464,11 @@ void AnimatedVectorImageVisual::OnUploadCompleted()
   {
     actor.AddRenderer( mImpl->mRenderer );
     mRendererAdded = true;
-  }
 
-  ResourceReady( Toolkit::Visual::ResourceStatus::READY );
+    ResourceReady( Toolkit::Visual::ResourceStatus::READY );
 
-  DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnUploadCompleted: Renderer is added [%p]\n", this );
+    DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "AnimatedVectorImageVisual::OnUploadCompleted: Renderer is added [%p]\n", this );
+  }
 }
 
 void AnimatedVectorImageVisual::OnAnimationFinished()
index db42b6772a8357ce79093e974e4242df17979766..ac898677b1100e14f550f0d2cfedd278e7fe4e13 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.Reset();
+}
+
 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 )
index 4f6f83ad527f41d756e76b43c0af5ff3e8f835b4..a16faeade2cd4e3b9bf7e906b32aa24592a4abcc 100644 (file)
@@ -63,6 +63,11 @@ public:
    */
   virtual ~VectorAnimationTask();
 
+  /**
+   * @brief Finalizes the task.
+   */
+  void Finalize();
+
   /**
    * @brief Sets the renderer used to display the result image.
    *
index df39c1e6b6259d8ddb157460c60b49b627d5613f..8403e6a818c679ecdddf9ea27589a38e4a2aad0f 100644 (file)
@@ -119,7 +119,7 @@ void VectorAnimationThread::OnTaskCompleted( VectorAnimationTaskPtr task, bool k
   {
     ConditionalWait::ScopedLock lock( mConditionalWait );
 
-    if( mAnimationTasks.end() == std::find( mAnimationTasks.begin(), mAnimationTasks.end(), task ) )
+    if( mCompletedTasks.end() == std::find( mCompletedTasks.begin(), mCompletedTasks.end(), task ) )
     {
       mCompletedTasks.push_back( task );
 
@@ -192,7 +192,7 @@ void VectorAnimationThread::Rasterize()
   mCompletedTasks.clear();
 
   // pop out the next task from the queue
-  if( !mAnimationTasks.empty() && !mNeedToSleep )
+  while( !mAnimationTasks.empty() && !mNeedToSleep )
   {
     std::vector< VectorAnimationTaskPtr >::iterator next = mAnimationTasks.begin();
     VectorAnimationTaskPtr nextTask = *next;