Allow multiple renderers per Actor and sharing renderers between actors
[platform/core/uifw/dali-core.git] / dali / internal / update / common / discard-queue.h
1 #ifndef __DALI_INTERNAL_DISCARD_QUEUE_H__
2 #define __DALI_INTERNAL_DISCARD_QUEUE_H__
3
4 /*
5  * Copyright (c) 2014 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/object/ref-object.h>
23 #include <dali/internal/common/buffer-index.h>
24 #include <dali/internal/common/owner-container.h>
25 #include <dali/internal/update/nodes/node-declarations.h>
26 #include <dali/internal/update/node-attachments/node-attachment-declarations.h>
27 #include <dali/internal/update/common/scene-graph-property-buffer.h>
28 #include <dali/internal/update/rendering/scene-graph-geometry.h>
29 #include <dali/internal/update/rendering/scene-graph-material.h>
30 #include <dali/internal/update/rendering/scene-graph-sampler.h>
31 #include <dali/internal/update/rendering/scene-graph-renderer.h>
32
33 namespace Dali
34 {
35
36 namespace Internal
37 {
38
39 class Texture;
40
41 namespace SceneGraph
42 {
43
44 class Node;
45 class RenderQueue;
46 class Shader;
47
48
49 /**
50  * DiscardQueue is used to cleanup nodes & resources when no longer in use.
51  * Unwanted objects are added here during UpdateManager::Update().
52  * When added, messages will be sent to clean-up GL resources in the next Render.
53  * The Update for frame N+1 may occur in parallel with the rendering of frame N.
54  * Therefore objects queued for destruction in frame N, are destroyed frame N+2.
55  */
56 class DiscardQueue
57 {
58 public:
59
60   typedef OwnerContainer< Shader* > ShaderQueue;
61   typedef OwnerContainer< Geometry* > GeometryQueue;
62   typedef OwnerContainer< Material* > MaterialQueue;
63   typedef OwnerContainer< Sampler* > SamplerQueue;
64   typedef OwnerContainer< PropertyBuffer* > PropertyBufferQueue;
65   typedef OwnerContainer< Renderer* > RendererQueue;
66
67   /**
68    * Create a new DiscardQueue.
69    * @param[in] renderQueue Used to send GL clean-up messages for the next Render.
70    */
71   DiscardQueue( RenderQueue& renderQueue );
72
73   /**
74    * Non-virtual destructor; DiscardQueue is not suitable as a base class.
75    */
76   ~DiscardQueue();
77
78   /**
79    * Adds an unwanted Node and its children to the discard queue.
80    * If necessary, a message will be sent to clean-up GL resources in the next Render.
81    * @pre This method is not thread-safe, and should only be called from the update-thread.
82    * @param[in] updateBufferIndex The current update buffer index.
83    * @param[in] node The discarded node; DiscardQueue takes ownership.
84    */
85   void Add( BufferIndex updateBufferIndex, Node* node );
86
87   /**
88    * Adds an unwanted NodeAttachment to the discard queue.
89    * If necessary, a message will be sent to clean-up GL resources in the next Render.
90    * @pre This method is not thread-safe, and should only be called from the update-thread.
91    * @param[in] updateBufferIndex The current update buffer index.
92    * @param[in] attachment The discarded attachment; DiscardQueue takes ownership.
93    */
94   void Add( BufferIndex updateBufferIndex, NodeAttachment* attachment );
95
96   /**
97    * Adds an unwanted geometry to the discard queue.
98    * A message will be sent to clean up GL resources in the next Render
99    */
100   void Add( BufferIndex updateBufferIndex, Geometry* geometry );
101
102   /**
103    * Adds an unwanted material to the discard queue.
104    * A message will be sent to clean up GL resources in the next Render.
105    */
106   void Add( BufferIndex updateBufferIndex, PropertyBuffer* material );
107
108   /**
109    * Adds an unwanted material to the discard queue.
110    * A message will be sent to clean up GL resources in the next Render.
111    */
112   void Add( BufferIndex updateBufferIndex, Material* material );
113
114   /**
115    * Adds an unwanted material to the discard queue.
116    * A message will be sent to clean up GL resources in the next Render.
117    */
118   void Add( BufferIndex updateBufferIndex, Sampler* material );
119
120   /**
121    * Adds an unwanted shader to the discard queue.
122    * A message will be sent to clean-up GL resources in the next Render.
123    * @pre This method is not thread-safe, and should only be called from the update-thread.
124    * @param[in] bufferIndex The current update buffer index.
125    * @param[in] shader The shader to queue; DiscardQueue takes ownership.
126    */
127   void Add( BufferIndex bufferIndex, Shader* shader );
128
129   /**
130    * Adds an unwanted Renderer to the discard queue.
131    * A message will be sent to clean up GL resources in the next Render.
132    * @param[in] updateBufferIndex The current update buffer index.
133    * @param[in] renderer The discarded renderer; DiscardQueue takes ownership.
134    */
135   void Add( BufferIndex updateBufferIndex, Renderer* renderer );
136
137   /**
138    * Release the nodes which were queued in the frame N-2.
139    * @pre This method should be called (once) at the beginning of every Update.
140    * @param[in] updateBufferIndex The current update buffer index.
141    */
142   void Clear( BufferIndex updateBufferIndex );
143
144 private:
145
146   // Undefined
147   DiscardQueue( const DiscardQueue& );
148
149   // Undefined
150   DiscardQueue& operator=( const DiscardQueue& rhs );
151
152 private:
153
154   RenderQueue& mRenderQueue; ///< Used to send GL clean-up messages for the next Render.
155
156   // Messages are queued here when the update buffer index == 0
157   NodeOwnerContainer           mNodeQueue0;
158   NodeAttachmentOwnerContainer mAttachmentQueue0;
159   ShaderQueue                  mShaderQueue0;
160   GeometryQueue                mGeometryQueue0;
161   MaterialQueue                mMaterialQueue0;
162   SamplerQueue                 mSamplerQueue0;
163   PropertyBufferQueue          mPropertyBufferQueue0;
164   RendererQueue                mRendererQueue0;
165
166   // Messages are queued here when the update buffer index == 1
167   NodeOwnerContainer           mNodeQueue1;
168   NodeAttachmentOwnerContainer mAttachmentQueue1;
169   ShaderQueue                  mShaderQueue1;
170   GeometryQueue                mGeometryQueue1;
171   MaterialQueue                mMaterialQueue1;
172   SamplerQueue                 mSamplerQueue1;
173   PropertyBufferQueue          mPropertyBufferQueue1;
174   RendererQueue                mRendererQueue1;
175 };
176
177 } // namespace SceneGraph
178
179 } // namespace Internal
180
181 } // namespace Dali
182
183 #endif // __DALI_INTERNAL_RESOURCE_DISCARD_QUEUE_H__