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