1 #ifndef DALI_TOOLKIT_VECTOR_ANIMATION_THREAD_H
2 #define DALI_TOOLKIT_VECTOR_ANIMATION_THREAD_H
5 * Copyright (c) 2021 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 task The completed task
65 void OnTaskCompleted(VectorAnimationTaskPtr task, bool stopped);
68 * @brief Called when the sleep thread is awaken.
70 void OnAwakeFromSleep();
74 * @brief The entry function of the animation thread.
80 * Rasterizes the tasks.
86 * @brief Helper class to keep the relation between VectorRasterizeThread and corresponding container
88 class RasterizeHelper : public ConnectionTracker
92 * @brief Create an RasterizeHelper.
94 * @param[in] animationThread Reference to the VectorAnimationThread
96 RasterizeHelper(VectorAnimationThread& animationThread);
99 * @brief Rasterizes the task.
101 * @param[in] task The task to rasterize.
103 void Rasterize(VectorAnimationTaskPtr task);
106 RasterizeHelper(const RasterizeHelper&) = delete;
107 RasterizeHelper& operator=(const RasterizeHelper&) = delete;
109 RasterizeHelper(RasterizeHelper&& rhs);
110 RasterizeHelper& operator=(RasterizeHelper&& rhs) = delete;
114 * @brief Main constructor that used by all other constructors
116 RasterizeHelper(std::unique_ptr<VectorRasterizeThread> rasterizer, VectorAnimationThread& animationThread);
119 std::unique_ptr<VectorRasterizeThread> mRasterizer;
120 VectorAnimationThread& mAnimationThread;
124 * @brief The thread to sleep until the next frame time.
126 class SleepThread : public Thread
130 * @brief Constructor.
132 SleepThread(CallbackBase* callback);
137 ~SleepThread() override;
140 * @brief Sleeps untile the specified time point.
142 void SleepUntil(std::chrono::time_point<std::chrono::steady_clock> timeToSleepUntil);
146 * @brief The entry function of the animation thread.
151 SleepThread(const SleepThread& thread) = delete;
152 SleepThread& operator=(const SleepThread& thread) = delete;
155 ConditionalWait mConditionalWait;
156 std::unique_ptr<CallbackBase> mAwakeCallback;
157 std::chrono::time_point<std::chrono::steady_clock> mSleepTimePoint;
158 const Dali::LogFactoryInterface& mLogFactory;
165 VectorAnimationThread(const VectorAnimationThread& thread) = delete;
168 VectorAnimationThread& operator=(const VectorAnimationThread& thread) = delete;
171 std::vector<VectorAnimationTaskPtr> mAnimationTasks;
172 std::vector<VectorAnimationTaskPtr> mCompletedTasks;
173 std::vector<VectorAnimationTaskPtr> mWorkingTasks;
174 RoundRobinContainerView<RasterizeHelper> mRasterizers;
175 SleepThread mSleepThread;
176 ConditionalWait mConditionalWait;
179 const Dali::LogFactoryInterface& mLogFactory;
182 } // namespace Internal
184 } // namespace Toolkit
188 #endif // #endif // DALI_TOOLKIT_VECTOR_ANIMATION_THREAD_H