From 3cae9ffd1eae23d3d16ff329d3981afd47efe3d1 Mon Sep 17 00:00:00 2001 From: seungho baek Date: Tue, 24 Oct 2023 19:09:38 +0900 Subject: [PATCH] To stop animated image visual when it become invisible. Change-Id: I48ba87d31ba6db63489879cb4a7940da8714a29f Signed-off-by: seungho baek --- .../dali-toolkit/utc-Dali-AnimatedImageVisual.cpp | 159 +++++++++++++++++++++ .../animated-image/animated-image-visual.cpp | 37 +++++ .../visuals/animated-image/animated-image-visual.h | 12 ++ 3 files changed, 208 insertions(+) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp index 73f4cf7..4535413 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #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(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(), 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(), 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(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(), 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(), 0, TEST_LOCATION); + + END_TEST; +} \ No newline at end of file diff --git a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp index 60d992c..6dac0e7 100644 --- a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp +++ b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp @@ -19,6 +19,7 @@ #include // EXTERNAL INCLUDES +#include #include #include #include @@ -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 diff --git a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.h b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.h index 84113a1..b37d74b 100644 --- a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.h +++ b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.h @@ -19,6 +19,8 @@ */ // EXTERNAL INCLUDES +#include +#include #include #include #include @@ -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); -- 2.7.4