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