Use modern construct 'using' instead of typedef.
[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) 2019 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 class Scene;
42
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   using ShaderQueue   = OwnerContainer<Shader*>;
55   using RendererQueue = OwnerContainer<Renderer*>;
56   using CameraQueue   = OwnerContainer<Camera*>;
57   using SceneQueue    = OwnerContainer<Scene*>;
58
59   /**
60    * Create a new DiscardQueue.
61    * @param[in] renderQueue Used to send GL clean-up messages for the next Render.
62    */
63   DiscardQueue( RenderQueue& renderQueue );
64
65   /**
66    * Non-virtual destructor; DiscardQueue is not suitable as a base class.
67    */
68   ~DiscardQueue();
69
70   /**
71    * Adds an unwanted Node and its children to the discard queue.
72    * If necessary, a message will be sent to clean-up GL resources in the next Render.
73    * @pre This method is not thread-safe, and should only be called from the update-thread.
74    * @param[in] updateBufferIndex The current update buffer index.
75    * @param[in] node The discarded node; DiscardQueue takes ownership.
76    */
77   void Add( BufferIndex updateBufferIndex, Node* node );
78
79   /**
80    * Adds an unwanted shader to the discard queue.
81    * A message will be sent to clean-up GL resources in the next Render.
82    * @pre This method is not thread-safe, and should only be called from the update-thread.
83    * @param[in] bufferIndex The current update buffer index.
84    * @param[in] shader The shader to queue; DiscardQueue takes ownership.
85    */
86   void Add( BufferIndex bufferIndex, Shader* shader );
87
88   /**
89    * Adds an unwanted Renderer to the discard queue.
90    * A message will be sent to clean up GL resources in the next Render.
91    * @param[in] updateBufferIndex The current update buffer index.
92    * @param[in] renderer The discarded renderer; DiscardQueue takes ownership.
93    */
94   void Add( BufferIndex updateBufferIndex, Renderer* renderer );
95
96   /**
97    * Adds an unwanted Camera to the discard queue.
98    * This is done because Render thread may use Matrices from the camera
99    * @param[in] updateBufferIndex The current update buffer index.
100    * @param[in] camera The discarded renderer; DiscardQueue takes ownership.
101    */
102   void Add( BufferIndex updateBufferIndex, Camera* camera );
103
104   /**
105    * Adds an unwanted Scene to the discard queue.
106    * A message will be sent to clean up GL resources in the next Render.
107    * @param[in] updateBufferIndex The current update buffer index.
108    * @param[in] scene The discarded scene; DiscardQueue takes ownership.
109    */
110   void Add( BufferIndex updateBufferIndex, Scene* scene );
111
112   /**
113    * Release the nodes which were queued in the frame N-2.
114    * @pre This method should be called (once) at the beginning of every Update.
115    * @param[in] updateBufferIndex The current update buffer index.
116    */
117   void Clear( BufferIndex updateBufferIndex );
118
119 private:
120
121   // Undefined
122   DiscardQueue( const DiscardQueue& );
123
124   // Undefined
125   DiscardQueue& operator=( const DiscardQueue& rhs );
126
127 private:
128
129   RenderQueue& mRenderQueue; ///< Used to send GL clean-up messages for the next Render.
130
131   // Messages are queued here following the current update buffer number
132   OwnerContainer< Node* >      mNodeQueue[2];
133   ShaderQueue                  mShaderQueue[2];
134   RendererQueue                mRendererQueue[2];
135   CameraQueue                  mCameraQueue[2];
136   SceneQueue                   mSceneQueue[2];
137 };
138
139 } // namespace SceneGraph
140
141 } // namespace Internal
142
143 } // namespace Dali
144
145 #endif // DALI_INTERNAL_DISCARD_QUEUE_H