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