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