Add some more logs for images
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / svg / svg-task.h
1 #ifndef DALI_TOOLKIT_SVG_TASK_H
2 #define DALI_TOOLKIT_SVG_TASK_H
3
4 /*
5  * Copyright (c) 2023 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/vector-image-renderer.h>
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/images/pixel-data.h>
25 #include <memory>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/internal/visuals/visual-url.h>
29 #include <dali/public-api/adaptor-framework/async-task-manager.h>
30
31 namespace Dali
32 {
33 namespace Toolkit
34 {
35 namespace Internal
36 {
37 class SvgVisual;
38 typedef IntrusivePtr<SvgVisual> SvgVisualPtr;
39 class SvgTask;
40 typedef IntrusivePtr<SvgTask> SvgTaskPtr;
41
42 /**
43  * The svg rasterizing tasks to be processed in the worker thread.
44  *
45  * Life cycle of a rasterizing task is as follows:
46  * 1. Created by SvgVisual in the main thread
47  * 2. Queued in the worked thread waiting to be processed.
48  * 3. If this task gets its turn to do the rasterization, it triggers main thread to apply the rasterized image to material then been deleted in main thread call back
49  *    Or if this task is been removed ( new image/size set to the visual or actor off stage) before its turn to be processed, it then been deleted in the worker thread.
50  */
51 class SvgTask : public AsyncTask
52 {
53 public:
54   /**
55    * Constructor
56    * @param[in] vectorRenderer The vector rasterizer.
57    * @param[in] callback The callback that is called when the operation is completed.
58    * @param[in] priorityType The priority of this task.
59    */
60   SvgTask(VectorImageRenderer vectorRenderer, CallbackBase* callback, AsyncTask::PriorityType priorityType = AsyncTask::PriorityType::DEFAULT);
61
62   /**
63    * Destructor.
64    */
65   virtual ~SvgTask() = default;
66
67   /**
68    * Process the task
69    */
70   virtual void Process() = 0;
71
72   /**
73    * Whether the task is ready to process.
74    * @return True if the task is ready to process.
75    */
76   virtual bool IsReady() = 0;
77
78   /**
79    * Whether the task has succeeded.
80    * @return True if the task has succeeded.
81    */
82   bool HasSucceeded() const;
83
84   /**
85    * @brief Get the task's imageRenderer
86    * @return VectorImageRenderer
87    */
88   VectorImageRenderer GetRenderer();
89
90   /**
91    * Get the rasterization result.
92    * @return The pixel data with the rasterized pixels.
93    */
94   virtual PixelData GetPixelData() const;
95
96 private:
97   // Undefined
98   SvgTask(const SvgTask& task) = delete;
99
100   // Undefined
101   SvgTask& operator=(const SvgTask& task) = delete;
102
103 protected:
104   VectorImageRenderer mVectorRenderer;
105   bool                mHasSucceeded;
106 };
107
108 class SvgLoadingTask : public SvgTask
109 {
110 public:
111   /**
112    * Constructor
113    * @param[in] vectorRenderer The vector rasterizer.
114    * @param[in] url The URL to svg resource to use.
115    * @param[in] dpi The DPI of the screen.
116    * @param[in] callback The callback that is called when the operation is completed.
117    */
118   SvgLoadingTask(VectorImageRenderer vectorRenderer, const VisualUrl& url, float dpi, CallbackBase* callback);
119
120   /**
121    * Destructor.
122    */
123   ~SvgLoadingTask() override;
124
125   /**
126    * Process the task
127    */
128   void Process() override;
129
130   /**
131    * Whether the task is ready to process.
132    * @return True if the task is ready to process.
133    */
134   bool IsReady() override;
135
136 private:
137   // Undefined
138   SvgLoadingTask(const SvgLoadingTask& task) = delete;
139
140   // Undefined
141   SvgLoadingTask& operator=(const SvgLoadingTask& task) = delete;
142
143 private:
144   VisualUrl mImageUrl;
145   float     mDpi;
146 };
147
148 class SvgRasterizingTask : public SvgTask
149 {
150 public:
151   /**
152    * Constructor
153    * @param[in] vectorRenderer The vector rasterizer.
154    * @param[in] width The rasterization width.
155    * @param[in] height The rasterization height.
156    * @param[in] callback The callback that is called when the operation is completed.
157    */
158   SvgRasterizingTask(VectorImageRenderer vectorRenderer, uint32_t width, uint32_t height, CallbackBase* callback);
159
160   /**
161    * Destructor.
162    */
163   ~SvgRasterizingTask() override;
164
165   /**
166    * Process the task accodring to the type
167    */
168   void Process() override;
169
170   /**
171    * Whether the task is ready to process.
172    * @return True if the task is ready to process.
173    */
174   bool IsReady() override;
175
176   /**
177    * Get the rasterization result.
178    * @return The pixel data with the rasterized pixels.
179    */
180   PixelData GetPixelData() const override;
181
182 #ifdef TRACE_ENABLED
183   /**
184    * Set the url of rasterizatoin visual. Only for tracing
185    * @param[in] url The url of this visual
186    */
187   void SetUrl(VisualUrl url)
188   {
189     mImageUrl = std::move(url);
190   }
191 #endif
192
193 private:
194   // Undefined
195   SvgRasterizingTask(const SvgRasterizingTask& task) = delete;
196
197   // Undefined
198   SvgRasterizingTask& operator=(const SvgRasterizingTask& task) = delete;
199
200 private:
201 #ifdef TRACE_ENABLED
202   VisualUrl mImageUrl{};
203 #endif
204   PixelData mPixelData;
205   uint32_t  mWidth;
206   uint32_t  mHeight;
207 };
208
209 } // namespace Internal
210
211 } // namespace Toolkit
212
213 } // namespace Dali
214
215 #endif // DALI_TOOLKIT_SVG_TASK_H