1 #ifndef DALI_TOOLKIT_SVG_TASK_H
2 #define DALI_TOOLKIT_SVG_TASK_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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 <dali/public-api/adaptor-framework/encoded-image-buffer.h>
29 #include <dali-toolkit/internal/visuals/visual-url.h>
30 #include <dali/public-api/adaptor-framework/async-task-manager.h>
39 typedef IntrusivePtr<SvgVisual> SvgVisualPtr;
41 typedef IntrusivePtr<SvgTask> SvgTaskPtr;
44 * The svg rasterizing tasks to be processed in the worker thread.
46 * Life cycle of a rasterizing task is as follows:
47 * 1. Created by SvgVisual in the main thread
48 * 2. Queued in the worked thread waiting to be processed.
49 * 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
50 * 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.
52 class SvgTask : public AsyncTask
57 * @param[in] vectorRenderer The vector rasterizer.
58 * @param[in] callback The callback that is called when the operation is completed.
59 * @param[in] priorityType The priority of this task.
61 SvgTask(VectorImageRenderer vectorRenderer, CallbackBase* callback, AsyncTask::PriorityType priorityType = AsyncTask::PriorityType::DEFAULT);
66 virtual ~SvgTask() = default;
71 virtual void Process() = 0;
74 * Whether the task is ready to process.
75 * @return True if the task is ready to process.
77 virtual bool IsReady() = 0;
80 * Whether the task has succeeded.
81 * @return True if the task has succeeded.
83 bool HasSucceeded() const;
86 * @brief Get the task's imageRenderer
87 * @return VectorImageRenderer
89 VectorImageRenderer GetRenderer();
92 * Get the rasterization result.
93 * @return The pixel data with the rasterized pixels.
95 virtual PixelData GetPixelData() const;
99 SvgTask(const SvgTask& task) = delete;
102 SvgTask& operator=(const SvgTask& task) = delete;
105 VectorImageRenderer mVectorRenderer;
109 class SvgLoadingTask : public SvgTask
114 * @param[in] vectorRenderer The vector rasterizer.
115 * @param[in] url The URL to svg resource to use.
116 * @param[in] encodedImageBuffer The resource buffer if required.
117 * @param[in] dpi The DPI of the screen.
118 * @param[in] callback The callback that is called when the operation is completed.
120 SvgLoadingTask(VectorImageRenderer vectorRenderer, const VisualUrl& url, EncodedImageBuffer encodedImageBuffer, float dpi, CallbackBase* callback);
125 ~SvgLoadingTask() override;
130 void Process() override;
133 * Whether the task is ready to process.
134 * @return True if the task is ready to process.
136 bool IsReady() override;
140 SvgLoadingTask(const SvgLoadingTask& task) = delete;
143 SvgLoadingTask& operator=(const SvgLoadingTask& task) = delete;
147 EncodedImageBuffer mEncodedImageBuffer;
151 class SvgRasterizingTask : public SvgTask
156 * @param[in] vectorRenderer The vector rasterizer.
157 * @param[in] width The rasterization width.
158 * @param[in] height The rasterization height.
159 * @param[in] callback The callback that is called when the operation is completed.
161 SvgRasterizingTask(VectorImageRenderer vectorRenderer, uint32_t width, uint32_t height, CallbackBase* callback);
166 ~SvgRasterizingTask() override;
169 * Process the task accodring to the type
171 void Process() override;
174 * Whether the task is ready to process.
175 * @return True if the task is ready to process.
177 bool IsReady() override;
180 * Get the rasterization result.
181 * @return The pixel data with the rasterized pixels.
183 PixelData GetPixelData() const override;
187 * Set the url of rasterizatoin visual. Only for tracing
188 * @param[in] url The url of this visual
190 void SetUrl(VisualUrl url)
192 mImageUrl = std::move(url);
198 SvgRasterizingTask(const SvgRasterizingTask& task) = delete;
201 SvgRasterizingTask& operator=(const SvgRasterizingTask& task) = delete;
205 VisualUrl mImageUrl{};
207 PixelData mPixelData;
212 } // namespace Internal
214 } // namespace Toolkit
218 #endif // DALI_TOOLKIT_SVG_TASK_H