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>
30 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
42 * The worker thread for vector image rasterization.
44 class VectorRasterizeThread : public Thread
51 * @param[in] url The url of the vector animation file
53 VectorRasterizeThread( const std::string& url );
58 virtual ~VectorRasterizeThread();
61 * @brief Sets the renderer used to display the result image.
63 * @param[in] renderer The renderer used to display the result image
65 void SetRenderer( Renderer renderer );
68 * @brief Sets the target image size.
70 * @param[in] width The target image width
71 * @param[in] height The target image height
73 void SetSize( uint32_t width, uint32_t height );
76 * @brief Play the vector animation.
81 * @brief Stop the vector animation.
86 * @brief Pause the vector animation.
88 void PauseAnimation();
91 * @brief Render one frame. The current frame number will be increased.
96 * @brief This callback is called after the first frame is ready.
97 * @param[in] callback The resource ready callback
99 void SetResourceReadyCallback( EventThreadCallback* callback );
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 Gets the loop count. -1 means to repeat forever.
115 * @return The number of times to loop
117 int32_t GetLoopCount() const;
120 * @brief Set the playing range.
121 * @param[in] range Two values between [0,1] to specify minimum and maximum progress.
122 * The animation will play between those values.
124 void SetPlayRange( Vector2 range );
127 * @brief Gets the playing range.
128 * @return The play range defined for the animation
130 Vector2 GetPlayRange() const;
133 * @brief Get the play state
134 * @return The play state
136 DevelImageVisual::PlayState GetPlayState() const;
139 * @brief Queries whether the resource is ready.
140 * @return true if ready, false otherwise
142 bool IsResourceReady() const;
147 * @brief The entry function of the worker thread.
148 * It rasterizes the vector image.
155 * @brief Called by the rasterize thread which ensures a wait if required.
156 * @return false if the thread should stop.
158 bool IsThreadReady();
161 * @brief Start rendering
166 * @brief Rasterize the current frame.
171 VectorRasterizeThread( const VectorRasterizeThread& thread ) = delete;
174 VectorRasterizeThread& operator=( const VectorRasterizeThread& thread ) = delete;
179 VectorAnimationRenderer mVectorRenderer;
180 ConditionalWait mConditionalWait;
182 EventThreadCallback* mResourceReadyTrigger;
183 EventThreadCallback* mAnimationFinishedTrigger;
185 DevelImageVisual::PlayState mPlayState;
187 uint32_t mCurrentFrame;
188 uint32_t mTotalFrame;
189 uint32_t mStartFrame;
194 int32_t mCurrentLoop;
196 bool mDestroyThread; ///< Whether the thread be destroyed
198 const Dali::LogFactoryInterface& mLogFactory; ///< The log factory
202 } // namespace Internal
204 } // namespace Toolkit
208 #endif // DALI_TOOLKIT_VECTOR_IMAGE_RASTERIZE_THREAD_H