84058fcc730b60fb588aedf70694f8f0b0393e4e
[platform/core/uifw/dali-core.git] / dali / internal / update / render-tasks / scene-graph-render-task-list.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDER_TASK_LIST_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_TASK_LIST_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
21 // INTERNAL INCLUDES
22 #include <dali/devel-api/common/owner-container.h>
23 #include <dali/internal/common/message.h>
24 #include <dali/internal/event/common/event-thread-services.h>
25 #include <dali/internal/update/render-tasks/scene-graph-render-task.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 class CompleteNotificationInterface;
32
33 namespace SceneGraph
34 {
35 class RenderMessageDispatcher;
36 class RenderTask;
37
38 /**
39  * An ordered list of render-tasks.
40  */
41 class RenderTaskList
42 {
43 public:
44   using RenderTaskContainer = OwnerContainer<RenderTask*>;
45
46   /**
47    * Construct a new RenderTaskList.
48    * @return A new RenderTaskList
49    */
50   static RenderTaskList* New();
51
52   /**
53    * Destructor
54    */
55   ~RenderTaskList();
56
57   /**
58    * Overriden delete operator
59    * Deletes the RenderTaskList from its global memory pool
60    */
61   void operator delete(void* ptr);
62
63   /**
64    * Set the renderMessageDispatcher to send message.
65    * @param[in] renderMessageDispatcher The renderMessageDispatcher to send messages.
66    */
67   void SetRenderMessageDispatcher(RenderMessageDispatcher* renderMessageDispatcher);
68
69   /**
70    * Add a new RenderTask to the list.
71    * @param[in] newTask The RenderTaskList takes ownership of this task.
72    */
73   void AddTask(OwnerPointer<RenderTask>& newTask);
74
75   /**
76    * Remove a RenderTask from the list.
77    * @param[in] task The RenderTaskList will destroy this task.
78    */
79   void RemoveTask(RenderTask* task);
80
81   /**
82    * Retrieve the count of RenderTasks.
83    * @return The count.
84    */
85   uint32_t GetTaskCount();
86
87   /**
88    * Retrieve the container of RenderTasks.
89    * @return The container.
90    */
91   RenderTaskContainer& GetTasks();
92
93   /**
94    * Retrieve the container of RenderTasks.
95    * @return The container.
96    */
97   const RenderTaskContainer& GetTasks() const;
98
99   /**
100    * Set the notification method to package in the NotifyFinishedMessage
101    * @param object to store in notification managers queue
102    */
103   void SetCompleteNotificationInterface(CompleteNotificationInterface* object);
104
105   /**
106    * Get the Notification interface for when 1+ render tasks have finished
107    */
108   CompleteNotificationInterface* GetCompleteNotificationInterface();
109
110   /**
111    * Get the capacity of the memory pools
112    */
113   static uint32_t GetMemoryPoolCapacity();
114
115 protected:
116   /**
117    * Protected constructor. See New()
118    */
119   RenderTaskList();
120
121 private:
122   // Undefined
123   RenderTaskList(const RenderTaskList&);
124
125   // Undefined
126   RenderTaskList& operator=(const RenderTaskList&);
127
128 private:
129   CompleteNotificationInterface* mNotificationObject;      ///< object to pass in to the complete notification
130   RenderMessageDispatcher*       mRenderMessageDispatcher; ///< for sending messages to render thread
131   RenderTaskContainer            mRenderTasks;             ///< A container of owned RenderTasks
132 };
133
134 // Messages for RenderTaskList
135
136 inline void AddTaskMessage(EventThreadServices& eventThreadServices, const RenderTaskList& list, OwnerPointer<RenderTask>& task)
137 {
138   // Message has ownership of the RenderTask while in transit from event -> update
139   using LocalType = MessageValue1<RenderTaskList, OwnerPointer<RenderTask> >;
140
141   // Reserve some memory inside the message queue
142   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
143
144   // Construct message in the message queue memory; note that delete should not be called on the return value
145   new(slot) LocalType(&list, &RenderTaskList::AddTask, task);
146 }
147
148 inline void RemoveTaskMessage(EventThreadServices& eventThreadServices, const RenderTaskList& list, const RenderTask& constTask)
149 {
150   // Scene graph thread can destroy this object.
151   RenderTask& task = const_cast<RenderTask&>(constTask);
152
153   using LocalType = MessageValue1<RenderTaskList, RenderTask*>;
154
155   // Reserve some memory inside the message queue
156   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
157
158   // Construct message in the message queue memory; note that delete should not be called on the return value
159   new(slot) LocalType(&list, &RenderTaskList::RemoveTask, &task);
160 }
161
162 } // namespace SceneGraph
163
164 } // namespace Internal
165
166 } // namespace Dali
167
168 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_TASK_LIST_H