Add Overlay Layer in scene
[platform/core/uifw/dali-core.git] / dali / internal / event / render-tasks / render-task-list-impl.h
1 #ifndef DALI_INTERNAL_RENDER_TASK_LIST_H
2 #define DALI_INTERNAL_RENDER_TASK_LIST_H
3
4 /*
5  * Copyright (c) 2021 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/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/render-tasks/render-task-list.h>
25
26 #include <dali/internal/event/common/complete-notification-interface.h>
27 #include <dali/internal/event/events/actor-observer.h>
28 #include <dali/internal/event/render-tasks/render-task-impl.h>
29
30 namespace Dali
31 {
32 namespace Internal
33 {
34 class EventThreadServices;
35 class RenderTaskDefaults;
36 class Actor;
37 class CameraActor;
38
39 using RenderTaskPtr = IntrusivePtr<RenderTask>;
40 class RenderTaskList;
41 using RenderTaskListPtr = IntrusivePtr<RenderTaskList>;
42
43 namespace SceneGraph
44 {
45 class RenderTaskList;
46 class UpdateManager;
47 } // namespace SceneGraph
48
49 /**
50  * A proxy for the scene-graph RenderTaskList.
51  * A separate LayerList is maintained for actors added via the SystemLevel::Add().
52  */
53 class RenderTaskList : public BaseObject, public CompleteNotificationInterface
54 {
55 public:
56   using RenderTaskContainer = std::vector<RenderTaskPtr>;
57
58   struct Exclusive
59   {
60     RenderTask*   renderTaskPtr; ///< Pointer for comparison with current rendertask.
61     ActorObserver actor;         ///< For comparison with current actor.
62
63     bool operator==(const Exclusive& other) const
64     {
65       return renderTaskPtr == other.renderTaskPtr;
66     }
67   };
68
69   using ExclusivesContainer = std::vector<Exclusive>;
70   using ExclusiveIter       = ExclusivesContainer::iterator;
71
72   /**
73    * Create a RenderTaskList.
74    * @return A newly allocated RenderTaskList; the caller takes ownership.
75    */
76   static RenderTaskListPtr New();
77
78   /**
79    * @copydoc Dali::RenderTaskList::CreateTask()
80    */
81   RenderTaskPtr CreateTask();
82
83   /**
84    * @brief Creates a new RenderTask.
85    *
86    * This will be appended to the list of render-tasks.
87    *
88    * @param[in] sourceActor The actor and its children to be rendered for this render task.
89    * @param[in] cameraActor The actor from which the scene is viewed for this render task.
90    * @return A valid handle to a new RenderTask
91    */
92   RenderTaskPtr CreateTask(Actor* sourceActor, CameraActor* cameraActor);
93
94   /**
95    * @brief Creates a new RenderTask for overlay.
96    * This will be appended to the end of render-task list.
97    * @param[in] sourceActor The actor and its children to be rendered for this render task.
98    * @param[in] cameraActor The actor from which the scene is viewed for this render task.
99    * @return A valid handle to a new overlay RenderTask
100    * @note The Overlay RenderTask will be rendered after all the other render tasks are rendered.
101    */
102   RenderTaskPtr CreateOverlayTask(Actor* sourceActor, CameraActor* cameraActor);
103
104   /**
105    * @copydoc Dali::RenderTaskList::RemoveTask()
106    */
107   void RemoveTask(Internal::RenderTask& task);
108
109   /**
110    * @copydoc Dali::RenderTaskList::GetTaskCount()
111    */
112   uint32_t GetTaskCount() const;
113
114   /**
115    * @copydoc Dali::RenderTaskList::GetTask()
116    */
117   RenderTaskPtr GetTask(uint32_t index) const;
118
119   /**
120    * @copydoc Dali::RenderTaskList::GetOverlayTask()
121    */
122   RenderTaskPtr GetOverlayTask() const;
123
124   /**
125    * Retrieve the container of render-tasks.
126    * @return The container.
127    */
128   RenderTaskContainer& GetTasks()
129   {
130     return mTasks;
131   }
132
133   /**
134    * @brief Mark a rendertask as having exclusive access to its source actor.
135    *
136    * @param[in] task Pointer to the rendertask.
137    * @param[in] exclusive If a rendertask is to have exclusive acesss to its source actor.
138    */
139   void SetExclusive(RenderTask* task, bool exclusive);
140
141   /**
142    * @brief Return the list of rendertasks that exclusively own their source actor.
143    *
144    * @return [description]
145    */
146   const ExclusivesContainer& GetExclusivesList() const
147   {
148     return mExclusives;
149   }
150
151   /**
152    * Provide notification signals for a "Finished" render task.
153    * This method should be called in the event-thread
154    * Queue NotifyFinishedMessage() from update-thread
155    * @param object pointer to this class instance
156    */
157   static void NotifyFinished(void* object);
158
159   /**
160    * This method refreshes all render tasks that have a frame buffer
161    * and a refresh rate of RefreshOnce.
162    */
163   void RecoverFromContextLoss();
164
165   /**
166    * Retrieve the SceneGraph::RenderTaskList object.
167    * @return The RenderTaskList.
168    */
169   const SceneGraph::RenderTaskList& GetSceneObject() const;
170
171 protected:
172   /**
173    * Construct a new RenderTaskList.
174    */
175   RenderTaskList();
176
177   /**
178    * A reference counted object may only be deleted by calling Unreference()
179    */
180   ~RenderTaskList() override;
181
182   /**
183    * 2nd-phase construction
184    */
185   void Initialize();
186
187 private: // from CompleteNotificationInterface
188   /**
189    * @copydoc CompleteNotificationInterface::NotifyCompleted()
190    */
191   void NotifyCompleted() override;
192
193 private:
194   EventThreadServices& mEventThreadServices;
195   RenderTaskDefaults&  mDefaults;
196
197   SceneGraph::RenderTaskList* mSceneObject; ///< Raw-pointer to the scene-graph object; not owned.
198
199   RenderTaskContainer mTasks;      ///< Reference counted render-tasks
200   ExclusivesContainer mExclusives; ///< List of rendertasks with exclusively owned source actors.
201   RenderTaskPtr       mOverlayRenderTask{nullptr};
202 };
203
204 } // namespace Internal
205
206 // Helpers for public-api forwarding methods
207
208 inline Internal::RenderTaskList& GetImplementation(Dali::RenderTaskList& taskList)
209 {
210   DALI_ASSERT_ALWAYS(taskList && "RenderTaskList handle is empty");
211
212   BaseObject& handle = taskList.GetBaseObject();
213
214   return static_cast<Internal::RenderTaskList&>(handle);
215 }
216
217 inline const Internal::RenderTaskList& GetImplementation(const Dali::RenderTaskList& taskList)
218 {
219   DALI_ASSERT_ALWAYS(taskList && "RenderTaskList handle is empty");
220
221   const BaseObject& handle = taskList.GetBaseObject();
222
223   return static_cast<const Internal::RenderTaskList&>(handle);
224 }
225
226 } // namespace Dali
227
228 #endif // DALI_INTERNAL_RENDER_TASK_LIST_H