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