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
52 * @param[in] url The url of the vector animation file
54 VectorRasterizeThread( const std::string& url );
59 virtual ~VectorRasterizeThread();
62 * @brief Sets the renderer used to display the result image.
64 * @param[in] renderer The renderer used to display the result image
66 void SetRenderer( Renderer renderer );
69 * @brief Sets the target image size.
71 * @param[in] width The target image width
72 * @param[in] height The target image height
74 void SetSize( uint32_t width, uint32_t height );
77 * @brief Play the vector animation.
82 * @brief Stop the vector animation.
87 * @brief Pause the vector animation.
89 void PauseAnimation();
92 * @brief Render one frame. The current frame number will be increased.
97 * @brief This callback is called after the first frame is ready.
98 * @param[in] callback The resource ready callback
100 void SetResourceReadyCallback( EventThreadCallback* callback );
103 * @brief This callback is called after the animation is finished.
104 * @param[in] callback The animation finished callback
106 void SetAnimationFinishedCallback( EventThreadCallback* callback );
109 * @brief Enable looping for 'count' repeats. -1 means to repeat forever.
110 * @param[in] count The number of times to loop
112 void SetLoopCount( int32_t count );
115 * @brief Set the playing range in frame number.
116 * @param[in] startFrame The frame number to specify minimum progress.
117 * @param[in] endFrame The frame number to specify maximum progress.
118 * The animation will play between those values.
120 void SetPlayRange( uint32_t startFrame, uint32_t endFrame );
123 * @brief Get the play state
124 * @return The play state
126 DevelImageVisual::PlayState::Type GetPlayState() const;
129 * @brief Queries whether the resource is ready.
130 * @return true if ready, false otherwise
132 bool IsResourceReady() 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 );
174 * @brief The entry function of the worker thread.
175 * It rasterizes the vector image.
182 * @brief Initializes the vector renderer.
187 * @brief Rasterizes the current frame.
192 * @brief Gets the frame number when the animation is stopped according to the stop behavior.
194 uint32_t GetStoppedFrame( uint32_t startFrame, uint32_t endFrame, uint32_t currentFrame );
197 VectorRasterizeThread( const VectorRasterizeThread& thread ) = delete;
200 VectorRasterizeThread& operator=( const VectorRasterizeThread& thread ) = delete;
206 STOPPING, ///< The animation is stopping
207 STOPPED, ///< The animation has stopped
208 PLAYING, ///< The animation is playing
209 PAUSED ///< The animation is paused
213 VectorAnimationRenderer mVectorRenderer;
214 ConditionalWait mConditionalWait;
215 std::unique_ptr< EventThreadCallback > mResourceReadyTrigger;
216 std::unique_ptr< EventThreadCallback > mAnimationFinishedTrigger;
218 PlayState mPlayState;
219 DevelImageVisual::StopBehavior::Type mStopBehavior;
220 DevelImageVisual::LoopingMode::Type mLoopingMode;
221 int64_t mFrameDurationNanoSeconds;
223 uint32_t mCurrentFrame;
224 uint32_t mTotalFrame;
225 uint32_t mStartFrame;
230 int32_t mCurrentLoop;
232 bool mDestroyThread; ///< Whether the thread be destroyed
234 bool mCurrentFrameUpdated;
236 bool mUpdateFrameNumber;
237 const Dali::LogFactoryInterface& mLogFactory; ///< The log factory
241 } // namespace Internal
243 } // namespace Toolkit
247 #endif // DALI_TOOLKIT_VECTOR_IMAGE_RASTERIZE_THREAD_H