1 #ifndef DALI_TOOLKIT_VECTOR_ANIMATION_THREAD_H
2 #define DALI_TOOLKIT_VECTOR_ANIMATION_THREAD_H
5 * Copyright (c) 2019 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.
22 #include <dali/public-api/signals/connection-tracker.h>
23 #include <dali/devel-api/threading/conditional-wait.h>
24 #include <dali/devel-api/threading/thread.h>
25 #include <dali/integration-api/adaptor-framework/log-factory-interface.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>
42 * The main animation thread for vector animations
44 class VectorAnimationThread : public Thread
51 VectorAnimationThread();
56 ~VectorAnimationThread() override;
59 * Add a animation task into the vector animation thread, called by main thread.
61 * @param[in] task The task added to the thread.
63 void AddTask( VectorAnimationTaskPtr task );
66 * @brief Called when the rasterization is completed from the rasterize thread.
67 * @param task The completed task
69 void OnTaskCompleted( VectorAnimationTaskPtr task, bool stopped );
72 * @brief Called when the sleep thread is awaken.
74 void OnAwakeFromSleep();
79 * @brief The entry function of the animation thread.
86 * Rasterizes the tasks.
93 * @brief Helper class to keep the relation between VectorRasterizeThread and corresponding container
95 class RasterizeHelper : public ConnectionTracker
99 * @brief Create an RasterizeHelper.
101 * @param[in] animationThread Reference to the VectorAnimationThread
103 RasterizeHelper( VectorAnimationThread& animationThread );
106 * @brief Rasterizes the task.
108 * @param[in] task The task to rasterize.
110 void Rasterize( VectorAnimationTaskPtr task );
113 RasterizeHelper( const RasterizeHelper& ) = delete;
114 RasterizeHelper& operator=( const RasterizeHelper& ) = delete;
116 RasterizeHelper( RasterizeHelper&& rhs );
117 RasterizeHelper& operator=( RasterizeHelper&& rhs ) = delete;
122 * @brief Main constructor that used by all other constructors
124 RasterizeHelper( std::unique_ptr< VectorRasterizeThread > rasterizer, VectorAnimationThread& animationThread );
127 std::unique_ptr< VectorRasterizeThread > mRasterizer;
128 VectorAnimationThread& mAnimationThread;
132 * @brief The thread to sleep until the next frame time.
134 class SleepThread : public Thread
139 * @brief Constructor.
141 SleepThread( CallbackBase* callback );
146 ~SleepThread() override;
149 * @brief Sleeps untile the specified time point.
151 void SleepUntil( std::chrono::time_point< std::chrono::system_clock > timeToSleepUntil );
156 * @brief The entry function of the animation thread.
162 SleepThread( const SleepThread& thread ) = delete;
163 SleepThread& operator=( const SleepThread& thread ) = delete;
166 ConditionalWait mConditionalWait;
167 std::unique_ptr< CallbackBase > mAwakeCallback;
168 std::chrono::time_point< std::chrono::system_clock > mSleepTimePoint;
169 const Dali::LogFactoryInterface& mLogFactory;
177 VectorAnimationThread( const VectorAnimationThread& thread ) = delete;
180 VectorAnimationThread& operator=( const VectorAnimationThread& thread ) = delete;
184 std::vector< VectorAnimationTaskPtr > mAnimationTasks;
185 std::vector< VectorAnimationTaskPtr > mCompletedTasks;
186 std::vector< VectorAnimationTaskPtr > mWorkingTasks;
187 RoundRobinContainerView< RasterizeHelper > mRasterizers;
188 SleepThread mSleepThread;
189 ConditionalWait mConditionalWait;
192 const Dali::LogFactoryInterface& mLogFactory;
196 } // namespace Internal
198 } // namespace Toolkit
202 #endif // #endif // DALI_TOOLKIT_VECTOR_ANIMATION_THREAD_H