1 #ifndef __DALI_INTERNAL_DISCARD_QUEUE_H__
2 #define __DALI_INTERNAL_DISCARD_QUEUE_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
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.
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;
68 * Create a new DiscardQueue.
69 * @param[in] renderQueue Used to send GL clean-up messages for the next Render.
71 DiscardQueue( RenderQueue& renderQueue );
74 * Non-virtual destructor; DiscardQueue is not suitable as a base class.
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.
85 void Add( BufferIndex updateBufferIndex, Node* node );
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.
94 void Add( BufferIndex updateBufferIndex, NodeAttachment* attachment );
97 * Adds an unwanted geometry to the discard queue.
98 * A message will be sent to clean up GL resources in the next Render
100 void Add( BufferIndex updateBufferIndex, Geometry* geometry );
103 * Adds an unwanted material to the discard queue.
104 * A message will be sent to clean up GL resources in the next Render.
106 void Add( BufferIndex updateBufferIndex, PropertyBuffer* material );
109 * Adds an unwanted material to the discard queue.
110 * A message will be sent to clean up GL resources in the next Render.
112 void Add( BufferIndex updateBufferIndex, Material* material );
115 * Adds an unwanted material to the discard queue.
116 * A message will be sent to clean up GL resources in the next Render.
118 void Add( BufferIndex updateBufferIndex, Sampler* material );
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.
127 void Add( BufferIndex bufferIndex, Shader* shader );
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.
135 void Add( BufferIndex updateBufferIndex, Renderer* renderer );
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.
142 void Clear( BufferIndex updateBufferIndex );
147 DiscardQueue( const DiscardQueue& );
150 DiscardQueue& operator=( const DiscardQueue& rhs );
154 RenderQueue& mRenderQueue; ///< Used to send GL clean-up messages for the next Render.
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;
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;
177 } // namespace SceneGraph
179 } // namespace Internal
183 #endif // __DALI_INTERNAL_RESOURCE_DISCARD_QUEUE_H__