1 #ifndef DALI_TOOLKIT_SVG_TASK_H
2 #define DALI_TOOLKIT_SVG_TASK_H
5 * Copyright (c) 2022 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.
59 SvgTask(VectorImageRenderer vectorRenderer, CallbackBase* callback);
64 virtual ~SvgTask() = default;
69 virtual void Process() = 0;
72 * Whether the task is ready to process.
73 * @return True if the task is ready to process.
75 virtual bool IsReady() = 0;
78 * Whether the task has succeeded.
79 * @return True if the task has succeeded.
81 bool HasSucceeded() const;
84 * @brief Get the task's imageRenderer
85 * @return VectorImageRenderer
87 VectorImageRenderer GetRenderer();
90 * Get the rasterization result.
91 * @return The pixel data with the rasterized pixels.
93 virtual PixelData GetPixelData() const;
97 SvgTask(const SvgTask& task) = delete;
100 SvgTask& operator=(const SvgTask& task) = delete;
103 VectorImageRenderer mVectorRenderer;
107 class SvgLoadingTask : public SvgTask
112 * @param[in] vectorRenderer The vector rasterizer.
113 * @param[in] url The URL to svg resource to use.
114 * @param[in] dpi The DPI of the screen.
115 * @param[in] callback The callback that is called when the operation is completed.
117 SvgLoadingTask(VectorImageRenderer vectorRenderer, const VisualUrl& url, float dpi, CallbackBase* callback);
122 ~SvgLoadingTask() override;
127 void Process() override;
130 * Whether the task is ready to process.
131 * @return True if the task is ready to process.
133 bool IsReady() override;
137 SvgLoadingTask(const SvgLoadingTask& task) = delete;
140 SvgLoadingTask& operator=(const SvgLoadingTask& task) = delete;
147 class SvgRasterizingTask : public SvgTask
152 * @param[in] vectorRenderer The vector rasterizer.
153 * @param[in] width The rasterization width.
154 * @param[in] height The rasterization height.
155 * @param[in] callback The callback that is called when the operation is completed.
157 SvgRasterizingTask(VectorImageRenderer vectorRenderer, uint32_t width, uint32_t height, CallbackBase* callback);
162 ~SvgRasterizingTask() override;
165 * Process the task accodring to the type
167 void Process() override;
170 * Whether the task is ready to process.
171 * @return True if the task is ready to process.
173 bool IsReady() override;
176 * Get the rasterization result.
177 * @return The pixel data with the rasterized pixels.
179 PixelData GetPixelData() const override;
183 SvgRasterizingTask(const SvgRasterizingTask& task) = delete;
186 SvgRasterizingTask& operator=(const SvgRasterizingTask& task) = delete;
189 PixelData mPixelData;
194 } // namespace Internal
196 } // namespace Toolkit
200 #endif // DALI_TOOLKIT_SVG_TASK_H