1 #ifndef DALI_TOOLKIT_VECTOR_ANIMATION_THREAD_H
2 #define DALI_TOOLKIT_VECTOR_ANIMATION_THREAD_H
5 * Copyright (c) 2023 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/integration-api/adaptor-framework/trace-factory-interface.h>
25 #include <dali/public-api/adaptor-framework/round-robin-container-view.h>
26 #include <dali/public-api/signals/connection-tracker.h>
30 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h>
39 * The main animation thread for vector animations
41 class VectorAnimationThread : public Thread
47 VectorAnimationThread();
52 ~VectorAnimationThread() override;
55 * @brief 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.
64 * @param[in] task The completed task
65 * @param[in] success true if the task succeeded, false otherwise.
66 * @param[in] keepAnimation true if the animation is running, false otherwise.
68 void OnTaskCompleted(VectorAnimationTaskPtr task, bool success, bool keepAnimation);
71 * @brief Called when the sleep thread is awaken.
73 void OnAwakeFromSleep();
76 * @brief Add an event trigger callback.
78 * @param callback The callback to add
79 * @note Ownership of the callback is NOT passed onto this class.
80 * @note The callback will be excuted in the main thread.
82 void AddEventTriggerCallback(CallbackBase* callback);
85 * @brief Remove an event trigger callback.
87 * @param callback The callback to remove
89 void RemoveEventTriggerCallback(CallbackBase* callback);
93 * @brief The entry function of the animation thread.
99 * @brief Rasterizes the tasks.
104 * @brief Called when the event callback is triggered.
106 void OnEventCallbackTriggered();
109 * @brief Gets next event callback to process.
111 CallbackBase* GetNextEventCallback();
114 * @brief The thread to sleep until the next frame time.
116 class SleepThread : public Thread
120 * @brief Constructor.
122 SleepThread(CallbackBase* callback);
127 ~SleepThread() override;
130 * @brief Sleeps untile the specified time point.
132 void SleepUntil(std::chrono::time_point<std::chrono::steady_clock> timeToSleepUntil);
136 * @brief The entry function of the animation thread.
141 SleepThread(const SleepThread& thread) = delete;
142 SleepThread& operator=(const SleepThread& thread) = delete;
145 ConditionalWait mConditionalWait;
146 std::unique_ptr<CallbackBase> mAwakeCallback;
147 std::chrono::time_point<std::chrono::steady_clock> mSleepTimePoint;
148 const Dali::LogFactoryInterface& mLogFactory;
149 const Dali::TraceFactoryInterface& mTraceFactory;
156 VectorAnimationThread(const VectorAnimationThread& thread) = delete;
159 VectorAnimationThread& operator=(const VectorAnimationThread& thread) = delete;
162 std::vector<VectorAnimationTaskPtr> mAnimationTasks;
163 std::vector<VectorAnimationTaskPtr> mCompletedTasks;
164 std::vector<VectorAnimationTaskPtr> mWorkingTasks;
165 std::vector<CallbackBase*> mTriggerEventCallbacks{}; // Callbacks are not owned
166 SleepThread mSleepThread;
167 ConditionalWait mConditionalWait;
168 std::unique_ptr<EventThreadCallback> mEventTrigger{};
171 bool mEventTriggered{false};
172 const Dali::LogFactoryInterface& mLogFactory;
173 const Dali::TraceFactoryInterface& mTraceFactory;
174 Dali::AsyncTaskManager mAsyncTaskManager;
177 } // namespace Internal
179 } // namespace Toolkit
183 #endif // #endif // DALI_TOOLKIT_VECTOR_ANIMATION_THREAD_H