Cleaning up and optimizing scene-graph-material and scene-graph-renderer
[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) 2015 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
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31 class ResourceManager;
32 class CompleteNotificationInterface;
33
34 namespace SceneGraph
35 {
36 class RenderMessageDispatcher;
37 class RenderTask;
38
39 /**
40  * An ordered list of render-tasks.
41  */
42 class RenderTaskList
43 {
44 public:
45
46   typedef OwnerContainer< RenderTask* > RenderTaskContainer;
47
48   /**
49    * Constructor
50    * @param renderMessageDispatcher to send messages
51    * @param resourceManager to pass to render tasks
52    */
53   RenderTaskList( RenderMessageDispatcher& renderMessageDispatcher, ResourceManager& resourceManager );
54
55   /**
56    * Destructor
57    */
58   ~RenderTaskList();
59
60   /**
61    * Add a new RenderTask to the list.
62    * @param[in] newTask The RenderTaskList takes ownership of this task.
63    */
64   void AddTask( RenderTask* newTask );
65
66   /**
67    * Remove a RenderTask from the list.
68    * @param[in] task The RenderTaskList will destroy this task.
69    */
70   void RemoveTask( RenderTask* task );
71
72   /**
73    * Retrieve the container of RenderTasks.
74    * @return The container.
75    */
76   RenderTaskContainer& GetTasks();
77
78   /**
79    * Retrieve the container of RenderTasks.
80    * @return The container.
81    */
82   const RenderTaskContainer& GetTasks() const;
83
84   /**
85    * Set the notification method to package in the NotifyFinishedMessage
86    * @param object to store in notification managers queue
87    */
88   void SetCompleteNotificationInterface( CompleteNotificationInterface* object );
89
90   /**
91    * Get the Notification interface for when 1+ render tasks have finished
92    */
93   CompleteNotificationInterface* GetCompleteNotificationInterface();
94
95 private:
96
97   // Undefined
98   RenderTaskList(const RenderTaskList&);
99
100   // Undefined
101   RenderTaskList& operator=(const RenderTaskList&);
102
103 private:
104
105   CompleteNotificationInterface* mNotificationObject; ///< object to pass in to the complete notification
106   RenderMessageDispatcher& mRenderMessageDispatcher; ///< for sending messages to render thread
107   ResourceManager& mResourceManager; ///< The resource manager (render tasks need this)
108   RenderTaskContainer mRenderTasks; ///< A container of owned RenderTasks
109
110 };
111
112 // Messages for RenderTaskList
113
114 inline void AddTaskMessage( EventThreadServices& eventThreadServices, RenderTaskList& list, RenderTask& task )
115 {
116   typedef MessageValue1< RenderTaskList, RenderTask* > LocalType;
117
118   // Reserve some memory inside the message queue
119   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
120
121   // Construct message in the message queue memory; note that delete should not be called on the return value
122   new (slot) LocalType( &list, &RenderTaskList::AddTask, &task );
123 }
124
125 inline void RemoveTaskMessage( EventThreadServices& eventThreadServices, RenderTaskList& list, const RenderTask& constTask )
126 {
127   // Scene graph thread can destroy this object.
128   RenderTask& task = const_cast< RenderTask& >( constTask );
129
130   typedef MessageValue1< RenderTaskList, RenderTask* > LocalType;
131
132   // Reserve some memory inside the message queue
133   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
134
135   // Construct message in the message queue memory; note that delete should not be called on the return value
136   new (slot) LocalType( &list, &RenderTaskList::RemoveTask, &task );
137 }
138
139 } // namespace SceneGraph
140
141 } // namespace Internal
142
143 } // namespace Dali
144
145 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_TASK_LIST_H__