[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / canvas-view / canvas-view-rasterize-task.h
1 #ifndef DALI_TOOLKIT_CANVAS_VIEW_RASTERIZE_TASK_H
2 #define DALI_TOOLKIT_CANVAS_VIEW_RASTERIZE_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/canvas-renderer/canvas-renderer.h>
22 #include <dali/devel-api/adaptor-framework/event-thread-callback.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/adaptor-framework/log-factory-interface.h>
27 #include <dali/public-api/adaptor-framework/async-task-manager.h>
28 #include <dali/public-api/common/intrusive-ptr.h>
29 #include <dali/public-api/object/ref-object.h>
30 #include <dali/public-api/rendering/texture-set.h>
31 #include <memory>
32 #include <vector>
33
34 namespace Dali
35 {
36 namespace Toolkit
37 {
38 namespace Internal
39 {
40 class CanvasRendererRasterizingTask;
41 using CanvasRendererRasterizingTaskPtr = IntrusivePtr<CanvasRendererRasterizingTask>;
42
43 /**
44  * The canvasview rasterizing tasks to be processed in the worker thread.
45  *
46  * Life cycle of a rasterizing task is as follows:
47  * 1. Created by CanvasView 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 before its turn to be processed, it then been deleted in the worker thread.
51  */
52 class CanvasRendererRasterizingTask : public AsyncTask
53 {
54 public:
55   /**
56    * Constructor
57    * @param[in] canvasRenderer The renderer which the rasterized canvas to be applied.
58    * @param[in] callback The callback that is called when the operation is completed.
59    */
60   CanvasRendererRasterizingTask(CanvasRenderer canvasRenderer, CallbackBase* callback);
61
62   /**
63    * Destructor.
64    */
65   ~CanvasRendererRasterizingTask() = default;
66
67   /**
68    * Do the rasterization with the mRasterizer.
69    * @return Returns True when it's successful. False otherwise.
70    */
71   bool Rasterize();
72
73   /**
74    * Whether the rasterize is completed
75    * @return Returns True when it's completed
76    */
77   bool IsRasterized();
78
79   /**
80    * Get the rasterization result.
81    * @return The texture with the rasterized pixels.
82    */
83   Texture GetRasterizedTexture();
84
85 public: // Implementation of AsyncTask
86   /**
87    * @copydoc Dali::AsyncTask::Process()
88    */
89   void Process() override;
90
91   /**
92    * @copydoc Dali::AsyncTask::IsReady()
93    */
94   bool IsReady() override;
95
96   /**
97    * @copydoc Dali::AsyncTask::GetTaskName()
98    */
99   std::string_view GetTaskName() const override
100   {
101     return "CanvasRendererRasterizingTask";
102   }
103
104 private:
105   // Undefined
106   CanvasRendererRasterizingTask(const CanvasRendererRasterizingTask& task);
107
108   // Undefined
109   CanvasRendererRasterizingTask& operator=(const CanvasRendererRasterizingTask& task);
110
111 private:
112   CanvasRenderer mCanvasRenderer;
113   bool           mRasterizedSuccessed;
114 };
115
116 } // namespace Internal
117
118 } // namespace Toolkit
119
120 } // namespace Dali
121
122 #endif // DALI_TOOLKIT_CANVAS_VIEW_RASTERIZE_TASK_H