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