Reduce the number of UpdateOnce call after rasterization 05/309705/1
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 16 Apr 2024 01:44:15 +0000 (10:44 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 16 Apr 2024 01:47:10 +0000 (10:47 +0900)
Previous code request UpdateOnce by each visuals.
But this don't need to spend the number of requests.
So let we just use only one single request API for it.

Change-Id: I5b11ee7ad19dc7c32945c0cfc637f7c65cfe3a77
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp
dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h
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
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h

index 6ee22d7c5722f77c617e5fc8ad87a75afd7c5cb3..238de7955f59705c37298dd11f4312378b6afacf 100644 (file)
@@ -434,7 +434,6 @@ void AnimatedVectorImageVisual::OnInitialize(void)
 {
   mVectorAnimationTask->ResourceReadySignal().Connect(this, &AnimatedVectorImageVisual::OnResourceReady);
   mVectorAnimationTask->SetAnimationFinishedCallback(MakeCallback(this, &AnimatedVectorImageVisual::OnAnimationFinished));
-  mVectorAnimationTask->SetForceRenderOnceCallback(MakeCallback(this, &AnimatedVectorImageVisual::OnForceRendering));
 
   EncodedImageBuffer encodedImageBuffer;
 
@@ -748,14 +747,6 @@ void AnimatedVectorImageVisual::OnAnimationFinished(uint32_t playStateId)
   }
 }
 
-void AnimatedVectorImageVisual::OnForceRendering(uint32_t playStateId)
-{
-  if(!mCoreShutdown && Dali::Adaptor::IsAvailable())
-  {
-    Dali::Adaptor::Get().UpdateOnce();
-  }
-}
-
 void AnimatedVectorImageVisual::SendAnimationData()
 {
   if(mAnimationData.resendFlag)
index a24a76a5d9514833ebf5e81df68f1520ae4b2796..a1e74809373d22290647977aaadee50152617aa7 100644 (file)
@@ -187,13 +187,6 @@ private:
    */
   void OnAnimationFinished(uint32_t playStateId);
 
-  /**
-   * @brief Event callback from rasterize thread. This is called when we want to ensure rendering next frame.
-   *
-   * @param[in] argument Not using arguments
-   */
-  void OnForceRendering(uint32_t argument);
-
   /**
    * @brief Send animation data to the rasterize thread.
    */
index d74b22d3fcd4c49a364c3483033c9893e24f0d34..ac448c022638886aba975689b0f162254d5d649a 100644 (file)
@@ -140,11 +140,6 @@ void VectorAnimationTask::Finalize()
       mVectorAnimationThread.RemoveEventTriggerCallbacks(mAnimationFinishedCallback.get());
       mAnimationFinishedCallback.reset();
     }
-    if(mForceRenderOnceCallback)
-    {
-      mVectorAnimationThread.RemoveEventTriggerCallbacks(mForceRenderOnceCallback.get());
-      mForceRenderOnceCallback.reset();
-    }
     if(mLoadCompletedCallback)
     {
       mVectorAnimationThread.RemoveEventTriggerCallbacks(mLoadCompletedCallback.get());
@@ -396,12 +391,6 @@ void VectorAnimationTask::SetAnimationFinishedCallback(CallbackBase* callback)
   mAnimationFinishedCallback = std::unique_ptr<CallbackBase>(callback);
 }
 
