removed some dead code
[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/shader.h>
29 #include <dali/internal/update/modeling/scene-graph-mesh.h>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 namespace SceneGraph
38 {
39
40 namespace // unnamed namespace
41 {
42
43 static void DoGlCleanup( BufferIndex updateBufferIndex, GlResourceOwner& owner, RenderQueue& renderQueue )
44 {
45   typedef Message< GlResourceOwner > DerivedType;
46
47   // Reserve some memory inside the render queue
48   unsigned int* slot = renderQueue.ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
49
50   // Construct message in the render queue memory; note that delete should not be called on the return value
51   new (slot) DerivedType( &owner, &GlResourceOwner::GlCleanup );
52 }
53
54 } // unnamed namespace
55
56 DiscardQueue::DiscardQueue( RenderQueue& renderQueue )
57 : mRenderQueue( renderQueue )
58 {
59 }
60
61 DiscardQueue::~DiscardQueue()
62 {
63 }
64
65 void DiscardQueue::Add( BufferIndex updateBufferIndex, Node* node )
66 {
67   DALI_ASSERT_DEBUG( NULL != node );
68
69   // The GL resources will now be freed in frame N
70   // The Update for frame N+1 may occur in parallel with the rendering of frame N
71   // Queue the node for destruction in frame N+2
72   if ( 0u == updateBufferIndex )
73   {
74     mNodeQueue0.PushBack( node );
75   }
76   else
77   {
78     mNodeQueue1.PushBack( node );
79   }
80 }
81
82 void DiscardQueue::Add( BufferIndex updateBufferIndex, NodeAttachment* attachment )
83 {
84   DALI_ASSERT_DEBUG( NULL != attachment );
85
86   // The GL resources will now be freed in Render frame N
87   // The Update for frame N+1 may occur in parallel with the rendering of frame N
88   // Queue the attachment for destruction in Update frame N+2
89   if ( 0u == updateBufferIndex )
90   {
91     mAttachmentQueue0.PushBack( attachment );
92   }
93   else
94   {
95     mAttachmentQueue1.PushBack( attachment );
96   }
97 }
98
99 void DiscardQueue::Add( BufferIndex updateBufferIndex, Mesh* mesh )
100 {
101   DALI_ASSERT_DEBUG( mesh );
102
103   // Send message to clean-up GL resources in the next Render
104   DoGlCleanup( updateBufferIndex, *mesh, mRenderQueue );
105
106   // The GL resources will now be freed in frame N
107   // The Update for frame N+1 may occur in parallel with the rendering of frame N
108   // Queue the node for destruction in frame N+2
109   if ( 0u == updateBufferIndex )
110   {
111     mMeshQueue0.PushBack( mesh );
112   }
113   else
114   {
115     mMeshQueue1.PushBack( mesh );
116   }
117 }
118
119 void DiscardQueue::Add( BufferIndex updateBufferIndex, Shader* shader )
120 {
121   DALI_ASSERT_DEBUG( NULL != shader );
122
123   // Programs are cached for the lifetime of DALi so no need for GL cleanup for shader for now.
124
125   // The GL resources will now be freed in frame N
126   // The Update for frame N+1 may occur in parallel with the rendering of frame N
127   // Queue the node for destruction in frame N+2
128   if ( 0u == updateBufferIndex )
129   {
130     mShaderQueue0.PushBack( shader );
131   }
132   else
133   {
134     mShaderQueue1.PushBack( shader );
135   }
136 }
137
138 void DiscardQueue::Clear( BufferIndex updateBufferIndex )
139 {
140   // Destroy some discarded objects; these should no longer own any GL resources
141
142   if ( 0u == updateBufferIndex )
143   {
144     mNodeQueue0.Clear();
145     mAttachmentQueue0.Clear();
146     mMeshQueue0.Clear();
147     mShaderQueue0.Clear();
148   }
149   else
150   {
151     mNodeQueue1.Clear();
152     mAttachmentQueue1.Clear();
153     mMeshQueue1.Clear();
154     mShaderQueue1.Clear();
155   }
156 }
157
158 } // namespace SceneGraph
159
160 } // namespace Internal
161
162 } // namespace Dali