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>
28 #include <dali-toolkit/internal/visuals/visual-url.h>
29 #include <dali/public-api/adaptor-framework/async-task-manager.h>
38 typedef IntrusivePtr<SvgVisual> SvgVisualPtr;
40 typedef IntrusivePtr<SvgTask> SvgTaskPtr;
43 * The svg rasterizing tasks to be processed in the worker thread.
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.
51 class SvgTask : public AsyncTask
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.
60 SvgTask(VectorImageRenderer vectorRenderer, CallbackBase* callback, AsyncTask::PriorityType priorityType = AsyncTask::PriorityType::DEFAULT);
65 virtual ~SvgTask() = default;
70 virtual void Process() = 0;
73 * Whether the task is ready to process.
74 * @return True if the task is ready to process.
76 virtual bool IsReady() = 0;
79 * Whether the task has succeeded.
80 * @return True if the task has succeeded.
82 bool HasSucceeded() const;
85 * @brief Get the task's imageRenderer
86 * @return VectorImageRenderer
88 VectorImageRenderer GetRenderer();
91 * Get the rasterization result.
92 * @return The pixel data with the rasterized pixels.
94 virtual PixelData GetPixelData() const;
98 SvgTask(const SvgTask& task) = delete;
101 SvgTask& operator=(const SvgTask& task) = delete;
104 VectorImageRenderer mVectorRenderer;
108 class SvgLoadingTask : public SvgTask
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.
118 SvgLoadingTask(VectorImageRenderer vectorRenderer, const VisualUrl& url, float dpi, CallbackBase* callback);
123 ~SvgLoadingTask() override;
128 void Process() override;
131 * Whether the task is ready to process.
132 * @return True if the task is ready to process.
134 bool IsReady() override;
138 SvgLoadingTask(const SvgLoadingTask& task) = delete;
141 SvgLoadingTask& operator=(const SvgLoadingTask& task) = delete;
148 class SvgRasterizingTask : public SvgTask
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.
158 SvgRasterizingTask(VectorImageRenderer vectorRenderer, uint32_t width, uint32_t height, CallbackBase* callback);
163 ~SvgRasterizingTask() override;
166 * Process the task accodring to the type
168 void Process() override;
171 * Whether the task is ready to process.
172 * @return True if the task is ready to process.
174 bool IsReady() override;
177 * Get the rasterization result.
178 * @return The pixel data with the rasterized pixels.
180 PixelData GetPixelData() const override;
184 * Set the url of rasterizatoin visual. Only for tracing
185 * @param[in] url The url of this visual
187 void SetUrl(VisualUrl url)
189 mImageUrl = std::move(url);
195 SvgRasterizingTask(const SvgRasterizingTask& task) = delete;
198 SvgRasterizingTask& operator=(const SvgRasterizingTask& task) = delete;
202 VisualUrl mImageUrl{};
204 PixelData mPixelData;
209 } // namespace Internal
211 } // namespace Toolkit
215 #endif // DALI_TOOLKIT_SVG_TASK_H