From 328b58705e176211893c5125dd23bf9622a9191a Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Tue, 16 Apr 2024 10:44:15 +0900 Subject: [PATCH] Reduce the number of UpdateOnce call after rasterization 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 --- .../animated-vector-image-visual.cpp | 9 ----- .../animated-vector-image-visual.h | 7 ---- .../vector-animation-task.cpp | 16 +-------- .../vector-animation-task.h | 7 ---- .../vector-animation-thread.cpp | 33 +++++++++++++++++-- .../vector-animation-thread.h | 18 +++++++--- 6 files changed, 45 insertions(+), 45 deletions(-) diff --git a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp index 6ee22d7c57..238de7955f 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp +++ b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp @@ -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) diff --git a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h index a24a76a5d9..a1e7480937 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h +++ b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h @@ -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. */ diff --git a/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.cpp b/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.cpp index d74b22d3fc..ac448c0226 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.cpp +++ b/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.cpp @@ -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(callback); } -void VectorAnimationTask::SetForceRenderOnceCallback(CallbackBase* callback) -{ - Mutex::ScopedLock lock(mMutex); - mForceRenderOnceCallback = std::unique_ptr(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; } diff --git a/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h b/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h index 92eff2310b..c741be1c7d 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h +++ b/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h @@ -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 mAnimationFinishedCallback{}; - std::unique_ptr mForceRenderOnceCallback{}; std::unique_ptr mLoadCompletedCallback{}; mutable Property::Map mCachedLayerInfo; mutable Property::Map mCachedMarkerInfo; diff --git a/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.cpp b/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.cpp index b07ba5b29a..5638ec3a0b 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.cpp +++ b/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.cpp @@ -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 VectorAnimationThread::GetNextEventCallback() diff --git a/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h b/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h index b1f608a87e..8b820cc254 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h +++ b/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h @@ -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 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 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 -- 2.34.1