-void VectorAnimationTask::SetForceRenderOnceCallback(CallbackBase* callback)
-{
-  Mutex::ScopedLock lock(mMutex);
-  mForceRenderOnceCallback = std::unique_ptr<CallbackBase>(callback);
-}
-
 void VectorAnimationTask::SetLoopCount(int32_t count)
 {
   if(mLoopCount != count)
@@ -751,10 +740,7 @@ bool VectorAnimationTask::Rasterize()
   if(mNotifyAfterRasterization || mNeedForceRenderOnceTrigger)
   {
     Mutex::ScopedLock lock(mMutex);
-    if(mForceRenderOnceCallback)
-    {
-      mVectorAnimationThread.AddEventTriggerCallback(mForceRenderOnceCallback.get(), mAppliedPlayStateId);
-    }
+    mVectorAnimationThread.RequestForceRenderOnce();
     mNeedForceRenderOnceTrigger = false;
   }
 
index 92eff2310bc8b0eb8f221b9323c6bb3702578b73..c741be1c7d83b58de9767052ea4b7b6f05de94f1 100644 (file)
@@ -182,12 +182,6 @@ public:
    */
   void SetAnimationFinishedCallback(CallbackBase* callback);
 
-  /**
-   * @brief This callback is called when we want to force render next frame.
-   * @param[in] callback The force render once callback
-   */
-  void SetForceRenderOnceCallback(CallbackBase* callback);
-
   /**
    * @brief Gets the playing range in frame number.
    * @param[out] startFrame The frame number to specify minimum progress.
@@ -403,7 +397,6 @@ private:
   Mutex                                mMutex;
   ResourceReadySignalType              mResourceReadySignal;
   std::unique_ptr<CallbackBase>        mAnimationFinishedCallback{};
-  std::unique_ptr<CallbackBase>        mForceRenderOnceCallback{};
   std::unique_ptr<CallbackBase>        mLoadCompletedCallback{};
   mutable Property::Map                mCachedLayerInfo;
   mutable Property::Map                mCachedMarkerInfo;
index b07ba5b29a6e6db95c80ecef674fa4aa3221e584..5638ec3a0bb060c62c82cc0ac972a67845fff626 100644 (file)
@@ -46,10 +46,12 @@ VectorAnimationThread::VectorAnimationThread()
   mSleepThread(MakeCallback(this, &VectorAnimationThread::OnAwakeFromSleep)),
   mConditionalWait(),
   mEventTriggerMutex(),
+  mLogFactory(Dali::Adaptor::Get().GetLogFactory()),
+  mTraceFactory(Dali::Adaptor::Get().GetTraceFactory()),
   mNeedToSleep(false),
   mDestroyThread(false),
-  mLogFactory(Dali::Adaptor::Get().GetLogFactory()),
-  mTraceFactory(Dali::Adaptor::Get().GetTraceFactory())
+  mEventTriggered(false),
+  mForceRenderOnce(false)
 {
   mAsyncTaskManager = Dali::AsyncTaskManager::Get();
   mSleepThread.Start();
@@ -184,6 +186,21 @@ void VectorAnimationThread::RemoveEventTriggerCallbacks(CallbackBase* callback)
   }
 }
 
+void VectorAnimationThread::RequestForceRenderOnce()
+{
+  Mutex::ScopedLock lock(mEventTriggerMutex);
+  if(!mDestroyThread)
+  {
+    mForceRenderOnce = true;
+
+    if(!mEventTriggered)
+    {
+      mEventTrigger->Trigger();
+      mEventTriggered = true;
+    }
+  }
+}
+
 void VectorAnimationThread::Run()
 {
   SetThreadName("VectorAnimationThread");
@@ -285,6 +302,18 @@ void VectorAnimationThread::OnEventCallbackTriggered()
     }
     CallbackBase::Execute(*callbackPair.first, callbackPair.second);
   }
+  // Request update once if we need.
+  {
+    Mutex::ScopedLock lock(mEventTriggerMutex);
+    if(!mDestroyThread && mForceRenderOnce)
+    {
+      mForceRenderOnce = false;
+      if(Dali::Adaptor::IsAvailable())
+      {
+        Dali::Adaptor::Get().UpdateOnce();
+      }
+    }
+  }
 }
 
 std::pair<CallbackBase*, uint32_t> VectorAnimationThread::GetNextEventCallback()
index b1f608a87ef5cf548f9966f2d2a8736d5eafd3b6..8b820cc2548150cce0b53d85de6974ccb35950f0 100644 (file)
@@ -90,6 +90,11 @@ public:
    */
   void RemoveEventTriggerCallbacks(CallbackBase* callback);
 
+  /**
+   * @brief Request to event callback from rasterize thread. This is called when we want to ensure rendering next frame.
+   */
+  void RequestForceRenderOnce();
+
 protected:
   /**
    * @brief The entry function of the animation thread.
@@ -149,8 +154,9 @@ private:
     std::chrono::time_point<std::chrono::steady_clock> mSleepTimePoint;
     const Dali::LogFactoryInterface&                   mLogFactory;
     const Dali::TraceFactoryInterface&                 mTraceFactory;
-    bool                                               mNeedToSleep;
-    bool                                               mDestroyThread;
+
+    bool mNeedToSleep : 1;
+    bool mDestroyThread : 1;
   };
 
 private:
@@ -169,12 +175,14 @@ private:
   ConditionalWait                                 mConditionalWait;
   Mutex                                           mEventTriggerMutex;
   std::unique_ptr<EventThreadCallback>            mEventTrigger{};
-  bool                                            mNeedToSleep;
-  bool                                            mDestroyThread;
-  bool                                            mEventTriggered{false};
   const Dali::LogFactoryInterface&                mLogFactory;
   const Dali::TraceFactoryInterface&              mTraceFactory;
   Dali::AsyncTaskManager                          mAsyncTaskManager;
+
+  bool mNeedToSleep : 1;
+  bool mDestroyThread : 1;
+  bool mEventTriggered : 1;
+  bool mForceRenderOnce : 1;
 };
 
 } // namespace Internal