[dali_1.0.47] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / update / common / discard-queue.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/update/common/discard-queue.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/render/gl-resources/gl-resource-owner.h>
23 #include <dali/internal/common/message.h>
24 #include <dali/internal/update/nodes/node.h>
25 #include <dali/internal/render/queue/render-queue.h>
26 #include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
27 #include <dali/internal/render/renderers/scene-graph-renderer.h>
28 #include <dali/internal/render/shaders/scene-graph-shader.h>
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 namespace SceneGraph
37 {
38
39 DiscardQueue::DiscardQueue( RenderQueue& renderQueue )
40 : mRenderQueue( renderQueue )
41 {
42 }
43
44 DiscardQueue::~DiscardQueue()
45 {
46 }
47
48 void DiscardQueue::Add( BufferIndex updateBufferIndex, Node* node )
49 {
50   DALI_ASSERT_DEBUG( NULL != node );
51
52   // The GL resources will now be freed in frame N
53   // The Update for frame N+1 may occur in parallel with the rendering of frame N
54   // Queue the node for destruction in frame N+2
55   if ( 0u == updateBufferIndex )
56   {
57     mNodeQueue0.PushBack( node );
58   }
59   else
60   {
61     mNodeQueue1.PushBack( node );
62   }
63 }
64
65 void DiscardQueue::Add( BufferIndex updateBufferIndex, NodeAttachment* attachment )
66 {
67   DALI_ASSERT_DEBUG( NULL != attachment );
68
69   // The GL resources will now be freed in Render frame N
70   // The Update for frame N+1 may occur in parallel with the rendering of frame N
71   // Queue the attachment for destruction in Update frame N+2
72   if ( 0u == updateBufferIndex )
73   {
74     mAttachmentQueue0.PushBack( attachment );
75   }
76   else
77   {
78     mAttachmentQueue1.PushBack( attachment );
79   }
80 }
81
82 void DiscardQueue::Add( BufferIndex updateBufferIndex, Geometry* geometry )
83 {
84   DALI_ASSERT_DEBUG( NULL != geometry );
85
86   // The GL resources will now be freed in frame N
87   // The Update for frame N+1 may occur in parallel with the rendering of frame N
88   // Queue the node for destruction in frame N+2
89   if ( 0u == updateBufferIndex )
90   {
91     mGeometryQueue0.PushBack( geometry );
92   }
93   else
94   {
95     mGeometryQueue1.PushBack( geometry );
96   }
97 }
98
99 void DiscardQueue::Add( BufferIndex updateBufferIndex, Material* material )
100 {
101   DALI_ASSERT_DEBUG( NULL != material );
102
103   // The GL resources will now be freed in frame N
104   // The Update for frame N+1 may occur in parallel with the rendering of frame N
105   // Queue the node for destruction in frame N+2
106   if ( 0u == updateBufferIndex )
107   {
108     mMaterialQueue0.PushBack( material );
109   }
110   else
111   {
112     mMaterialQueue1.PushBack( material );
113   }
114 }
115
116
117 void DiscardQueue::Add( BufferIndex updateBufferIndex, Shader* shader )
118 {
119   DALI_ASSERT_DEBUG( NULL != shader );
120
121   // Programs are cached for the lifetime of DALi so no need for GL cleanup for shader for now.
122
123   // The GL resources will now be freed in frame N
124   // The Update for frame N+1 may occur in parallel with the rendering of frame N
125   // Queue the node for destruction in frame N+2
126   if ( 0u == updateBufferIndex )
127   {
128     mShaderQueue0.PushBack( shader );
129   }
130   else
131   {
132     mShaderQueue1.PushBack( shader );
133   }
134 }
135
136 void DiscardQueue::Add( BufferIndex updateBufferIndex, Sampler* sampler )
137 {
138   DALI_ASSERT_DEBUG( NULL != sampler );
139
140   if ( 0u == updateBufferIndex )
141   {
142     mSamplerQueue0.PushBack( sampler );
143   }
144   else
145   {
146     mSamplerQueue1.PushBack( sampler );
147   }
148 }
149
150 void DiscardQueue::Add( BufferIndex updateBufferIndex, PropertyBuffer* propertyBuffer )
151 {
152   DALI_ASSERT_DEBUG( NULL != propertyBuffer );
153
154   if ( 0u == updateBufferIndex )
155   {
156     mPropertyBufferQueue0.PushBack( propertyBuffer );
157   }
158   else
159   {
160     mPropertyBufferQueue1.PushBack( propertyBuffer );
161   }
162 }
163
164 void DiscardQueue::Clear( BufferIndex updateBufferIndex )
165 {
166   // Destroy some discarded objects; these should no longer own any GL resources
167
168   if ( 0u == updateBufferIndex )
169   {
170     mNodeQueue0.Clear();
171     mAttachmentQueue0.Clear();
172     mShaderQueue0.Clear();
173     mGeometryQueue0.Clear();
174     mMaterialQueue0.Clear();
175     mSamplerQueue0.Clear();
176     mPropertyBufferQueue0.Clear();
177   }
178   else
179   {
180     mNodeQueue1.Clear();
181     mAttachmentQueue1.Clear();
182     mShaderQueue1.Clear();
183     mGeometryQueue1.Clear();
184     mMaterialQueue1.Clear();
185     mSamplerQueue1.Clear();
186     mPropertyBufferQueue1.Clear();
187   }
188 }
189
190 } // namespace SceneGraph
191
192 } // namespace Internal
193
194 } // namespace Dali