(Vector) Fix occasional tc failure 85/277785/1
authorHeeyong Song <heeyong.song@samsung.com>
Wed, 13 Jul 2022 07:29:44 +0000 (16:29 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Wed, 13 Jul 2022 08:20:38 +0000 (17:20 +0900)
Change-Id: I9690000614119603e40385cb785277e10140bd5a

automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.cpp
automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp
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-manager.cpp
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.cpp
dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h

index 4b6c5c8..e6456ec 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
 #include <dali/devel-api/adaptor-framework/vector-animation-renderer.h>
+#include <dali/devel-api/threading/mutex.h>
 #include <dali/public-api/object/base-object.h>
 #include <toolkit-application.h>
 #include <toolkit-event-thread-callback.h>
@@ -70,6 +71,7 @@ public:
 
   bool Load(const std::string& url)
   {
+    Dali::Mutex::ScopedLock lock(mMutex);
     mUrl = url;
     if(mUrl == "invalid.json")
     {
@@ -80,7 +82,6 @@ public:
     {
       // Change total frame number for test
       mTotalFrameNumber = 200;
-      mTestFrameDrop    = true;
     }
 
     mDefaultWidth  = 100;
@@ -96,6 +97,7 @@ public:
 
   void SetSize(uint32_t width, uint32_t height)
   {
+    Dali::Mutex::ScopedLock lock(mMutex);
     mWidth  = width;
     mHeight = height;
 
@@ -108,6 +110,7 @@ public:
 
   bool Render(uint32_t frameNumber)
   {
+    Dali::Mutex::ScopedLock lock(mMutex);
     if(mWidth == 0 || mHeight == 0)
     {
       return false;
@@ -179,8 +182,12 @@ public:
 
   void InvalidateBuffer()
   {
-    mNeedTrigger   = true;
-    mResourceReady = false;
+    Dali::Mutex::ScopedLock lock(mMutex);
+    if(mResourceReady)
+    {
+      mNeedTrigger   = true;
+      mResourceReady = false;
+    }
   }
 
   Dali::VectorAnimationRenderer::UploadCompletedSignalType& UploadCompletedSignal()
@@ -211,6 +218,7 @@ public:
 
   std::string    mUrl;
   Dali::Renderer mRenderer;
+  Dali::Mutex    mMutex;
   uint32_t       mWidth;
   uint32_t       mHeight;
   uint32_t       mDefaultWidth;
@@ -353,7 +361,8 @@ namespace VectorAnimationRenderer
 {
 void DelayRendering(uint32_t delay)
 {
-  Dali::Internal::Adaptor::gVectorAnimationRenderer->mDelayTime = delay;
+  Dali::Internal::Adaptor::gVectorAnimationRenderer->mDelayTime     = delay;
+  Dali::Internal::Adaptor::gVectorAnimationRenderer->mTestFrameDrop = true;
 }
 
 uint32_t GetDroppedFrames()
index f69ae92..0529655 100644 (file)
@@ -610,6 +610,9 @@ int UtcDaliAnimatedVectorImageVisualNaturalSize(void)
   application.SendNotification();
   application.Render();
 
+  // Trigger count is 1 - load
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
   visual.GetNaturalSize(naturalSize);
 
   DALI_TEST_EQUALS(naturalSize, Vector2(100.0f, 100.0f), TEST_LOCATION); // 100x100 is the content default size.
@@ -1511,6 +1514,9 @@ int UtcDaliAnimatedVectorImageVisualMultipleInstances(void)
 
   application.GetScene().Add(actor2);
 
+  application.SendNotification();
+  application.Render();
+
   // Trigger count is 4 - load & render a frame for each instance
   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
 
@@ -1798,6 +1804,12 @@ int UtcDaliAnimatedVectorImageVisualFrameDrops(void)
 
   application.GetScene().Add(actor);
 
+  application.SendNotification();
+  application.Render();
+
+  // Trigger count is 2 - load, render the first frame
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
+
   Property::Map    map              = actor.GetProperty<Property::Map>(DummyControl::Property::TEST_VISUAL);
   Property::Value* value            = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER);
   int              totalFrameNumber = value->Get<int>();
@@ -1811,8 +1823,8 @@ int UtcDaliAnimatedVectorImageVisualFrameDrops(void)
   application.SendNotification();
   application.Render();
 
-  // Trigger count is 3 - load, render the first frame & calculating frame drops
-  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
+  // Trigger count is 1 - calculating frame drops
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
 
   // Check dropped frame
   uint32_t frames = Test::VectorAnimationRenderer::GetDroppedFrames();
index 9636775..4b547b4 100644 (file)
@@ -374,7 +374,7 @@ void AnimatedVectorImageVisual::DoSetOnScene(Actor& actor)
 void AnimatedVectorImageVisual::DoSetOffScene(Actor& actor)
 {
   StopAnimation();
-  SendAnimationData();
+  TriggerVectorRasterization();
 
   if(mImpl->mRenderer)
   {
@@ -423,7 +423,7 @@ void AnimatedVectorImageVisual::OnSetTransform()
       mAnimationData.resendFlag |= VectorAnimationTask::RESEND_PLAY_STATE;
     }
 
-    SendAnimationData();
+    TriggerVectorRasterization();
   }
 }
 
@@ -489,31 +489,41 @@ void AnimatedVectorImageVisual::OnDoAction(const Property::Index actionId, const
   TriggerVectorRasterization();
 }
 
-void AnimatedVectorImageVisual::OnResourceReady(bool success)
+void AnimatedVectorImageVisual::OnResourceReady(VectorAnimationTask::ResourceStatus status)
 {
-  mLoadFailed = !success;
-
-  // If weak handle is holding a placement actor, it is the time to add the renderer to actor.
-  Actor actor = mPlacementActor.GetHandle();
-  if(actor && !mRendererAdded)
+  if(status == VectorAnimationTask::ResourceStatus::LOADED)
   {
-    if(success)
-    {
-      actor.AddRenderer(mImpl->mRenderer);
-      ResourceReady(Toolkit::Visual::ResourceStatus::READY);
-    }
-    else
+    if(mImpl->mEventObserver)
     {
-      Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
-      mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize);
-      actor.AddRenderer(mImpl->mRenderer);
-      ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
+      mImpl->mEventObserver->RelayoutRequest(*this);
     }
+  }
+  else
+  {
+    mLoadFailed = status == VectorAnimationTask::ResourceStatus::FAILED ? true : false;
 
-    mRendererAdded = true;
+    // If weak handle is holding a placement actor, it is the time to add the renderer to actor.
+    Actor actor = mPlacementActor.GetHandle();
+    if(actor && !mRendererAdded)
+    {
+      if(!mLoadFailed)
+      {
+        actor.AddRenderer(mImpl->mRenderer);
+        ResourceReady(Toolkit::Visual::ResourceStatus::READY);
+      }
+      else
+      {
+        Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
+        mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize);
+        actor.AddRenderer(mImpl->mRenderer);
+        ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
+      }
 
-    DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "Renderer is added (success = %d) [%p]\n", success, this);
+      mRendererAdded = true;
+    }
   }
+
+  DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "Renderer is added (status = %d) [%p]\n", status, this);
 }
 
 void AnimatedVectorImageVisual::OnAnimationFinished()
index 533fc71..221cf23 100644 (file)
@@ -169,9 +169,9 @@ private:
 
   /**
    * @brief Called when the resource is ready.
-   * @param[in] success True if the texture load was successful. If false, then the resource failed to load.
+   * @param[in] status The resource status
    */
-  void OnResourceReady(bool success);
+  void OnResourceReady(VectorAnimationTask::ResourceStatus status);
 
   /**
    * @brief Event callback from rasterize thread. This is called after the animation is finished.
index f23439d..7971b4d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -57,7 +57,7 @@ VectorAnimationManager::~VectorAnimationManager()
 
   if(mProcessorRegistered)
   {
-    Adaptor::Get().UnregisterProcessor(*this);
+    Adaptor::Get().UnregisterProcessor(*this, true);
   }
 
   for(auto observer : mLifecycleObservers)
@@ -97,7 +97,7 @@ void VectorAnimationManager::RegisterEventCallback(CallbackBase* callback)
 
   if(!mProcessorRegistered)
   {
-    Adaptor::Get().RegisterProcessor(*this);
+    Adaptor::Get().RegisterProcessor(*this, true); // Use post processor to trigger after layoutting
     mProcessorRegistered = true;
   }
 }
@@ -113,7 +113,7 @@ void VectorAnimationManager::UnregisterEventCallback(CallbackBase* callback)
     {
       if(Adaptor::IsAvailable())
       {
-        Adaptor::Get().UnregisterProcessor(*this);
+        Adaptor::Get().UnregisterProcessor(*this, true);
         mProcessorRegistered = false;
       }
     }
@@ -129,7 +129,7 @@ void VectorAnimationManager::Process(bool postProcessor)
   }
   mEventCallbacks.clear();
 
-  Adaptor::Get().UnregisterProcessor(*this);
+  Adaptor::Get().UnregisterProcessor(*this, true);
   mProcessorRegistered = false;
 }
 
index 4d31135..b79f422 100644 (file)
@@ -397,11 +397,7 @@ bool VectorAnimationTask::Rasterize(bool& keepAnimation)
 
     if(mLoadRequest)
     {
-      bool result = Load();
-      if(!result)
-      {
-        return false;
-      }
+      return Load();
     }
   }
 
@@ -652,27 +648,18 @@ void VectorAnimationTask::ApplyAnimationData()
 
 void VectorAnimationTask::OnUploadCompleted()
 {
-  mResourceReadySignal.Emit(true);
+  mResourceReadySignal.Emit(ResourceStatus::READY);
 }
 
 void VectorAnimationTask::OnLoadCompleted()
 {
   if(!mLoadFailed)
   {
-    if(mWidth == 0 && mHeight == 0)
-    {
-      uint32_t width, height;
-      mVectorRenderer.GetDefaultSize(width, height);
-
-      SetSize(width, height);
-
-      mVectorAnimationThread.AddTask(this);
-    }
+    mResourceReadySignal.Emit(ResourceStatus::LOADED);
   }
   else
   {
-    // Load failed
-    mResourceReadySignal.Emit(false);
+    mResourceReadySignal.Emit(ResourceStatus::FAILED);
   }
 }
 } // namespace Internal
index fb4a55c..1e4ff4c 100644 (file)
@@ -45,7 +45,14 @@ typedef IntrusivePtr<VectorAnimationTask> VectorAnimationTaskPtr;
 class VectorAnimationTask : public RefObject, public ConnectionTracker
 {
 public:
-  using ResourceReadySignalType = Signal<void(bool)>;
+  enum class ResourceStatus
+  {
+    LOADED, /// Resource is loaded
+    READY,  /// Resource is ready
+    FAILED  /// Resource is fail to load
+  };
+
+  using ResourceReadySignalType = Signal<void(ResourceStatus)>;
 
   using TimePoint = std::chrono::time_point<std::chrono::steady_clock>;