From 9555fd0add30a9ba1fd0bf1bf8f18f4b07f93e38 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Wed, 8 Nov 2023 20:22:15 +0900 Subject: [PATCH] (AnimatedVector) Cache lottie file's layer / marker info GetLayerInfo and GetMarkerInfo can be called usually if we use NUI system. (Since we call Visual::Base::CreatePropertyMap() every times we change some properties.) But the LayerInfo / MarkerInfo never be changed if the file is fixed. So let we cache that information, and use cached value. It can also reduce mutex block at plugin system internally. Change-Id: I767bd581dc5e2a41715263d03c1ace15d2476df3 Signed-off-by: Eunki, Hong --- .../utc-Dali-AnimatedVectorImageVisual.cpp | 45 ++++++++++++++++++++++ .../vector-animation-task.cpp | 36 +++++++++++++++-- .../animated-vector-image/vector-animation-task.h | 22 ++++++----- 3 files changed, 91 insertions(+), 12 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp index 907b8af..2aa3d4e 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp @@ -1049,6 +1049,51 @@ int UtcDaliAnimatedVectorImageVisualMarkerInfo(void) END_TEST; } +int UtcDaliAnimatedVectorImageVisualMarkerInfoFromInvalid(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliAnimatedVectorImageVisualMarkerInfoFromInvalid"); + + Property::Map propertyMap; + propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE) + .Add(ImageVisual::Property::URL, "invalid.json") + .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false); + + Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap); + DALI_TEST_CHECK(visual); + + DummyControl actor = DummyControl::New(true); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual); + + Vector2 controlSize(20.f, 30.f); + actor.SetProperty(Actor::Property::SIZE, controlSize); + + application.GetScene().Add(actor); + + Property::Map attributes; + DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes); + + application.SendNotification(); + application.Render(); + + // Trigger count is 1 - load, and failed. + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + // renderer is added to actor + DALI_TEST_CHECK(actor.GetRendererCount() == 1u); + Renderer renderer = actor.GetRendererAt(0u); + DALI_TEST_CHECK(renderer); + + Property::Map map = actor.GetProperty(DummyControl::Property::TEST_VISUAL); + Property::Value* value = map.Find(DevelImageVisual::Property::MARKER_INFO); + + // The values when load failed case is invalid. + DALI_TEST_CHECK(value == nullptr || (value->GetMap() == nullptr) || (value->GetMap()->Empty())); + + END_TEST; +} + int UtcDaliAnimatedVectorImageVisualAnimationFinishedSignal(void) { ToolkitTestApplication application; 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 c0d3802..4bb2471 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 @@ -63,6 +63,8 @@ VectorAnimationTask::VectorAnimationTask(VisualFactoryCache& factoryCache) mConditionalWait(), mResourceReadySignal(), mLoadCompletedCallback(MakeCallback(this, &VectorAnimationTask::OnLoadCompleted)), + mCachedLayerInfo(), + mCachedMarkerInfo(), mPlayState(PlayState::STOPPED), mStopBehavior(DevelImageVisual::StopBehavior::CURRENT_FRAME), mLoopingMode(DevelImageVisual::LoopingMode::RESTART), @@ -87,7 +89,9 @@ VectorAnimationTask::VectorAnimationTask(VisualFactoryCache& factoryCache) mLoadRequest(false), mLoadFailed(false), mRasterized(false), - mKeepAnimation(false) + mKeepAnimation(false), + mLayerInfoCached(false), + mMarkerInfoCached(false) { mVectorRenderer.UploadCompletedSignal().Connect(this, &VectorAnimationTask::OnUploadCompleted); } @@ -484,12 +488,38 @@ void VectorAnimationTask::SetLoopingMode(DevelImageVisual::LoopingMode::Type loo void VectorAnimationTask::GetLayerInfo(Property::Map& map) const { - mVectorRenderer.GetLayerInfo(map); + // Fast-out if file is loading, or load failed. + if(mLoadFailed || IsLoadRequested()) + { + return; + } + + if(DALI_UNLIKELY(!mLayerInfoCached)) + { + // Update only 1 time. + mLayerInfoCached = true; + mVectorRenderer.GetLayerInfo(mCachedLayerInfo); + } + + map = mCachedLayerInfo; } void VectorAnimationTask::GetMarkerInfo(Property::Map& map) const { - mVectorRenderer.GetMarkerInfo(map); + // Fast-out if file is loading, or load failed. + if(mLoadFailed || IsLoadRequested()) + { + return; + } + + if(DALI_UNLIKELY(!mMarkerInfoCached)) + { + // Update only 1 time. + mMarkerInfoCached = true; + mVectorRenderer.GetMarkerInfo(mCachedMarkerInfo); + } + + map = mCachedMarkerInfo; } VectorAnimationTask::ResourceReadySignalType& VectorAnimationTask::ResourceReadySignal() 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 367fc8a..dcd66fc 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 @@ -373,6 +373,8 @@ private: ResourceReadySignalType mResourceReadySignal; std::unique_ptr mAnimationFinishedCallback{}; std::unique_ptr mLoadCompletedCallback{}; + mutable Property::Map mCachedLayerInfo; + mutable Property::Map mCachedMarkerInfo; PlayState mPlayState; DevelImageVisual::StopBehavior::Type mStopBehavior; DevelImageVisual::LoopingMode::Type mLoopingMode; @@ -389,15 +391,17 @@ private: uint32_t mAnimationDataIndex; int32_t mLoopCount; int32_t mCurrentLoop; - bool mForward; - bool mUpdateFrameNumber; - bool mNeedAnimationFinishedTrigger; - bool mAnimationDataUpdated; - bool mDestroyTask; - bool mLoadRequest; - bool mLoadFailed; - bool mRasterized; - bool mKeepAnimation; + bool mForward : 1; + bool mUpdateFrameNumber : 1; + bool mNeedAnimationFinishedTrigger : 1; + bool mAnimationDataUpdated : 1; + bool mDestroyTask : 1; + bool mLoadRequest : 1; + bool mLoadFailed : 1; + bool mRasterized : 1; + bool mKeepAnimation : 1; + mutable bool mLayerInfoCached : 1; + mutable bool mMarkerInfoCached : 1; }; } // namespace Internal -- 2.7.4