(Vector) Do not use renderingDataImpl if Finalized 88/311088/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 14 May 2024 03:03:05 +0000 (12:03 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 14 May 2024 03:07:06 +0000 (12:07 +0900)
Finalize can be called during Render sequence is running.

Let we block the rendering if finalize requested.

Change-Id: I3856b373ca6c918fd0ddc7f58f00ed516a6a65b0
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali-extension/vector-animation-renderer/vector-animation-renderer-tizen.cpp
dali-extension/vector-animation-renderer/vector-animation-renderer-x.cpp
dali-extension/vector-animation-renderer/vector-animation-renderer.cpp
dali-extension/vector-animation-renderer/vector-animation-renderer.h

index 2e003dc..bf5b016 100644 (file)
@@ -77,14 +77,17 @@ bool VectorAnimationRendererTizen::Render(uint32_t frameNumber)
   std::shared_ptr<RenderingDataImpl> renderingDataImpl;
   {
     Dali::Mutex::ScopedLock lock(mRenderingDataMutex);
-    if(mPreparedRenderingData)
+    if(DALI_LIKELY(!mFinalized))
     {
-      mPreviousRenderingData.push_back(mCurrentRenderingData);
-      mCurrentRenderingData = mPreparedRenderingData;
-      mPreparedRenderingData.reset();
-      mResourceReady = false;
+      if(mPreparedRenderingData)
+      {
+        mPreviousRenderingData.push_back(mCurrentRenderingData);
+        mCurrentRenderingData = mPreparedRenderingData;
+        mPreparedRenderingData.reset();
+        mResourceReady = false;
+      }
+      renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(mCurrentRenderingData);
     }
-    renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(mCurrentRenderingData);
   }
 
   if(!renderingDataImpl)
@@ -233,7 +236,10 @@ void VectorAnimationRendererTizen::RenderStopped()
   std::shared_ptr<RenderingDataImpl> renderingDataImpl;
   {
     Dali::Mutex::ScopedLock lock(mRenderingDataMutex);
-    renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(mCurrentRenderingData);
+    if(DALI_LIKELY(!mFinalized))
+    {
+      renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(mCurrentRenderingData);
+    }
   }
 
   if(renderingDataImpl && renderingDataImpl->mTargetSurface)
@@ -258,7 +264,7 @@ void VectorAnimationRendererTizen::ResetBuffers()
   mBuffers.clear();
 }
 
-// This Method is called inside mRenderingDataMutex
+// This Method is called inside mMutex
 void VectorAnimationRendererTizen::OnFinalize()
 {
   mRenderedTexture.Reset();
@@ -292,7 +298,10 @@ bool VectorAnimationRendererTizen::IsTargetPrepared()
   std::shared_ptr<RenderingDataImpl> renderingDataImpl;
   {
     Dali::Mutex::ScopedLock lock(mRenderingDataMutex);
-    renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(mPreparedRenderingData ? mPreparedRenderingData : mCurrentRenderingData);
+    if(DALI_LIKELY(!mFinalized))
+    {
+      renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(mPreparedRenderingData ? mPreparedRenderingData : mCurrentRenderingData);
+    }
   }
   return (renderingDataImpl) ? !!renderingDataImpl->mTargetSurface : false;
 }
index 7e3c49d..ead555c 100644 (file)
@@ -71,14 +71,17 @@ bool VectorAnimationRendererX::Render(uint32_t frameNumber)
   std::shared_ptr<RenderingDataImpl> renderingDataImpl;
   {
     Dali::Mutex::ScopedLock lock(mRenderingDataMutex);
-    if(mPreparedRenderingData)
+    if(DALI_LIKELY(!mFinalized))
     {
-      mPreviousRenderingData.push_back(mCurrentRenderingData);
-      mCurrentRenderingData = mPreparedRenderingData;
-      mPreparedRenderingData.reset();
-      mResourceReady = false;
+      if(mPreparedRenderingData)
+      {
+        mPreviousRenderingData.push_back(mCurrentRenderingData);
+        mCurrentRenderingData = mPreparedRenderingData;
+        mPreparedRenderingData.reset();
+        mResourceReady = false;
+      }
+      renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(mCurrentRenderingData);
     }
-    renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(mCurrentRenderingData);
   }
 
   if(!renderingDataImpl)
