Merge "Enum properties added for the text effects style." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-vector-image / vector-rasterize-thread.h
1 #ifndef DALI_TOOLKIT_VECTOR_IMAGE_RASTERIZE_THREAD_H
2 #define DALI_TOOLKIT_VECTOR_IMAGE_RASTERIZE_THREAD_H
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 // EXTERNAL INCLUDES
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>
27 #include <string>
28 #include <memory>
29
30 // INTERNAL INCLUDES
31 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
32
33 namespace Dali
34 {
35
36 namespace Toolkit
37 {
38
39 namespace Internal
40 {
41
42 /**
43  * The worker thread for vector image rasterization.
44  */
45 class VectorRasterizeThread : public Thread
46 {
47 public:
48
49   /**
50    * @brief Constructor.
51    *
52    * @param[in] url The url of the vector animation file
53    * @param[in] renderer The renderer used to render the image
54    * @param[in] width The width of the content
55    * @param[in] height The height of the content
56    */
57   VectorRasterizeThread( const std::string& url, Renderer renderer, uint32_t width, uint32_t height );
58
59   /**
60    * @brief Destructor.
61    */
62   virtual ~VectorRasterizeThread();
63
64   /**
65    * @brief Sets the target image size.
66    *
67    * @param[in] width The target image width
68    * @param[in] height The target image height
69    */
70   void SetSize( uint32_t width, uint32_t height );
71
72   /**
73    * @brief Play the vector animation.
74    */
75   void StartAnimation();
76
77   /**
78    * @brief Stop the vector animation.
79    */
80   void StopAnimation();
81
82   /**
83    * @brief Pause the vector animation.
84    */
85   void PauseAnimation();
86
87   /**
88    * @brief Render one frame. The current frame number will be increased.
89    */
90   void RenderFrame();
91
92   /**
93    * @brief This callback is called after the first frame is ready.
94    * @param[in] callback The resource ready callback
95    */
96   void SetResourceReadyCallback( EventThreadCallback* callback );
97
98   /**
99    * @brief This callback is called after the animation is finished.
100    * @param[in] callback The animation finished callback
101    */
102   void SetAnimationFinishedCallback( EventThreadCallback* callback );
103
104   /**
105    * @brief Enable looping for 'count' repeats. -1 means to repeat forever.
106    * @param[in] count The number of times to loop
107    */
108   void SetLoopCount( int16_t count );
109
110   /**
111    * @brief Set the playing range.
112    * @param[in] range Two values between [0,1] to specify minimum and maximum progress.
113    * The animation will play between those values.
114    */
115   void SetPlayRange( Vector2 range );
116
117   /**
118    * @brief Get the play state
119    * @return The play state
120    */
121   DevelImageVisual::PlayState GetPlayState();
122
123 protected:
124
125   /**
126    * @brief The entry function of the worker thread.
127    *        It rasterizes the vector image.
128    */
129   void Run() override;
130
131 private:
132
133   /**
134    * @brief Called by the rasterize thread which ensures a wait if required.
135    * @return false if the thread should stop.
136    */
137   bool IsThreadReady();
138
139   /**
140    * @brief Start rendering
141    */
142   bool StartRender();
143
144   /**
145    * @brief Rasterize the current frame.
146    */
147   void Rasterize();
148
149   // Undefined
150   VectorRasterizeThread( const VectorRasterizeThread& thread ) = delete;
151
152   // Undefined
153   VectorRasterizeThread& operator=( const VectorRasterizeThread& thread ) = delete;
154
155 private:
156
157   std::string                 mUrl;
158   VectorAnimationRenderer     mVectorRenderer;
159   ConditionalWait             mConditionalWait;
160   Dali::Mutex                 mMutex;
161   std::unique_ptr< EventThreadCallback > mResourceReadyTrigger;
162   std::unique_ptr< EventThreadCallback > mAnimationFinishedTrigger;
163   Vector2                     mPlayRange;
164   DevelImageVisual::PlayState mPlayState;
165   uint32_t                    mCurrentFrame;
166   uint32_t                    mTotalFrame;
167   uint32_t                    mStartFrame;
168   uint32_t                    mEndFrame;
169   uint32_t                    mWidth;
170   uint32_t                    mHeight;
171   int16_t                     mLoopCount;
172   int16_t                     mCurrentLoop;
173   bool                        mNeedRender;
174   bool                        mDestroyThread;  ///< Whether the thread be destroyed
175   bool                        mResourceReady;
176   const Dali::LogFactoryInterface& mLogFactory; ///< The log factory
177
178 };
179
180 } // namespace Internal
181
182 } // namespace Toolkit
183
184 } // namespace Dali
185
186 #endif // DALI_TOOLKIT_VECTOR_IMAGE_RASTERIZE_THREAD_H