1 #ifndef DALI_TOOLKIT_VECTOR_IMAGE_RASTERIZE_THREAD_H
2 #define DALI_TOOLKIT_VECTOR_IMAGE_RASTERIZE_THREAD_H
5 * Copyright (c) 2018 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>
24 #include <dali/devel-api/threading/mutex.h>
25 #include <dali/devel-api/threading/thread.h>
26 #include <dali/integration-api/adaptors/log-factory-interface.h>
31 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
43 * The worker thread for vector image rasterization.
45 class VectorRasterizeThread : public Thread
49 using UploadCompletedSignalType = Dali::VectorAnimationRenderer::UploadCompletedSignalType;
54 * @param[in] url The url of the vector animation file
56 VectorRasterizeThread( const std::string& url );
61 virtual ~VectorRasterizeThread();
64 * @brief Sets the renderer used to display the result image.
66 * @param[in] renderer The renderer used to display the result image
68 void SetRenderer( Renderer renderer );
71 * @brief Sets the target image size.
73 * @param[in] width The target image width
74 * @param[in] height The target image height
76 void SetSize( uint32_t width, uint32_t height );
79 * @brief Play the vector animation.
84 * @brief Stop the vector animation.
89 * @brief Pause the vector animation.
91 void PauseAnimation();
94 * @brief Render one frame. The current frame number will be increased.
99 * @brief This callback is called after the animation is finished.
100 * @param[in] callback The animation finished callback
102 void SetAnimationFinishedCallback( EventThreadCallback* callback );
105 * @brief Enable looping for 'count' repeats. -1 means to repeat forever.
106 * @param[in] count The number of times to loop
108 void SetLoopCount( int32_t count );
111 * @brief Set the playing range in frame number.
112 * @param[in] startFrame The frame number to specify minimum progress.
113 * @param[in] endFrame The frame number to specify maximum progress.
114 * The animation will play between those values.
116 void SetPlayRange( uint32_t startFrame, uint32_t endFrame );
119 * @brief Get the play state
120 * @return The play state
122 DevelImageVisual::PlayState::Type GetPlayState() const;
125 * @brief Queries whether the resource is ready.
126 * @return true if ready, false otherwise
128 bool IsResourceReady() const;
131 * @brief Sets the current frame number of the animation.
132 * @param[in] frameNumber The new frame number between [0, the maximum frame number] or between the play range if specified.
134 void SetCurrentFrameNumber( uint32_t frameNumber );
137 * @brief Retrieves the current frame number of the animation.
138 * @return The current frame number
140 uint32_t GetCurrentFrameNumber() const;
143 * @brief Retrieves the total frame number of the animation.
144 * @return The total frame number
146 uint32_t GetTotalFrameNumber() const;
149 * @brief Gets the default size of the file,.
150 * @return The default size of the file
152 void GetDefaultSize( uint32_t& width, uint32_t& height ) const;
155 * @brief Sets the stop behavior of the animation. This is performed when the animation is stopped.
156 * @param[in] stopBehavior The stop behavior
158 void SetStopBehavior( DevelImageVisual::StopBehavior::Type stopBehavior );
161 * @brief Sets the looping mode.
162 * Animation plays forwards and then restarts from the beginning or runs backwards again.
163 * @param[in] loopingMode The looping mode
165 void SetLoopingMode( DevelImageVisual::LoopingMode::Type loopingMode );
168 * @brief Connect to this signal to be notified when the texture upload is completed.
169 * @return The signal to connect to.
171 UploadCompletedSignalType& UploadCompletedSignal();
176 * @brief The entry function of the worker thread.
177 * It rasterizes the vector image.
184 * @brief Initializes the vector renderer.
189 * @brief Rasterizes the current frame.
194 * @brief Gets the frame number when the animation is stopped according to the stop behavior.
196 uint32_t GetStoppedFrame( uint32_t startFrame, uint32_t endFrame, uint32_t currentFrame );
199 VectorRasterizeThread( const VectorRasterizeThread& thread ) = delete;
202 VectorRasterizeThread& operator=( const VectorRasterizeThread& thread ) = delete;
208 STOPPING, ///< The animation is stopping
209 STOPPED, ///< The animation has stopped
210 PLAYING, ///< The animation is playing
211 PAUSED ///< The animation is paused
215 VectorAnimationRenderer mVectorRenderer;
216 ConditionalWait mConditionalWait;
217 std::unique_ptr< EventThreadCallback > mAnimationFinishedTrigger;
219 PlayState mPlayState;
220 DevelImageVisual::StopBehavior::Type mStopBehavior;
221 DevelImageVisual::LoopingMode::Type mLoopingMode;
222 int64_t mFrameDurationNanoSeconds;
224 uint32_t mCurrentFrame;
225 uint32_t mTotalFrame;
226 uint32_t mStartFrame;
231 int32_t mCurrentLoop;
233 bool mDestroyThread; ///< Whether the thread be destroyed
235 bool mCurrentFrameUpdated;
236 bool mCurrentLoopUpdated;
238 bool mUpdateFrameNumber;
239 bool mNeedAnimationFinishedTrigger;
240 const Dali::LogFactoryInterface& mLogFactory; ///< The log factory
244 } // namespace Internal
246 } // namespace Toolkit
250 #endif // DALI_TOOLKIT_VECTOR_IMAGE_RASTERIZE_THREAD_H