Make dirtyrect use map container instead of vector
[platform/core/uifw/dali-core.git] / dali / internal / update / common / scene-graph-scene.cpp
1 /*
2  * Copyright (c) 2022 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 // CLASS HEADER
18 #include <dali/internal/update/common/scene-graph-scene.h>
19
20 // INTERNAL INCLUDES
21 #include <dali/integration-api/core-enumerations.h>
22 #include <dali/internal/update/render-tasks/scene-graph-render-task-list.h>
23
24 namespace Dali
25 {
26 namespace Internal
27 {
28 namespace SceneGraph
29 {
30 Scene::Scene()
31 : mFrameRenderedCallbacks(),
32   mFramePresentedCallbacks(),
33   mSkipRendering(false),
34   mSurfaceRect(),
35   mSurfaceOrientation(0),
36   mScreenOrientation(0),
37   mSurfaceRectChanged(false),
38   mRotationCompletedAcknowledgement(false)
39 {
40 }
41
42 Scene::~Scene()
43 {
44   mFrameRenderedCallbacks.clear();
45   mFramePresentedCallbacks.clear();
46 }
47
48 void Scene::Initialize(Graphics::Controller& graphicsController, Integration::DepthBufferAvailable depthBufferAvailable, Integration::StencilBufferAvailable stencilBufferAvailable)
49 {
50   mGraphicsController = &graphicsController;
51
52   // Create the render target for the surface. It should already have been sent via message.
53   mRenderTarget = graphicsController.CreateRenderTarget(mRenderTargetCreateInfo, std::move(mRenderTarget));
54
55   // Create the render pass for the surface
56   std::vector<Graphics::AttachmentDescription> attachmentDescriptions;
57
58   // Default behaviour for color attachments is to CLEAR and STORE
59   mClearValues.clear();
60   mClearValues.emplace_back();
61
62   // Assume single color attachment
63   Graphics::AttachmentDescription desc{};
64   desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
65   desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
66   attachmentDescriptions.push_back(desc);
67
68   if(depthBufferAvailable == Integration::DepthBufferAvailable::TRUE ||
69      stencilBufferAvailable == Integration::StencilBufferAvailable::TRUE)
70   {
71     // Depth
72     desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
73     desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
74
75     // Stencil
76     desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::CLEAR);
77     desc.SetStencilStoreOp(Graphics::AttachmentStoreOp::STORE);
78     attachmentDescriptions.push_back(desc);
79
80     mClearValues.emplace_back();
81     mClearValues.back().depthStencil.depth   = 0;
82     mClearValues.back().depthStencil.stencil = 0;
83   }
84
85   Graphics::RenderPassCreateInfo rpInfo{};
86   rpInfo.SetAttachments(attachmentDescriptions);
87
88   // Add default render pass (loadOp = clear)
89   mRenderPass = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
90
91   desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
92   attachmentDescriptions[0] = desc;
93   if(attachmentDescriptions.size() > 1)
94   {
95     desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
96     desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::LOAD);
97     attachmentDescriptions.back() = desc;
98   }
99
100   mRenderPassNoClear = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
101 }
102
103 RenderInstructionContainer& Scene::GetRenderInstructions()
104 {
105   return mInstructions;
106 }
107
108 void Scene::AddFrameRenderedCallback(CallbackBase* callback, int32_t frameId)
109 {
110   mFrameRenderedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
111 }
112
113 void Scene::AddFramePresentedCallback(CallbackBase* callback, int32_t frameId)
114 {
115   mFramePresentedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
116 }
117
118 void Scene::GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
119 {
120   // Transfer owership of the callbacks
121   for(auto&& iter : mFrameRenderedCallbacks)
122   {
123     callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
124   }
125
126   mFrameRenderedCallbacks.clear();
127 }
128
129 void Scene::GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
130 {
131   // Transfer owership of the callbacks
132   for(auto&& iter : mFramePresentedCallbacks)
133   {
134     callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
135   }
136
137   mFramePresentedCallbacks.clear();
138 }
139
140 void Scene::SetSkipRendering(bool skip)
141 {
142   mSkipRendering = skip;
143 }
144
145 bool Scene::IsRenderingSkipped() const
146 {
147   return mSkipRendering;
148 }
149
150 void Scene::SetSurfaceRect(const Rect<int32_t>& rect)
151 {
152   mSurfaceRect        = rect;
153   mSurfaceRectChanged = true;
154
155   DALI_LOG_RELEASE_INFO("update surfce rect in scene-graph, width[%d], height[%d]\n", mSurfaceRect.width, mSurfaceRect.height);
156
157   if(mRoot)
158   {
159     mRoot->SetUpdated(true);
160   }
161 }
162
163 const Rect<int32_t>& Scene::GetSurfaceRect() const
164 {
165   return mSurfaceRect;
166 }
167
168 bool Scene::IsSurfaceRectChanged()
169 {
170   bool surfaceRectChanged = mSurfaceRectChanged;
171   mSurfaceRectChanged     = false;
172
173   return surfaceRectChanged;
174 }
175
176 void Scene::SetSurfaceOrientations(int32_t windowOrientation, int32_t screenOrienation)
177 {
178   mSurfaceOrientation = windowOrientation;
179   mScreenOrientation  = screenOrienation;
180
181   if(mRoot)
182   {
183     mRoot->SetUpdated(true);
184   }
185
186   DALI_LOG_RELEASE_INFO("update orientation in scene-graph, surface [%d], screen[%d]\n", mSurfaceOrientation, mScreenOrientation);
187 }
188
189 int32_t Scene::GetSurfaceOrientation() const
190 {
191   return mSurfaceOrientation;
192 }
193
194 int32_t Scene::GetScreenOrientation() const
195 {
196   return mScreenOrientation;
197 }
198
199 void Scene::SetRotationCompletedAcknowledgement()
200 {
201   mRotationCompletedAcknowledgement = true;
202 }
203
204 bool Scene::IsRotationCompletedAcknowledgementSet()
205 {
206   bool setRotationCompletedAcknowledgement = mRotationCompletedAcknowledgement;
207   mRotationCompletedAcknowledgement        = false;
208   return setRotationCompletedAcknowledgement;
209 }
210
211 Scene::ItemsDirtyRectsContainer& Scene::GetItemsDirtyRects()
212 {
213   return mItemsDirtyRects;
214 }
215
216 void Scene::SetSurfaceRenderTargetCreateInfo(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo)
217 {
218   if(mRenderTarget != nullptr &&
219      mRenderTargetCreateInfo.surface != renderTargetCreateInfo.surface)
220   {
221     // Only recreate if the surface has changed.
222     mRenderTargetCreateInfo = renderTargetCreateInfo;
223     if(mGraphicsController) // shouldn't be null, as we can't have already set mRenderTarget unless graphics controller exists.
224     {
225       mRenderTarget = mGraphicsController->CreateRenderTarget(renderTargetCreateInfo, std::move(mRenderTarget));
226     }
227   }
228   else
229   {
230     // 2nd Stage initialization happens in RenderManager, not UpdateManager, so is delayed.
231     mRenderTargetCreateInfo = renderTargetCreateInfo;
232   }
233 }
234
235 } // namespace SceneGraph
236
237 } // namespace Internal
238
239 } // namespace Dali