${toolkit_src_dir}/visuals/animated-vector-image/vector-animation-manager.cpp
${toolkit_src_dir}/visuals/animated-vector-image/vector-animation-task.cpp
${toolkit_src_dir}/visuals/animated-vector-image/vector-animation-thread.cpp
- ${toolkit_src_dir}/visuals/animated-vector-image/vector-rasterize-thread.cpp
${toolkit_src_dir}/visuals/arc/arc-visual.cpp
${toolkit_src_dir}/visuals/border/border-visual.cpp
${toolkit_src_dir}/visuals/color/color-visual.cpp
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
} // unnamed namespace
VectorAnimationTask::VectorAnimationTask(VisualFactoryCache& factoryCache)
-: mUrl(),
+: AsyncTask(MakeCallback(this, &VectorAnimationTask::TaskCompleted), AsyncTask::ThreadType::WORKER_THREAD),
+ mUrl(),
mVectorRenderer(VectorAnimationRenderer::New()),
mAnimationData(),
mVectorAnimationThread(factoryCache.GetVectorAnimationManager().GetVectorAnimationThread()),
mAnimationDataUpdated(false),
mDestroyTask(false),
mLoadRequest(false),
- mLoadFailed(false)
+ mLoadFailed(false),
+ mRasterized(false),
+ mKeepAnimation(false)
{
mVectorRenderer.UploadCompletedSignal().Connect(this, &VectorAnimationTask::OnUploadCompleted);
}
DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::~VectorAnimationTask: destructor [%p]\n", this);
}
+void VectorAnimationTask::Process()
+{
+ mRasterized = Rasterize();
+}
+
+bool VectorAnimationTask::IsReady()
+{
+ return true;
+}
+
void VectorAnimationTask::Finalize()
{
ConditionalWait::ScopedLock lock(mConditionalWait);
mDestroyTask = true;
}
+void VectorAnimationTask::TaskCompleted(VectorAnimationTaskPtr task)
+{
+ mVectorAnimationThread.OnTaskCompleted(task, task->IsRasterized(), task->IsAnimating());
+}
+
+bool VectorAnimationTask::IsRasterized()
+{
+ return mRasterized;
+}
+
+bool VectorAnimationTask::IsAnimating()
+{
+ return mKeepAnimation;
+}
+
bool VectorAnimationTask::Load(bool synchronousLoading)
{
if(!mVectorRenderer.Load(mUrl))
return mResourceReadySignal;
}
-bool VectorAnimationTask::Rasterize(bool& keepAnimation)
+bool VectorAnimationTask::Rasterize()
{
bool stopped = false;
uint32_t currentFrame;
- keepAnimation = false;
+ mKeepAnimation = false;
{
ConditionalWait::ScopedLock lock(mConditionalWait);
if(mPlayState != PlayState::PAUSED && mPlayState != PlayState::STOPPED)
{
- keepAnimation = true;
+ mKeepAnimation = true;
}
return true;
#define DALI_TOOLKIT_VECTOR_ANIMATION_TASK_H
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
#include <dali/devel-api/adaptor-framework/event-thread-callback.h>
#include <dali/devel-api/adaptor-framework/vector-animation-renderer.h>
#include <dali/devel-api/threading/conditional-wait.h>
+#include <dali/public-api/adaptor-framework/async-task-manager.h>
#include <dali/public-api/common/vector-wrapper.h>
#include <dali/public-api/object/property-array.h>
#include <chrono>
/**
* The task of the vector animation.
*/
-class VectorAnimationTask : public RefObject, public ConnectionTracker
+class VectorAnimationTask : public AsyncTask, public ConnectionTracker
{
public:
enum class ResourceStatus
~VectorAnimationTask() override;
/**
+ * Process the task accodring to the type
+ */
+ void Process() override;
+
+ /**
+ * Whether the task is ready to process.
+ * @return True if the task is ready to process.
+ */
+ bool IsReady() override;
+
+ /**
* @brief Finalizes the task.
*/
void Finalize();
/**
* @brief Rasterizes the current frame.
- * @param[out] keepAnimation true if the animation is running, false otherwise.
* @return true if the rasterization succeeded, false otherwise.
*/
- bool Rasterize(bool& keepAnimation);
+ bool Rasterize();
/**
* @brief Calculates the time for the next frame rasterization.
*/
TimePoint GetNextFrameTime();
+ /**
+ * @brief Called when the rasterization is completed from the asyncTaskManager
+ * @param[in] task The completed task
+ */
+ void TaskCompleted(VectorAnimationTaskPtr task);
+
+ /**
+ * @brief Check the rasterization succeeded
+ * @return true if the rasterization succeeded, false otherwise.
+ */
+ bool IsRasterized();
+
+ /**
+ * @brief Check the animation is running
+ * @return true if the animation is running, false otherwise.
+ */
+ bool IsAnimating();
+
private:
/**
* @brief Loads the animation file.
bool mDestroyTask;
bool mLoadRequest;
bool mLoadFailed;
+ bool mRasterized;
+ bool mKeepAnimation;
};
} // namespace Internal
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
{
namespace
{
-constexpr auto DEFAULT_NUMBER_OF_RASTERIZE_THREADS = size_t{4u};
-constexpr auto NUMBER_OF_RASTERIZE_THREADS_ENV = "DALI_VECTOR_RASTERIZE_THREADS";
-
-size_t GetNumberOfThreads(const char* environmentVariable, size_t defaultValue)
-{
- using Dali::EnvironmentVariable::GetEnvironmentVariable;
- auto numberString = GetEnvironmentVariable(environmentVariable);
- auto numberOfThreads = numberString ? std::strtoul(numberString, nullptr, 10) : 0;
- constexpr auto MAX_NUMBER_OF_THREADS = 100u;
- DALI_ASSERT_DEBUG(numberOfThreads < MAX_NUMBER_OF_THREADS);
- return (numberOfThreads > 0 && numberOfThreads < MAX_NUMBER_OF_THREADS) ? numberOfThreads : defaultValue;
-}
-
#if defined(DEBUG_ENABLED)
Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VECTOR_ANIMATION");
#endif
: mAnimationTasks(),
mCompletedTasks(),
mWorkingTasks(),
- mRasterizers(GetNumberOfThreads(NUMBER_OF_RASTERIZE_THREADS_ENV, DEFAULT_NUMBER_OF_RASTERIZE_THREADS), [&]() { return RasterizeHelper(*this); }),
mSleepThread(MakeCallback(this, &VectorAnimationThread::OnAwakeFromSleep)),
mConditionalWait(),
mNeedToSleep(false),
mDestroyThread(false),
mLogFactory(Dali::Adaptor::Get().GetLogFactory())
{
+ mAsyncTaskManager = Dali::AsyncTaskManager::Get();
mSleepThread.Start();
}
// DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationThread::Rasterize: [next time = %lld]\n", duration.count());
#endif
-
if(nextFrameTime <= currentTime)
{
// If the task is not in the working list
// Add it to the working list
mWorkingTasks.push_back(nextTask);
-
- auto rasterizerHelperIt = mRasterizers.GetNext();
- DALI_ASSERT_ALWAYS(rasterizerHelperIt != mRasterizers.End());
-
- rasterizerHelperIt->Rasterize(nextTask);
+ mAsyncTaskManager.AddTask(nextTask);
}
else
{
}
}
-VectorAnimationThread::RasterizeHelper::RasterizeHelper(VectorAnimationThread& animationThread)
-: RasterizeHelper(std::unique_ptr<VectorRasterizeThread>(new VectorRasterizeThread()), animationThread)
-{
-}
-
-VectorAnimationThread::RasterizeHelper::RasterizeHelper(RasterizeHelper&& rhs)
-: RasterizeHelper(std::move(rhs.mRasterizer), rhs.mAnimationThread)
-{
-}
-
-VectorAnimationThread::RasterizeHelper::RasterizeHelper(std::unique_ptr<VectorRasterizeThread> rasterizer, VectorAnimationThread& animationThread)
-: mRasterizer(std::move(rasterizer)),
- mAnimationThread(animationThread)
-{
- mRasterizer->SetCompletedCallback(MakeCallback(&mAnimationThread, &VectorAnimationThread::OnTaskCompleted));
-}
-
-void VectorAnimationThread::RasterizeHelper::Rasterize(VectorAnimationTaskPtr task)
-{
- if(task)
- {
- mRasterizer->AddTask(task);
- }
-}
-
VectorAnimationThread::SleepThread::SleepThread(CallbackBase* callback)
: mConditionalWait(),
mAwakeCallback(std::unique_ptr<CallbackBase>(callback)),
#define DALI_TOOLKIT_VECTOR_ANIMATION_THREAD_H
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
#include <dali/devel-api/threading/conditional-wait.h>
#include <dali/devel-api/threading/thread.h>
#include <dali/integration-api/adaptor-framework/log-factory-interface.h>
-#include <dali/public-api/signals/connection-tracker.h>
#include <dali/public-api/adaptor-framework/round-robin-container-view.h>
+#include <dali/public-api/signals/connection-tracker.h>
#include <memory>
// INTERNAL INCLUDES
#include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h>
-#include <dali-toolkit/internal/visuals/animated-vector-image/vector-rasterize-thread.h>
namespace Dali
{
*/
void Rasterize();
-private:
- /**
- * @brief Helper class to keep the relation between VectorRasterizeThread and corresponding container
- */
- class RasterizeHelper : public ConnectionTracker
- {
- public:
- /**
- * @brief Create an RasterizeHelper.
- *
- * @param[in] animationThread Reference to the VectorAnimationThread
- */
- RasterizeHelper(VectorAnimationThread& animationThread);
-
- /**
- * @brief Rasterizes the task.
- *
- * @param[in] task The task to rasterize.
- */
- void Rasterize(VectorAnimationTaskPtr task);
-
- public:
- RasterizeHelper(const RasterizeHelper&) = delete;
- RasterizeHelper& operator=(const RasterizeHelper&) = delete;
-
- RasterizeHelper(RasterizeHelper&& rhs);
- RasterizeHelper& operator=(RasterizeHelper&& rhs) = delete;
-
- private:
- /**
- * @brief Main constructor that used by all other constructors
- */
- RasterizeHelper(std::unique_ptr<VectorRasterizeThread> rasterizer, VectorAnimationThread& animationThread);
-
- private:
- std::unique_ptr<VectorRasterizeThread> mRasterizer;
- VectorAnimationThread& mAnimationThread;
- };
-
/**
* @brief The thread to sleep until the next frame time.
*/
VectorAnimationThread& operator=(const VectorAnimationThread& thread) = delete;
private:
- std::vector<VectorAnimationTaskPtr> mAnimationTasks;
- std::vector<VectorAnimationTaskPtr> mCompletedTasks;
- std::vector<VectorAnimationTaskPtr> mWorkingTasks;
- RoundRobinContainerView<RasterizeHelper> mRasterizers;
- SleepThread mSleepThread;
- ConditionalWait mConditionalWait;
- bool mNeedToSleep;
- bool mDestroyThread;
- const Dali::LogFactoryInterface& mLogFactory;
+ std::vector<VectorAnimationTaskPtr> mAnimationTasks;
+ std::vector<VectorAnimationTaskPtr> mCompletedTasks;
+ std::vector<VectorAnimationTaskPtr> mWorkingTasks;
+ SleepThread mSleepThread;
+ ConditionalWait mConditionalWait;
+ bool mNeedToSleep;
+ bool mDestroyThread;
+ const Dali::LogFactoryInterface& mLogFactory;
+ Dali::AsyncTaskManager mAsyncTaskManager;
};
} // namespace Internal
+++ /dev/null
-/*
- * 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// CLASS HEADER
-#include <dali-toolkit/internal/visuals/animated-vector-image/vector-rasterize-thread.h>
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/adaptor-framework/thread-settings.h>
-#include <dali/integration-api/adaptor-framework/adaptor.h>
-#include <dali/integration-api/debug.h>
-#include <chrono>
-#include <thread>
-
-namespace Dali
-{
-namespace Toolkit
-{
-namespace Internal
-{
-namespace
-{
-#if defined(DEBUG_ENABLED)
-Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VECTOR_ANIMATION");
-#endif
-
-} // unnamed namespace
-
-VectorRasterizeThread::VectorRasterizeThread()
-: mRasterizeTasks(),
- mConditionalWait(),
- mCompletedCallback(),
- mDestroyThread(false),
- mIsThreadStarted(false),
- mLogFactory(Dali::Adaptor::Get().GetLogFactory())
-{
-}
-
-VectorRasterizeThread::~VectorRasterizeThread()
-{
- // Stop the thread
- {
- ConditionalWait::ScopedLock lock(mConditionalWait);
- mDestroyThread = true;
- mConditionalWait.Notify(lock);
- }
-
- DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::~VectorRasterizeThread: Join [%p]\n", this);
-
- Join();
-}
-
-void VectorRasterizeThread::SetCompletedCallback(CallbackBase* callback)
-{
- ConditionalWait::ScopedLock lock(mConditionalWait);
-
- mCompletedCallback = std::unique_ptr<CallbackBase>(callback);
-}
-
-void VectorRasterizeThread::AddTask(VectorAnimationTaskPtr task)
-{
- // Lock while adding task to the queue
- ConditionalWait::ScopedLock lock(mConditionalWait);
-
- if(!mIsThreadStarted)
- {
- Start();
- mIsThreadStarted = true;
- }
-
- if(mRasterizeTasks.end() == std::find(mRasterizeTasks.begin(), mRasterizeTasks.end(), task))
- {
- mRasterizeTasks.push_back(task);
-
- // wake up the animation thread
- mConditionalWait.Notify(lock);
- }
-}
-
-void VectorRasterizeThread::Run()
-{
- SetThreadName("VectorRasterizeThread");
- mLogFactory.InstallLogFunction();
-
- while(!mDestroyThread)
- {
- Rasterize();
- }
-}
-
-void VectorRasterizeThread::Rasterize()
-{
- VectorAnimationTaskPtr nextTask;
- {
- // Lock while popping task out from the queue
- ConditionalWait::ScopedLock lock(mConditionalWait);
-
- // conditional wait
- if(mRasterizeTasks.empty())
- {
- mConditionalWait.Wait(lock);
- }
-
- // pop out the next task from the queue
- if(!mRasterizeTasks.empty())
- {
- std::vector<VectorAnimationTaskPtr>::iterator next = mRasterizeTasks.begin();
- nextTask = *next;
- mRasterizeTasks.erase(next);
- }
- }
-
- if(nextTask)
- {
- bool keepAnimation;
- bool success = nextTask->Rasterize(keepAnimation);
-
- if(mCompletedCallback)
- {
- CallbackBase::Execute(*mCompletedCallback, nextTask, success, keepAnimation);
- }
- }
-}
-
-} // namespace Internal
-
-} // namespace Toolkit
-
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_TOOLKIT_VECTOR_IMAGE_RASTERIZE_THREAD_H
-#define DALI_TOOLKIT_VECTOR_IMAGE_RASTERIZE_THREAD_H
-
-/*
- * Copyright (c) 2021 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/threading/conditional-wait.h>
-#include <dali/devel-api/threading/thread.h>
-#include <dali/integration-api/adaptor-framework/log-factory-interface.h>
-#include <memory>
-#include <vector>
-
-// INTERNAL INCLUDES
-#include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h>
-
-namespace Dali
-{
-namespace Toolkit
-{
-namespace Internal
-{
-/**
- * The worker thread for vector image rasterization.
- */
-class VectorRasterizeThread : public Thread
-{
-public:
- /**
- * @brief Constructor.
- */
- VectorRasterizeThread();
-
- /**
- * @brief Destructor.
- */
- ~VectorRasterizeThread() override;
-
- /**
- * The callback is called from the rasterize thread after the rasterization is completed.
- * @param[in] callBack The function to call.
- */
- void SetCompletedCallback(CallbackBase* callback);
-
- /**
- * Add a task to rasterize.
- *
- * @param[in] task The task to rasterize
- */
- void AddTask(VectorAnimationTaskPtr task);
-
-protected:
- /**
- * @brief The entry function of the worker thread.
- * It rasterizes the vector image.
- */
- void Run() override;
-
-private:
- /**
- * Rasterizes the tasks.
- */
- void Rasterize();
-
-private:
- // Undefined
- VectorRasterizeThread(const VectorRasterizeThread& thread) = delete;
-
- // Undefined
- VectorRasterizeThread& operator=(const VectorRasterizeThread& thread) = delete;
-
-private:
- std::vector<VectorAnimationTaskPtr> mRasterizeTasks;
- ConditionalWait mConditionalWait;
- std::unique_ptr<CallbackBase> mCompletedCallback;
- bool mDestroyThread; ///< Whether the thread be destroyed
- bool mIsThreadStarted;
- const Dali::LogFactoryInterface& mLogFactory; ///< The log factory
-};
-
-} // namespace Internal
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // DALI_TOOLKIT_VECTOR_IMAGE_RASTERIZE_THREAD_H