From e8954068388a568c9d89de31ae033fe94d0ce20d Mon Sep 17 00:00:00 2001 From: Heeyong Song Date: Wed, 13 Jul 2022 16:29:44 +0900 Subject: [PATCH] (Vector) Fix occasional tc failure Change-Id: I9690000614119603e40385cb785277e10140bd5a --- .../toolkit-vector-animation-renderer.cpp | 17 ++++++-- .../utc-Dali-AnimatedVectorImageVisual.cpp | 16 ++++++- .../animated-vector-image-visual.cpp | 50 +++++++++++++--------- .../animated-vector-image-visual.h | 4 +- .../vector-animation-manager.cpp | 10 ++--- .../vector-animation-task.cpp | 21 ++------- .../animated-vector-image/vector-animation-task.h | 9 +++- 7 files changed, 76 insertions(+), 51 deletions(-) diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.cpp index 4b6c5c8..e6456ec 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -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() diff --git a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp index f69ae92..0529655 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp @@ -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(DummyControl::Property::TEST_VISUAL); Property::Value* value = map.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER); int totalFrameNumber = value->Get(); @@ -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(); diff --git a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp index 9636775..4b547b4 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp +++ b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp @@ -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(); - 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(); + 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() diff --git a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h index 533fc71..221cf23 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h +++ b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h @@ -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. diff --git a/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.cpp b/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.cpp index f23439d..7971b4d 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.cpp +++ b/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.cpp @@ -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; } 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 4d31135..b79f422 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 @@ -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 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 fb4a55c..1e4ff4c 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 @@ -45,7 +45,14 @@ typedef IntrusivePtr VectorAnimationTaskPtr; class VectorAnimationTask : public RefObject, public ConnectionTracker { public: - using ResourceReadySignalType = Signal; + enum class ResourceStatus + { + LOADED, /// Resource is loaded + READY, /// Resource is ready + FAILED /// Resource is fail to load + }; + + using ResourceReadySignalType = Signal; using TimePoint = std::chrono::time_point; -- 2.7.4