6a8ed449ce5e55f2876bada7b0540ef255d65753
[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
64   using ExclusivesContainer = std::vector<Exclusive>;
65
66   /**
67    * Create a RenderTaskList.
68    * @return A newly allocated RenderTaskList; the caller takes ownership.
69    */
70   static RenderTaskListPtr New();
71
72   /**
73    * @copydoc Dali::RenderTaskList::CreateTask()
74    */
75   RenderTaskPtr CreateTask();
76
77   /**
78    * @brief Creates a new RenderTask.
79    *
80    * This will be appended to the list of render-tasks.
81    *
82    * @param[in] sourceActor The actor and its children to be rendered for this render task.
83    * @param[in] cameraActor The actor from which the scene is viewed for this render task.
84    * @return A valid handle to a new RenderTask
85    */
86   RenderTaskPtr CreateTask(Actor* sourceActor, CameraActor* cameraActor);
87
88   /**
89    * @copydoc Dali::RenderTaskList::RemoveTask()
90    */
91   void RemoveTask(Internal::RenderTask& task);
92
93   /**
94    * @copydoc Dali::RenderTaskList::GetTaskCount()
95    */
96   uint32_t GetTaskCount() const;
97
98   /**
99    * @copydoc Dali::RenderTaskList::GetTask()
100    */
101   RenderTaskPtr GetTask(uint32_t index) const;
102
103   /**
104    * Retrieve the container of render-tasks.
105    * @return The container.
106    */
107   RenderTaskContainer& GetTasks()
108   {
109     return mTasks;
110   }
111
112   /**
113    * @brief Mark a rendertask as having exclusive access to its source actor.
114    *
115    * @param[in] task Pointer to the rendertask.
116    * @param[in] exclusive If a rendertask is to have exclusive acesss to its source actor.
117    */
118   void SetExclusive(RenderTask* task, bool exclusive);
119
120   /**
121    * @brief Return the list of rendertasks that exclusively own their source actor.
122    *
123    * @return [description]
124    */
125   const ExclusivesContainer& GetExclusivesList() const
126   {
127     return mExclusives;
128   }
129
130   /**
131    * Provide notification signals for a "Finished" render task.
132    * This method should be called in the event-thread
133    * Queue NotifyFinishedMessage() from update-thread
134    * @param object pointer to this class instance
135    */
136   static void NotifyFinished(void* object);
137
138   /**
139    * This method refreshes all render tasks that have a frame buffer
140    * and a refresh rate of RefreshOnce.
141    */
142   void RecoverFromContextLoss();
143
144   /**
145    * Retrieve the SceneGraph::RenderTaskList object.
146    * @return The RenderTaskList.
147    */
148   const SceneGraph::RenderTaskList& GetSceneObject() const;
149
150 protected:
151   /**
152    * Construct a new RenderTaskList.
153    */
154   RenderTaskList();
155
156   /**
157    * A reference counted object may only be deleted by calling Unreference()
158    */
159   ~RenderTaskList() override;
160
161   /**
162    * 2nd-phase construction
163    */
164   void Initialize();
165
166 private: // from CompleteNotificationInterface
167   /**
168    * @copydoc CompleteNotificationInterface::NotifyCompleted()
169    */
170   void NotifyCompleted() override;
171
172 private:
173   EventThreadServices& mEventThreadServices;
174   RenderTaskDefaults&  mDefaults;
175
176   SceneGraph::RenderTaskList* mSceneObject; ///< Raw-pointer to the scene-graph object; not owned.
177
178   RenderTaskContainer mTasks;      ///< Reference counted render-tasks
179   ExclusivesContainer mExclusives; ///< List of rendertasks with exclusively owned source actors.
180 };
181
182 } // namespace Internal
183
184 // Helpers for public-api forwarding methods
185
186 inline Internal::RenderTaskList& GetImplementation(Dali::RenderTaskList& taskList)
187 {
188   DALI_ASSERT_ALWAYS(taskList && "RenderTaskList handle is empty");
189
190   BaseObject& handle = taskList.GetBaseObject();
191
192   return static_cast<Internal::RenderTaskList&>(handle);
193 }
194
195 inline const Internal::RenderTaskList& GetImplementation(const Dali::RenderTaskList& taskList)
196 {
197   DALI_ASSERT_ALWAYS(taskList && "RenderTaskList handle is empty");
198
199   const BaseObject& handle = taskList.GetBaseObject();
200
201   return static_cast<const Internal::RenderTaskList&>(handle);
202 }
203
204 } // namespace Dali
205
206 #endif // DALI_INTERNAL_RENDER_TASK_LIST_H