To stop animated image visual when it become invisible. 24/301424/7
authorseungho baek <sbsh.baek@samsung.com>
Tue, 24 Oct 2023 10:09:38 +0000 (19:09 +0900)
committerseungho baek <sbsh.baek@samsung.com>
Wed, 29 Nov 2023 05:32:25 +0000 (14:32 +0900)
Change-Id: I48ba87d31ba6db63489879cb4a7940da8714a29f
Signed-off-by: seungho baek <sbsh.baek@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp
dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp
dali-toolkit/internal/visuals/animated-image/animated-image-visual.h

index 73f4cf7..4535413 100644 (file)
@@ -28,6 +28,7 @@
 #include <dali-toolkit/devel-api/visuals/animated-image-visual-actions-devel.h>
 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
+#include <dali/devel-api/adaptor-framework/window-devel.h>
 
 #include "dummy-control.h"
 
@@ -1992,3 +1993,161 @@ int UtcDaliAnimatedImageVisualDesiredSize(void)
 
   END_TEST;
 }
+
+
+int UtcDaliAnimatedImageVisualControlVisibilityChanged(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliAnimatedImageVisualControlVisibilityChanged");
+
+  Property::Map propertyMap;
+  propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_IMAGE)
+    .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
+    .Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME)
+    .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);
+
+  application.SendNotification();
+  application.Render();
+
+  // Trigger count is 2 - load & render a frame
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
+
+  Property::Map attributes;
+  DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes);
+
+  application.SendNotification();
+  application.Render();
+
+  // Check frame number
+  DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
+  Renderer renderer = actor.GetRendererAt(0u);
+  DALI_TEST_CHECK(renderer);
+
+  Test::EmitGlobalTimerSignal();
+  application.SendNotification();
+  application.Render(16);
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  Property::Map resultMap;
+  visual.CreatePropertyMap(resultMap);
+
+  // check the property values from the returned map from a visual
+  Property::Value* value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
+  DALI_TEST_CHECK(value);
+  DALI_TEST_NOT_EQUALS(value->Get<int>(), 0, Math::MACHINE_EPSILON_100, TEST_LOCATION);
+
+  actor.SetProperty(Actor::Property::VISIBLE, false);
+
+  Test::EmitGlobalTimerSignal();
+  application.SendNotification();
+  application.Render(16);
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  visual.CreatePropertyMap(resultMap);
+
+  // check the property values from the returned map from a visual
+  value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
+  DALI_TEST_CHECK(value);
+  DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliAnimatedImageVisualWindowVisibilityChanged(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliAnimatedImageVisualWindowVisibilityChanged");
+
+  Property::Map propertyMap;
+  propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_IMAGE)
+    .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
+    .Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME)
+    .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);
+
+  application.SendNotification();
+  application.Render();
+
+  // Trigger count is 2 - load & render a frame
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
+
+  Property::Map attributes;
+  DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes);
+
+  application.SendNotification();
+  application.Render();
+
+  // Check frame number
+  DALI_TEST_CHECK(actor.GetRendererCount() == 1u);
+  Renderer renderer = actor.GetRendererAt(0u);
+  DALI_TEST_CHECK(renderer);
+
+  Test::EmitGlobalTimerSignal();
+  application.SendNotification();
+  application.Render(16);
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  Property::Map resultMap;
+  visual.CreatePropertyMap(resultMap);
+
+  // check the property values from the returned map from a visual
+  Property::Value* value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
+  DALI_TEST_CHECK(value);
+  DALI_TEST_NOT_EQUALS(value->Get<int>(), 0, Math::MACHINE_EPSILON_100, TEST_LOCATION);
+
+  Window window = DevelWindow::Get(actor);
+  window.Hide();
+
+  Test::EmitGlobalTimerSignal();
+  application.SendNotification();
+  application.Render(16);
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  visual.CreatePropertyMap(resultMap);
+
+  // check the property values from the returned map from a visual
+  value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER);
+  DALI_TEST_CHECK(value);
+  DALI_TEST_EQUALS(value->Get<int>(), 0, TEST_LOCATION);
+
+  END_TEST;
+}
\ No newline at end of file
index 60d992c..6dac0e7 100644 (file)
@@ -19,6 +19,7 @@
 #include <dali-toolkit/internal/visuals/animated-image/animated-image-visual.h>
 
 // EXTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/window-devel.h>
 #include <dali/devel-api/adaptor-framework/image-loading.h>
 #include <dali/integration-api/debug.h>
 #include <dali/public-api/rendering/decorated-visual-renderer.h>
