Remove invalid calls to EnableVisual from Button
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-vector-image / vector-image-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 Play the vector animation
62    */
63   void StartAnimation();
64
65   /**
66    * @brief Stop the vector animation
67    */
68   void StopAnimation();
69
70   /**
71    * @brief Pause the vector animation
72    */
73   void PauseAnimation();
74
75   /**
76    * @brief Resume the vector animation
77    */
78   void ResumeAnimation();
79
80   /**
81    * @brief Render one frame. The current frame number will be increased.
82    */
83   void RenderFrame();
84
85   /**
86    * @brief This callback is called after the first frame is ready.
87    * @param callback The resource ready callback
88    */
89   void SetResourceReadyCallback( EventThreadCallback* callback );
90
91 protected:
92
93   /**
94    * @brief The entry function of the worker thread.
95    *        It rasterizes the vector image.
96    */
97   void Run() override;
98
99 private:
100
101   /**
102    * @brief Called by the rasterize thread which ensures a wait if required.
103    * @return false if the thread should stop.
104    */
105   bool IsThreadReady();
106
107   /**
108    * @brief Start rendering
109    */
110   bool StartRender();
111
112   /**
113    * @brief Rasterize the current frame.
114    */
115   void Rasterize();
116
117   // Undefined
118   VectorRasterizeThread( const VectorRasterizeThread& thread ) = delete;
119
120   // Undefined
121   VectorRasterizeThread& operator=( const VectorRasterizeThread& thread ) = delete;
122
123 private:
124
125   std::string                mUrl;
126   VectorAnimationRenderer    mVectorRenderer;
127   ConditionalWait            mConditionalWait;
128   Dali::Mutex                mMutex;
129   EventThreadCallback*       mResourceReadyTrigger;
130   uint32_t                   mCurrentFrame;
131   uint32_t                   mTotalFrame;
132   uint32_t                   mWidth;
133   uint32_t                   mHeight;
134   bool                       mNeedRender;
135   bool                       mPlaying;
136   bool                       mPaused;
137   bool                       mDestroyThread;  ///< Whether the thread be destroyed
138   bool                       mResourceReady;
139   const Dali::LogFactoryInterface& mLogFactory; ///< The log factory
140
141 };
142
143 } // namespace Internal
144
145 } // namespace Toolkit
146
147 } // namespace Dali
148
149 #endif // DALI_TOOLKIT_VECTOR_IMAGE_RASTERIZE_THREAD_H