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