(AnimatedVector) Cache lottie file's layer / marker info 01/301101/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Wed, 8 Nov 2023 11:22:15 +0000 (20:22 +0900)
committerEunki Hong <eunkiki.hong@samsung.com>
Fri, 10 Nov 2023 02:19:23 +0000 (02:19 +0000)
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 <eunkiki.hong@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.cpp
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h

index 907b8af..2aa3d4e 100644 (file)
@@ -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<DummyControlImpl&>(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<Property::Map>(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;
index c0d3802..4bb2471 100644 (file)
@@ -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()
index 367fc8a..dcd66fc 100644 (file)
@@ -373,6 +373,8 @@ private:
   ResourceReadySignalType              mResourceReadySignal;
   std::unique_ptr<CallbackBase>        mAnimationFinishedCallback{};
   std::unique_ptr<CallbackBase>        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