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 Sets the renderer used to display the result image.
69 * @param[in] renderer The renderer used to display the result image
71 void SetRenderer( Renderer renderer );
74 * @brief Sets the target image size.
76 * @param[in] width The target image width
77 * @param[in] height The target image height
79 void SetSize( uint32_t width, uint32_t height );
82 * @brief Play the vector animation.
87 * @brief Stop the vector animation.
92 * @brief Pause the vector animation.
94 void PauseAnimation();
97 * @brief Render one frame. The current frame number will be increased.
102 * @brief This callback is called after the animation is finished.
103 * @param[in] callback The animation finished callback
105 void SetAnimationFinishedCallback( EventThreadCallback* callback );
108 * @brief Enable looping for 'count' repeats. -1 means to repeat forever.
109 * @param[in] count The number of times to loop
111 void SetLoopCount( int32_t count );
114 * @brief Set the playing range in frame number.
115 * @param[in] startFrame The frame number to specify minimum progress.
116 * @param[in] endFrame The frame number to specify maximum progress.
117 * The animation will play between those values.
119 void SetPlayRange( uint32_t startFrame, uint32_t endFrame );
122 * @brief Gets the playing range in frame number.
123 * @param[out] startFrame The frame number to specify minimum progress.
124 * @param[out] endFrame The frame number to specify maximum progress.
126 void GetPlayRange( uint32_t& startFrame, uint32_t& endFrame );
129 * @brief Get the play state
130 * @return The play state
132 DevelImageVisual::PlayState::Type GetPlayState() const;
135 * @brief Sets the current frame number of the animation.
136 * @param[in] frameNumber The new frame number between [0, the maximum frame number] or between the play range if specified.
138 void SetCurrentFrameNumber( uint32_t frameNumber );
141 * @brief Retrieves the current frame number of the animation.
142 * @return The current frame number
144 uint32_t GetCurrentFrameNumber() const;
147 * @brief Retrieves the total frame number of the animation.
148 * @return The total frame number
150 uint32_t GetTotalFrameNumber() const;
153 * @brief Gets the default size of the file,.
154 * @return The default size of the file
156 void GetDefaultSize( uint32_t& width, uint32_t& height ) const;
159 * @brief Sets the stop behavior of the animation. This is performed when the animation is stopped.
160 * @param[in] stopBehavior The stop behavior
162 void SetStopBehavior( DevelImageVisual::StopBehavior::Type stopBehavior );
165 * @brief Sets the looping mode.
166 * Animation plays forwards and then restarts from the beginning or runs backwards again.
167 * @param[in] loopingMode The looping mode
169 void SetLoopingMode( DevelImageVisual::LoopingMode::Type loopingMode );
172 * @brief Gets the layer information of all the child layers.
173 * @param[out] map The layer information
175 void GetLayerInfo( Property::Map& map ) const;
178 * @brief Connect to this signal to be notified when the texture upload is completed.
179 * @return The signal to connect to.
181 UploadCompletedSignalType& UploadCompletedSignal();
184 * @brief Rasterizes the current frame.
185 * @return true if the animation is running, false otherwise.
190 * @brief Calculates the time for the next frame rasterization.
191 * @return The time for the next frame rasterization.
193 std::chrono::time_point< std::chrono::system_clock > CalculateNextFrameTime( bool renderNow );
196 * @brief Gets the time for the next frame rasterization.
197 * @return The time for the next frame rasterization.
199 std::chrono::time_point< std::chrono::system_clock > GetNextFrameTime();
204 * @brief Initializes the vector renderer.
209 * @brief Gets the frame number when the animation is stopped according to the stop behavior.
211 uint32_t GetStoppedFrame( uint32_t startFrame, uint32_t endFrame, uint32_t currentFrame );
214 VectorAnimationTask( const VectorAnimationTask& task ) = delete;
217 VectorAnimationTask& operator=( const VectorAnimationTask& task ) = delete;
223 STOPPING, ///< The animation is stopping
224 STOPPED, ///< The animation has stopped
225 PLAYING, ///< The animation is playing
226 PAUSED ///< The animation is paused
230 VectorAnimationRenderer mVectorRenderer;
231 VectorAnimationThread& mVectorAnimationThread;
232 ConditionalWait mConditionalWait;
233 std::unique_ptr< EventThreadCallback > mAnimationFinishedTrigger;
235 PlayState mPlayState;
236 DevelImageVisual::StopBehavior::Type mStopBehavior;
237 DevelImageVisual::LoopingMode::Type mLoopingMode;
238 std::chrono::time_point< std::chrono::system_clock > mNextFrameStartTime;
239 int64_t mFrameDurationNanoSeconds;
241 uint32_t mCurrentFrame;
242 uint32_t mTotalFrame;
243 uint32_t mStartFrame;
248 int32_t mCurrentLoop;
250 bool mCurrentFrameUpdated;
251 bool mCurrentLoopUpdated;
253 bool mUpdateFrameNumber;
254 bool mNeedAnimationFinishedTrigger;
258 } // namespace Internal
260 } // namespace Toolkit
264 #endif // DALI_TOOLKIT_VECTOR_ANIMATION_TASK_H