@@ -116,7 +119,7 @@ void VectorAnimationRendererX::ResetBuffers()
 {
 }
 
-// This Method is called inside mRenderingDataMutex
+// This Method is called inside mMutex
 void VectorAnimationRendererX::OnFinalize()
 {
 }
@@ -133,7 +136,10 @@ void VectorAnimationRendererX::OnNotify()
   std::shared_ptr<RenderingDataImpl> renderingDataImpl;
   {
     Dali::Mutex::ScopedLock lock(mRenderingDataMutex);
-    renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(mCurrentRenderingData);
+    if(DALI_LIKELY(!mFinalized))
+    {
+      renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(mCurrentRenderingData);
+    }
   }
 
   if(renderingDataImpl && renderingDataImpl->mPixelBuffer && renderingDataImpl->mTexture)
@@ -159,7 +165,10 @@ bool VectorAnimationRendererX::IsTargetPrepared()
   std::shared_ptr<RenderingDataImpl> renderingDataImpl;
   {
     Dali::Mutex::ScopedLock lock(mRenderingDataMutex);
-    renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(mPreparedRenderingData ? mPreparedRenderingData : mCurrentRenderingData);
+    if(DALI_LIKELY(!mFinalized))
+    {
+      renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(mPreparedRenderingData ? mPreparedRenderingData : mCurrentRenderingData);
+    }
   }
   return (renderingDataImpl) ? !!renderingDataImpl->mPixelBuffer : false;
 }
@@ -170,7 +179,10 @@ bool VectorAnimationRendererX::IsRenderReady()
   std::shared_ptr<RenderingDataImpl> renderingDataImpl;
   {
     Dali::Mutex::ScopedLock lock(mRenderingDataMutex);
-    renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(mCurrentRenderingData);
+    if(DALI_LIKELY(!mFinalized))
+    {
+      renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(mCurrentRenderingData);
+    }
   }
   return mResourceReady && ((renderingDataImpl) ? !!renderingDataImpl->mTexture : false);
 }
@@ -181,7 +193,10 @@ Dali::Texture VectorAnimationRendererX::GetTargetTexture()
   std::shared_ptr<RenderingDataImpl> renderingDataImpl;
   {
     Dali::Mutex::ScopedLock lock(mRenderingDataMutex);
-    renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(mCurrentRenderingData);
+    if(DALI_LIKELY(!mFinalized))
+    {
+      renderingDataImpl = std::static_pointer_cast<RenderingDataImpl>(mCurrentRenderingData);
+    }
   }
   return (renderingDataImpl) ? renderingDataImpl->mTexture : Texture();
 }
index 60729ef..cd3f6eb 100644 (file)
@@ -58,7 +58,8 @@ VectorAnimationRenderer::VectorAnimationRenderer()
   mLoadFailed(false),
   mResourceReady(false),
   mResourceReadyTriggered(false),
-  mEnableFixedCache(false)
+  mEnableFixedCache(false),
+  mFinalized(false)
 {
   VectorAnimationPluginManager::Get().AddEventHandler(*this);
 }
@@ -84,9 +85,16 @@ void VectorAnimationRenderer::Finalize()
 
   mRenderer.Reset();
 
-  mPreparedRenderingData.reset();
-  mCurrentRenderingData.reset();
-  ClearPreviousRenderingData();
+  {
+    Dali::Mutex::ScopedLock lock(mRenderingDataMutex);
+
+    mPreparedRenderingData.reset();
+    mCurrentRenderingData.reset();
+    ClearPreviousRenderingData();
+
+    // Change this flag under both mMutex and mRenderingDataMutex
+    mFinalized = true;
+  }
 
   OnFinalize();
 
