Merge "bug fixed about the rtl markup behavior." 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
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 /**
39  * The worker thread for vector image rasterization.
40  */
41 class VectorRasterizeThread : public Thread
42 {
43 public:
44
45   /**
46    * @brief Constructor.
47    *
48    * @param[in] url The url of the vector animation file
49    * @param[in] renderer The renderer used to render the image
50    * @param[in] width The width of the content
51    * @param[in] height The height of the content
52    */
53   VectorRasterizeThread( const std::string& url, Renderer renderer, uint32_t width, uint32_t height );
54
55   /**
56    * @brief Destructor.
57    */
58   virtual ~VectorRasterizeThread();
59
60   /**
61    * @brief Sets the target image size.
62    *
63    * @param[in] width The target image width
64    * @param[in] height The target image height
65    */
66   void SetSize( uint32_t width, uint32_t height );
67
68   /**
69    * @brief Play the vector animation.
70    */
71   void StartAnimation();
72
73   /**
74    * @brief Stop the vector animation.
75    */
76   void StopAnimation();
77
78   /**
79    * @brief Pause the vector animation.
80    */
81   void PauseAnimation();
82
83   /**
84    * @brief Resume the vector animation.
85    */
86   void ResumeAnimation();
87
88   /**
89    * @brief Render one frame. The current frame number will be increased.
90    */
91   void RenderFrame();
92
93   /**
94    * @brief This callback is called after the first frame is ready.
95    * @param[in] callback The resource ready callback
96    */
97   void SetResourceReadyCallback( EventThreadCallback* callback );
98
99   /**
100    * @brief Enable looping for 'count' repeats. -1 means to repeat forever.
101    * @param[in] count The number of times to loop
102    */
103   void SetLoopCount( int16_t count );
104
105   /**
106    * @brief Set the playing range.
107    * @param[in] range Two values between [0,1] to specify minimum and maximum progress.
108    * The animation will play between those values.
109    */
110   void SetPlayRange( Vector2 range );
111
112 protected:
113
114   /**
115    * @brief The entry function of the worker thread.
116    *        It rasterizes the vector image.
117    */
118   void Run() override;
119
120 private:
121
122   /**
123    * @brief Called by the rasterize thread which ensures a wait if required.
124    * @return false if the thread should stop.
125    */
126   bool IsThreadReady();
127
128   /**
129    * @brief Start rendering
130    */
131   bool StartRender();
132
133   /**
134    * @brief Rasterize the current frame.
135    */
136   void Rasterize();
137
138   // Undefined
139   VectorRasterizeThread( const VectorRasterizeThread& thread ) = delete;
140
141   // Undefined
142   VectorRasterizeThread& operator=( const VectorRasterizeThread& thread ) = delete;
143
144 private:
145
146   std::string                mUrl;
147   VectorAnimationRenderer    mVectorRenderer;
148   ConditionalWait            mConditionalWait;
149   Dali::Mutex                mMutex;
150   EventThreadCallback*       mResourceReadyTrigger;
151   Vector2                    mPlayRange;
152   uint32_t                   mCurrentFrame;
153   uint32_t                   mTotalFrame;
154   uint32_t                   mStartFrame;
155   uint32_t                   mEndFrame;
156   uint32_t                   mWidth;
157   uint32_t                   mHeight;
158   int16_t                    mLoopCount;
159   int16_t                    mCurrentLoop;
160   bool                       mNeedRender;
161   bool                       mPlaying;
162   bool                       mPaused;
163   bool                       mDestroyThread;  ///< Whether the thread be destroyed
164   bool                       mResourceReady;
165   const Dali::LogFactoryInterface& mLogFactory; ///< The log factory
166
167 };
168
169 } // namespace Internal
170
171 } // namespace Toolkit
172
173 } // namespace Dali
174
175 #endif // DALI_TOOLKIT_VECTOR_IMAGE_RASTERIZE_THREAD_H