[Tizen] (Vector) Ensure to release VectorRenderer in the main thread 63/216463/4
authorHeeyong Song <heeyong.song@samsung.com>
Mon, 21 Oct 2019 08:41:14 +0000 (17:41 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Thu, 31 Oct 2019 06:20:05 +0000 (06:20 +0000)
Change-Id: Ie7a6798f92a55124a14b04df622b62549347ecfa

automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.cpp
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 f8c0c36..9dccaa7 100755 (executable)
@@ -108,7 +108,7 @@ public:
     height = 100;
   }
 
-  void GetLayerInfo( Property::Map& map ) const
+  void GetLayerInfo( Property::Map& map )
   {
   }
 
@@ -216,7 +216,7 @@ void VectorAnimationRenderer::GetDefaultSize( uint32_t& width, uint32_t& height
   Internal::Adaptor::GetImplementation( *this ).GetDefaultSize( width, height );
 }
 
-void VectorAnimationRenderer::GetLayerInfo( Property::Map& map ) const
+void VectorAnimationRenderer::GetLayerInfo( Property::Map& map )
 {
   Internal::Adaptor::GetImplementation( *this ).GetLayerInfo( map );
 }
index ea4dee5..122d407 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 7af08ac..8ebad55 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 );
@@ -317,7 +332,7 @@ void VectorAnimationTask::SetLoopingMode( DevelImageVisual::LoopingMode::Type lo
   DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetLoopingMode: looping mode = %d [%p]\n", mLoopingMode, this );
 }
 
-void VectorAnimationTask::GetLayerInfo( Property::Map& map ) const
+void VectorAnimationTask::GetLayerInfo( Property::Map& map )
 {
   mVectorRenderer.GetLayerInfo( map );
 }
@@ -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 4f6f83a..4defb86 100644 (file)
@@ -64,6 +64,11 @@ public:
   virtual ~VectorAnimationTask();
 
   /**
+   * @brief Finalizes the task.
+   */
+  void Finalize();
+
+  /**
    * @brief Sets the renderer used to display the result image.
    *
    * @param[in] renderer The renderer used to display the result image
@@ -172,7 +177,7 @@ public:
    * @brief Gets the layer information of all the child layers.
    * @param[out] map The layer information
    */
-  void GetLayerInfo( Property::Map& map ) const;
+  void GetLayerInfo( Property::Map& map );
 
   /**
    * @brief Connect to this signal to be notified when the texture upload is completed.
index a4a2a16..e1a4a40 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;