DALi Version 2.2.11
[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) 2022 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    * Process the task
69    */
70   void Process() override;
71
72   /**
73    * Whether the task is ready to process.
74    * @return True if the task is ready to process.
75    */
76   bool IsReady() override;
77
78   /**
79    * Do the rasterization with the mRasterizer.
80    * @return Returns True when it's successful. False otherwise.
81    */
82   bool Rasterize();
83
84   /**
85    * Whether the rasterize is completed
86    * @return Returns True when it's completed
87    */
88   bool IsRasterized();
89
90   /**
91    * Get the rasterization result.
92    * @return The texture with the rasterized pixels.
93    */
94   Texture GetRasterizedTexture();
95
96 private:
97   // Undefined
98   CanvasRendererRasterizingTask(const CanvasRendererRasterizingTask& task);
99
100   // Undefined
101   CanvasRendererRasterizingTask& operator=(const CanvasRendererRasterizingTask& task);
102
103 private:
104   CanvasRenderer mCanvasRenderer;
105   bool           mRasterizedSuccessed;
106 };
107
108 } // namespace Internal
109
110 } // namespace Toolkit
111
112 } // namespace Dali
113
114 #endif // DALI_TOOLKIT_CANVAS_VIEW_RASTERIZE_TASK_H