1 #ifndef DALI_TOOLKIT_VECTOR_ANIMATION_THREAD_H
2 #define DALI_TOOLKIT_VECTOR_ANIMATION_THREAD_H
5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 #include <dali/devel-api/threading/conditional-wait.h>
22 #include <dali/devel-api/threading/thread.h>
23 #include <dali/integration-api/adaptor-framework/log-factory-interface.h>
24 #include <dali/public-api/signals/connection-tracker.h>
28 #include <dali-toolkit/internal/helpers/round-robin-container-view.h>
29 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h>
30 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-rasterize-thread.h>
39 * The main animation thread for vector animations
41 class VectorAnimationThread : public Thread
47 VectorAnimationThread();
52 ~VectorAnimationThread() override;
55 * Add a animation task into the vector animation thread, called by main thread.
57 * @param[in] task The task added to the thread.
59 void AddTask(VectorAnimationTaskPtr task);
62 * @brief Called when the rasterization is completed from the rasterize thread.
63 * @param[in] task The completed task
64 * @param[in] success true if the task succeeded, false otherwise.
65 * @param[in] keepAnimation true if the animation is running, false otherwise.
67 void OnTaskCompleted(VectorAnimationTaskPtr task, bool success, bool keepAnimation);
70 * @brief Called when the sleep thread is awaken.
72 void OnAwakeFromSleep();
76 * @brief The entry function of the animation thread.
82 * Rasterizes the tasks.
88 * @brief Helper class to keep the relation between VectorRasterizeThread and corresponding container
90 class RasterizeHelper : public ConnectionTracker
94 * @brief Create an RasterizeHelper.
96 * @param[in] animationThread Reference to the VectorAnimationThread
98 RasterizeHelper(VectorAnimationThread& animationThread);
101 * @brief Rasterizes the task.
103 * @param[in] task The task to rasterize.
105 void Rasterize(VectorAnimationTaskPtr task);
108 RasterizeHelper(const RasterizeHelper&) = delete;
109 RasterizeHelper& operator=(const RasterizeHelper&) = delete;
111 RasterizeHelper(RasterizeHelper&& rhs);
112 RasterizeHelper& operator=(RasterizeHelper&& rhs) = delete;
116 * @brief Main constructor that used by all other constructors
118 RasterizeHelper(std::unique_ptr<VectorRasterizeThread> rasterizer, VectorAnimationThread& animationThread);
121 std::unique_ptr<VectorRasterizeThread> mRasterizer;
122 VectorAnimationThread& mAnimationThread;
126 * @brief The thread to sleep until the next frame time.
128 class SleepThread : public Thread
132 * @brief Constructor.
134 SleepThread(CallbackBase* callback);
139 ~SleepThread() override;
142 * @brief Sleeps untile the specified time point.
144 void SleepUntil(std::chrono::time_point<std::chrono::steady_clock> timeToSleepUntil);
148 * @brief The entry function of the animation thread.
153 SleepThread(const SleepThread& thread) = delete;
154 SleepThread& operator=(const SleepThread& thread) = delete;
157 ConditionalWait mConditionalWait;
158 std::unique_ptr<CallbackBase> mAwakeCallback;
159 std::chrono::time_point<std::chrono::steady_clock> mSleepTimePoint;
160 const Dali::LogFactoryInterface& mLogFactory;
167 VectorAnimationThread(const VectorAnimationThread& thread) = delete;
170 VectorAnimationThread& operator=(const VectorAnimationThread& thread) = delete;
173 std::vector<VectorAnimationTaskPtr> mAnimationTasks;
174 std::vector<VectorAnimationTaskPtr> mCompletedTasks;
175 std::vector<VectorAnimationTaskPtr> mWorkingTasks;
176 RoundRobinContainerView<RasterizeHelper> mRasterizers;
177 SleepThread mSleepThread;
178 ConditionalWait mConditionalWait;
181 const Dali::LogFactoryInterface& mLogFactory;
184 } // namespace Internal
186 } // namespace Toolkit
190 #endif // #endif // DALI_TOOLKIT_VECTOR_ANIMATION_THREAD_H