@@ -194,6 +202,11 @@ void VectorAnimationRenderer::SetSize(uint32_t width, uint32_t height)
 
   {
     Dali::Mutex::ScopedLock lock(mRenderingDataMutex);
+    if(DALI_UNLIKELY(mFinalized))
+    {
+      DALI_LOG_DEBUG_INFO("SetSize should be called after finialized.\n");
+      return;
+    }
 
     if(!mPreparedRenderingData && mCurrentRenderingData && (mCurrentRenderingData->mWidth == width && mCurrentRenderingData->mHeight == height))
     {
@@ -219,7 +232,10 @@ void VectorAnimationRenderer::SetSize(uint32_t width, uint32_t height)
 
   {
     Dali::Mutex::ScopedLock lock(mRenderingDataMutex);
-    mPreparedRenderingData = preparedRenderingData;
+    if(DALI_LIKELY(!mFinalized))
+    {
+      mPreparedRenderingData = preparedRenderingData;
+    }
   }
 
   DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "width = %d, height = %d [%p]\n", preparedRenderingData->mWidth, preparedRenderingData->mHeight, this);
@@ -306,43 +322,17 @@ void VectorAnimationRenderer::AddPropertyValueCallback(const std::string& keyPat
 {
   Dali::Mutex::ScopedLock lock(mMutex);
 
-  mPropertyCallbacks.push_back(std::unique_ptr<CallbackBase>(callback));
-
-  if(mVectorRenderer)
+  if(DALI_UNLIKELY(!mFinalized))
   {
-    switch(property)
+    mPropertyCallbacks.push_back(std::unique_ptr<CallbackBase>(callback));
+
+    if(mVectorRenderer)
     {
-      case VectorProperty::FILL_COLOR:
-      {
-        mVectorRenderer->setValue<rlottie::Property::FillColor>(keyPath,
-                                                                [property, callback, id](const rlottie::FrameInfo& info) {
-                                                                  Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
-                                                                  Vector3         color;
-                                                                  if(value.Get(color))
-                                                                  {
-                                                                    return rlottie::Color(color.r, color.g, color.b);
-                                                                  }
-                                                                  return rlottie::Color(1.0f, 1.0f, 1.0f);
-                                                                });
-        break;
-      }
-      case VectorProperty::FILL_OPACITY:
+      switch(property)
       {
-        mVectorRenderer->setValue<rlottie::Property::FillOpacity>(keyPath,
-                                                                  [property, callback, id](const rlottie::FrameInfo& info) {
-                                                                    Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
-                                                                    float           opacity;
-                                                                    if(value.Get(opacity))
-                                                                    {
-                                                                      return opacity * 100;
-                                                                    }
-                                                                    return 100.0f;
-                                                                  });
-        break;
-      }
-      case VectorProperty::STROKE_COLOR:
-      {
-        mVectorRenderer->setValue<rlottie::Property::StrokeColor>(keyPath,
+        case VectorProperty::FILL_COLOR:
+        {
+          mVectorRenderer->setValue<rlottie::Property::FillColor>(keyPath,
                                                                   [property, callback, id](const rlottie::FrameInfo& info) {
                                                                     Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
                                                                     Vector3         color;
@@ -352,11 +342,11 @@ void VectorAnimationRenderer::AddPropertyValueCallback(const std::string& keyPat
                                                                     }
                                                                     return rlottie::Color(1.0f, 1.0f, 1.0f);
                                                                   });
-        break;
-      }
-      case VectorProperty::STROKE_OPACITY:
-      {
-        mVectorRenderer->setValue<rlottie::Property::StrokeOpacity>(keyPath,
+          break;
+        }
+        case VectorProperty::FILL_OPACITY:
+        {
+          mVectorRenderer->setValue<rlottie::Property::FillOpacity>(keyPath,
                                                                     [property, callback, id](const rlottie::FrameInfo& info) {
                                                                       Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
                                                                       float           opacity;
@@ -366,91 +356,120 @@ void VectorAnimationRenderer::AddPropertyValueCallback(const std::string& keyPat
                                                                       }
                                                                       return 100.0f;
                                                                     });
-        break;
-      }
-      case VectorProperty::STROKE_WIDTH:
-      {
-        mVectorRenderer->setValue<rlottie::Property::StrokeWidth>(keyPath,
-                                                                  [property, callback, id](const rlottie::FrameInfo& info) {
-                                                                    Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
-                                                                    float           width;
-                                                                    if(value.Get(width))
-                                                                    {
-                                                                      return width;
-                                                                    }
-                                                                    return 1.0f;
-                                                                  });
-        break;
-      }
-      case VectorProperty::TRANSFORM_ANCHOR:
-      {
-        mVectorRenderer->setValue<rlottie::Property::TrAnchor>(keyPath,
-                                                               [property, callback, id](const rlottie::FrameInfo& info) {
-                                                                 Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
-                                                                 Vector2         point;
-                                                                 if(value.Get(point))
-                                                                 {
-                                                                   return rlottie::Point(point.x, point.y);
-                                                                 }
-                                                                 return rlottie::Point(0.0f, 0.0f);
-                                                               });
-        break;
-      }
-      case VectorProperty::TRANSFORM_POSITION:
-      {
-        mVectorRenderer->setValue<rlottie::Property::TrPosition>(keyPath,
+          break;
+        }
+        case VectorProperty::STROKE_COLOR:
+        {
+          mVectorRenderer->setValue<rlottie::Property::StrokeColor>(keyPath,
+                                                                    [property, callback, id](const rlottie::FrameInfo& info) {
+                                                                      Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
+                                                                      Vector3         color;
+                                                                      if(value.Get(color))
+                                                                      {
+                                                                        return rlottie::Color(color.r, color.g, color.b);
+                                                                      }
+                                                                      return rlottie::Color(1.0f, 1.0f, 1.0f);
+                                                                    });
+          break;
+        }
+        case VectorProperty::STROKE_OPACITY:
+        {
+          mVectorRenderer->setValue<rlottie::Property::StrokeOpacity>(keyPath,
+                                                                      [property, callback, id](const rlottie::FrameInfo& info) {
+                                                                        Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
+                                                                        float           opacity;
+                                                                        if(value.Get(opacity))
+                                                                        {
+                                                                          return opacity * 100;
+                                                                        }
+                                                                        return 100.0f;
+                                                                      });
+          break;
+        }
+        case VectorProperty::STROKE_WIDTH:
+        {
+          mVectorRenderer->setValue<rlottie::Property::StrokeWidth>(keyPath,
+                                                                    [property, callback, id](const rlottie::FrameInfo& info) {
+                                                                      Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
+                                                                      float           width;
+                                                                      if(value.Get(width))
+                                                                      {
+                                                                        return width;
+                                                                      }
+                                                                      return 1.0f;
+                                                                    });
+          break;
+        }
+        case VectorProperty::TRANSFORM_ANCHOR:
+        {
+          mVectorRenderer->setValue<rlottie::Property::TrAnchor>(keyPath,
                                                                  [property, callback, id](const rlottie::FrameInfo& info) {
                                                                    Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
-                                                                   Vector2         position;
-                                                                   if(value.Get(position))
+                                                                   Vector2         point;
+                                                                   if(value.Get(point))
                                                                    {
-                                                                     return rlottie::Point(position.x, position.y);
+                                                                     return rlottie::Point(point.x, point.y);
                                                                    }
                                                                    return rlottie::Point(0.0f, 0.0f);
                                                                  });
-        break;
-      }
-      case VectorProperty::TRANSFORM_SCALE:
-      {
-        mVectorRenderer->setValue<rlottie::Property::TrScale>(keyPath,
-                                                              [property, callback, id](const rlottie::FrameInfo& info) {
-                                                                Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
-                                                                Vector2         scale;
-                                                                if(value.Get(scale))
-                                                                {
-                                                                  return rlottie::Size(scale.x, scale.y);
-                                                                }
-                                                                return rlottie::Size(100.0f, 100.0f);
-                                                              });
-        break;
-      }
-      case VectorProperty::TRANSFORM_ROTATION:
-      {
-        mVectorRenderer->setValue<rlottie::Property::TrRotation>(keyPath,
-                                                                 [property, callback, id](const rlottie::FrameInfo& info) {
-                                                                   Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
-                                                                   float           rotation;
-                                                                   if(value.Get(rotation))
-                                                                   {
-                                                                     return rotation;
-                                                                   }
-                                                                   return 0.0f;
-                                                                 });
-        break;
-      }
-      case VectorProperty::TRANSFORM_OPACITY:
-      {
-        mVectorRenderer->setValue<rlottie::Property::TrOpacity>(keyPath,
+          break;
+        }
+        case VectorProperty::TRANSFORM_POSITION:
+        {
+          mVectorRenderer->setValue<rlottie::Property::TrPosition>(keyPath,
+                                                                   [property, callback, id](const rlottie::FrameInfo& info) {
+                                                                     Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
+                                                                     Vector2         position;
+                                                                     if(value.Get(position))
+                                                                     {
+                                                                       return rlottie::Point(position.x, position.y);
+                                                                     }
+                                                                     return rlottie::Point(0.0f, 0.0f);
+                                                                   });
+          break;
+        }
+        case VectorProperty::TRANSFORM_SCALE:
+        {
+          mVectorRenderer->setValue<rlottie::Property::TrScale>(keyPath,
                                                                 [property, callback, id](const rlottie::FrameInfo& info) {
                                                                   Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
-                                                                  float           opacity;
-                                                                  if(value.Get(opacity))
+                                                                  Vector2         scale;
+                                                                  if(value.Get(scale))
                                                                   {
-                                                                    return opacity * 100;
+                                                                    return rlottie::Size(scale.x, scale.y);
                                                                   }
-                                                                  return 100.0f;
+                                                                  return rlottie::Size(100.0f, 100.0f);
                                                                 });
-        break;
+          break;
+        }
+        case VectorProperty::TRANSFORM_ROTATION:
+        {
+          mVectorRenderer->setValue<rlottie::Property::TrRotation>(keyPath,
+                                                                   [property, callback, id](const rlottie::FrameInfo& info) {
+                                                                     Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
+                                                                     float           rotation;
+                                                                     if(value.Get(rotation))
+                                                                     {
+                                                                       return rotation;
+                                                                     }
+                                                                     return 0.0f;
+                                                                   });
+          break;
+        }
+        case VectorProperty::TRANSFORM_OPACITY:
+        {
+          mVectorRenderer->setValue<rlottie::Property::TrOpacity>(keyPath,
+                                                                  [property, callback, id](const rlottie::FrameInfo& info) {
+                                                                    Property::Value value = CallbackBase::ExecuteReturn<Property::Value>(*callback, id, property, info.curFrame());
+                                                                    float           opacity;
+                                                                    if(value.Get(opacity))
+                                                                    {
+                                                                      return opacity * 100;
+                                                                    }
+                                                                    return 100.0f;
+                                                                  });
+          break;
+        }
       }
     }
   }
index 6d2985a..ec9342f 100644 (file)
@@ -195,19 +195,21 @@ protected:
   std::shared_ptr<RenderingData>              mCurrentRenderingData;
   std::vector<std::shared_ptr<RenderingData>> mPreviousRenderingData;
 
-  mutable Dali::Mutex                 mMutex;                  ///< Mutex
-  mutable Dali::Mutex                 mRenderingDataMutex;     ///< Mutex
-  Dali::Renderer                      mRenderer;               ///< Renderer
-  std::unique_ptr<rlottie::Animation> mVectorRenderer;         ///< The vector animation renderer
-  UploadCompletedSignalType           mUploadCompletedSignal;  ///< Upload completed signal
-  uint32_t                            mTotalFrameNumber;       ///< The total frame number
-  uint32_t                            mDefaultWidth;           ///< The width of the surface
-  uint32_t                            mDefaultHeight;          ///< The height of the surface
-  float                               mFrameRate;              ///< The frame rate of the content
-  bool                                mLoadFailed;             ///< Whether the file is loaded
-  bool                                mResourceReady;          ///< Whether the resource is ready
-  bool                                mResourceReadyTriggered; ///< Whether the resource ready is triggered
-  bool                                mEnableFixedCache;
+  mutable Dali::Mutex mMutex;              ///< Mutex. We can lock mRenderingDataMutex under this scope.
+  mutable Dali::Mutex mRenderingDataMutex; ///< Mutex. We cannot lock any mutex under this scope.
+
+  Dali::Renderer                      mRenderer;                   ///< Renderer
+  std::unique_ptr<rlottie::Animation> mVectorRenderer;             ///< The vector animation renderer
+  UploadCompletedSignalType           mUploadCompletedSignal;      ///< Upload completed signal
+  uint32_t                            mTotalFrameNumber;           ///< The total frame number
+  uint32_t                            mDefaultWidth;               ///< The width of the surface
+  uint32_t                            mDefaultHeight;              ///< The height of the surface
+  float                               mFrameRate;                  ///< The frame rate of the content
+  bool                                mLoadFailed : 1;             ///< Whether the file is loaded
+  bool                                mResourceReady : 1;          ///< Whether the resource is ready
+  bool                                mResourceReadyTriggered : 1; ///< Whether the resource ready is triggered
+  bool                                mEnableFixedCache : 1;
+  bool                                mFinalized : 1;
 };
 
 } // namespace Plugin