@@ -764,6 +765,14 @@ void AnimatedImageVisual::DoSetOnScene(Actor& actor)
   mStartFirstFrame = true;
   mPlacementActor  = actor;
   PrepareTextureSet();
+
+  DevelActor::VisibilityChangedSignal(actor).Connect(this, &AnimatedImageVisual::OnControlVisibilityChanged);
+
+  Window window = DevelWindow::Get(actor);
+  if(window)
+  {
+    DevelWindow::VisibilityChangedSignal(window).Connect(this, &AnimatedImageVisual::OnWindowVisibilityChanged);
+  }
 }
 
 void AnimatedImageVisual::DoSetOffScene(Actor& actor)
@@ -790,6 +799,14 @@ void AnimatedImageVisual::DoSetOffScene(Actor& actor)
   mStartFirstFrame   = false;
   mCurrentFrameIndex = FIRST_FRAME_INDEX;
   mCurrentLoopIndex  = FIRST_LOOP;
+
+  DevelActor::VisibilityChangedSignal(actor).Disconnect(this, &AnimatedImageVisual::OnControlVisibilityChanged);
+
+  Window window = DevelWindow::Get(actor);
+  if(window)
+  {
+    DevelWindow::VisibilityChangedSignal(window).Disconnect(this, &AnimatedImageVisual::OnWindowVisibilityChanged);
+  }
 }
 
 void AnimatedImageVisual::OnSetTransform()
@@ -1098,6 +1115,26 @@ void AnimatedImageVisual::CheckMaskTexture()
   }
 }
 
+void AnimatedImageVisual::OnControlVisibilityChanged(Actor actor, bool visible, DevelActor::VisibilityChange::Type type)
+{
+  if(!visible && mActionStatus != DevelAnimatedImageVisual::Action::STOP)
+  {
+    mActionStatus = DevelAnimatedImageVisual::Action::STOP;
+    DisplayNextFrame();
+    DALI_LOG_INFO(gAnimImgLogFilter, Debug::Verbose, "AnimatedImageVisual::OnControlVisibilityChanged: invisibile. Pause animation [%p]\n", this);
+  }
+}
+
+void AnimatedImageVisual::OnWindowVisibilityChanged(Window window, bool visible)
+{
+  if(!visible && mActionStatus != DevelAnimatedImageVisual::Action::STOP)
+  {
+    mActionStatus = DevelAnimatedImageVisual::Action::STOP;
+    DisplayNextFrame();
+    DALI_LOG_INFO(gAnimImgLogFilter, Debug::Verbose, "AnimatedImageVisual::OnWindowVisibilityChanged: invisibile. Pause animation [%p]\n", this);
+  }
+}
+
 } // namespace Internal
 
 } // namespace Toolkit
index 84113a1..b37d74b 100644 (file)
@@ -19,6 +19,8 @@
  */
 
 // EXTERNAL INCLUDES
+#include <dali/devel-api/actors/actor-devel.h>
+#include <dali/public-api/adaptor-framework/window.h>
 #include <dali/devel-api/adaptor-framework/animated-image-loading.h>
 #include <dali/public-api/adaptor-framework/timer.h>
 #include <dali/public-api/common/dali-vector.h>
@@ -256,6 +258,16 @@ private:
    */
   void CheckMaskTexture();
 
+  /**
+   * @brief Callback when the visibility of the actor is changed.
+   */
+  void OnControlVisibilityChanged(Actor actor, bool visible, DevelActor::VisibilityChange::Type type);
+
+  /**
+   * @brief Callback when the visibility of the window is changed.
+   */
+  void OnWindowVisibilityChanged(Window window, bool visible);
+
   // Undefined
   AnimatedImageVisual(const AnimatedImageVisual& animatedImageVisual);