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