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