1 #ifndef DALI_TOOLKIT_VECTOR_ANIMATION_TASK_H
2 #define DALI_TOOLKIT_VECTOR_ANIMATION_TASK_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.
21 #include <dali/devel-api/adaptor-framework/event-thread-callback.h>
22 #include <dali/devel-api/adaptor-framework/vector-animation-renderer.h>
23 #include <dali/devel-api/threading/conditional-wait.h>
28 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
39 class VisualFactoryCache;
40 class VectorAnimationThread;
41 class VectorAnimationTask;
42 typedef IntrusivePtr< VectorAnimationTask > VectorAnimationTaskPtr;
45 * The task of the vector animation.
47 class VectorAnimationTask : public RefObject
51 using UploadCompletedSignalType = Dali::VectorAnimationRenderer::UploadCompletedSignalType;
56 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
57 * @param[in] url The url of the vector animation file
59 VectorAnimationTask( VisualFactoryCache& factoryCache, const std::string& url );
64 virtual ~VectorAnimationTask();
67 * @brief Finalizes the task.
72 * @brief Sets the renderer used to display the result image.
74 * @param[in] renderer The renderer used to display the result image
76 void SetRenderer( Renderer renderer );
79 * @brief Sets the target image size.
81 * @param[in] width The target image width
82 * @param[in] height The target image height
84 void SetSize( uint32_t width, uint32_t height );
87 * @brief Play the vector animation.
92 * @brief Stop the vector animation.
97 * @brief Pause the vector animation.
99 void PauseAnimation();
102 * @brief Render one frame. The current frame number will be increased.
107 * @brief This callback is called after the animation is finished.
108 * @param[in] callback The animation finished callback
110 void SetAnimationFinishedCallback( EventThreadCallback* callback );
113 * @brief Enable looping for 'count' repeats. -1 means to repeat forever.
114 * @param[in] count The number of times to loop
116 void SetLoopCount( int32_t count );
119 * @brief Set the playing range in frame number.
120 * @param[in] playRange The array to specify minimum and maximum progress.
121 * The animation will play between those values.
123 void SetPlayRange( Property::Array& playRange );
126 * @brief Gets the playing range in frame number.
127 * @param[out] startFrame The frame number to specify minimum progress.
128 * @param[out] endFrame The frame number to specify maximum progress.
130 void GetPlayRange( uint32_t& startFrame, uint32_t& endFrame );
133 * @brief Get the play state
134 * @return The play state
136 DevelImageVisual::PlayState::Type GetPlayState() const;
139 * @brief Sets the current frame number of the animation.
140 * @param[in] frameNumber The new frame number between [0, the maximum frame number] or between the play range if specified.
142 void SetCurrentFrameNumber( uint32_t frameNumber );
145 * @brief Retrieves the current frame number of the animation.
146 * @return The current frame number
148 uint32_t GetCurrentFrameNumber() const;
151 * @brief Retrieves the total frame number of the animation.
152 * @return The total frame number
154 uint32_t GetTotalFrameNumber() const;
157 * @brief Gets the default size of the file,.
158 * @return The default size of the file
160 void GetDefaultSize( uint32_t& width, uint32_t& height ) const;
163 * @brief Sets the stop behavior of the animation. This is performed when the animation is stopped.
164 * @param[in] stopBehavior The stop behavior
166 void SetStopBehavior( DevelImageVisual::StopBehavior::Type stopBehavior );
169 * @brief Sets the looping mode.
170 * Animation plays forwards and then restarts from the beginning or runs backwards again.
171 * @param[in] loopingMode The looping mode
173 void SetLoopingMode( DevelImageVisual::LoopingMode::Type loopingMode );
176 * @brief Gets the layer information of all the child layers.
177 * @param[out] map The layer information
179 void GetLayerInfo( Property::Map& map ) const;
182 * @brief Connect to this signal to be notified when the texture upload is completed.
183 * @return The signal to connect to.
185 UploadCompletedSignalType& UploadCompletedSignal();
188 * @brief Rasterizes the current frame.
189 * @return true if the animation is running, false otherwise.
194 * @brief Calculates the time for the next frame rasterization.
195 * @return The time for the next frame rasterization.
197 std::chrono::time_point< std::chrono::system_clock > CalculateNextFrameTime( bool renderNow );
200 * @brief Gets the time for the next frame rasterization.
201 * @return The time for the next frame rasterization.
203 std::chrono::time_point< std::chrono::system_clock > GetNextFrameTime();
208 * @brief Initializes the vector renderer.
213 * @brief Gets the frame number when the animation is stopped according to the stop behavior.
215 uint32_t GetStoppedFrame( uint32_t startFrame, uint32_t endFrame, uint32_t currentFrame );
218 VectorAnimationTask( const VectorAnimationTask& task ) = delete;
221 VectorAnimationTask& operator=( const VectorAnimationTask& task ) = delete;
227 STOPPING, ///< The animation is stopping
228 STOPPED, ///< The animation has stopped
229 PLAYING, ///< The animation is playing
230 PAUSED ///< The animation is paused
234 VectorAnimationRenderer mVectorRenderer;
235 VectorAnimationThread& mVectorAnimationThread;
236 ConditionalWait mConditionalWait;
237 std::unique_ptr< EventThreadCallback > mAnimationFinishedTrigger;
239 PlayState mPlayState;
240 DevelImageVisual::StopBehavior::Type mStopBehavior;
241 DevelImageVisual::LoopingMode::Type mLoopingMode;
242 std::chrono::time_point< std::chrono::system_clock > mNextFrameStartTime;
243 int64_t mFrameDurationNanoSeconds;
245 uint32_t mCurrentFrame;
246 uint32_t mTotalFrame;
247 uint32_t mStartFrame;
252 int32_t mCurrentLoop;
254 bool mCurrentFrameUpdated;
255 bool mCurrentLoopUpdated;
257 bool mUpdateFrameNumber;
258 bool mNeedAnimationFinishedTrigger;
262 } // namespace Internal
264 } // namespace Toolkit
268 #endif // DALI_TOOLKIT_VECTOR_ANIMATION_TASK_H