[Tizen](Partial Update) Fix window rotation issue
[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   mSurfaceRectChanged(false),
37   mRotationCompletedAcknowledgement(false)
38 {
39 }
40
41 Scene::~Scene()
42 {
43   mFrameRenderedCallbacks.clear();
44   mFramePresentedCallbacks.clear();
45 }
46
47 void Scene::Initialize(Graphics::Controller& graphicsController, Integration::DepthBufferAvailable depthBufferAvailable, Integration::StencilBufferAvailable stencilBufferAvailable)
48 {
49   // Create the render pass for the surface
50   std::vector<Graphics::AttachmentDescription> attachmentDescriptions;
51
52   // Default behaviour for color attachments is to CLEAR and STORE
53   mClearValues.clear();
54   mClearValues.emplace_back();
55
56   // Assume single color attachment
57   Graphics::AttachmentDescription desc{};
58   desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
59   desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
60   attachmentDescriptions.push_back(desc);
61
62   if(depthBufferAvailable == Integration::DepthBufferAvailable::TRUE ||
63      stencilBufferAvailable == Integration::StencilBufferAvailable::TRUE)
64   {
65     // Depth
66     desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
67     desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
68
69     // Stencil
70     desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::CLEAR);
71     desc.SetStencilStoreOp(Graphics::AttachmentStoreOp::STORE);
72     attachmentDescriptions.push_back(desc);
73
74     mClearValues.emplace_back();
75     mClearValues.back().depthStencil.depth   = 0;
76     mClearValues.back().depthStencil.stencil = 0;
77   }
78
79   Graphics::RenderPassCreateInfo rpInfo{};
80   rpInfo.SetAttachments(attachmentDescriptions);
81
82   // Add default render pass (loadOp = clear)
83   mRenderPass = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
84
85   desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
86   attachmentDescriptions[0] = desc;
87   if(attachmentDescriptions.size() > 1)
88   {
89     desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
90     desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::LOAD);
91     attachmentDescriptions.back() = desc;
92   }
93
94   mRenderPassNoClear = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
95 }
96
97 RenderInstructionContainer& Scene::GetRenderInstructions()
98 {
99   return mInstructions;
100 }
101
102 void Scene::AddFrameRenderedCallback(CallbackBase* callback, int32_t frameId)
103 {
104   mFrameRenderedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
105 }
106
107 void Scene::AddFramePresentedCallback(CallbackBase* callback, int32_t frameId)
108 {
109   mFramePresentedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
110 }
111
112 void Scene::GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
113 {
114   // Transfer owership of the callbacks
115   for(auto&& iter : mFrameRenderedCallbacks)
116   {
117     callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
118   }
119
120   mFrameRenderedCallbacks.clear();
121 }
122
123 void Scene::GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
124 {
125   // Transfer owership of the callbacks
126   for(auto&& iter : mFramePresentedCallbacks)
127   {
128     callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
129   }
130
131   mFramePresentedCallbacks.clear();
132 }
133
134 void Scene::SetSkipRendering(bool skip)
135 {
136   mSkipRendering = skip;
137 }
138
139 bool Scene::IsRenderingSkipped() const
140 {
141   return mSkipRendering;
142 }
143
144 void Scene::SetSurfaceRect(const Rect<int32_t>& rect)
145 {
146   mSurfaceRect        = rect;
147   mSurfaceRectChanged = true;
148
149   if(mRoot)
150   {
151     mRoot->SetUpdated(true);
152   }
153 }
154
155 const Rect<int32_t>& Scene::GetSurfaceRect() const
156 {
157   return mSurfaceRect;
158 }
159
160 void Scene::SetSurfaceOrientation(int32_t orientation)
161 {
162   mSurfaceOrientation = orientation;
163
164   if(mRoot)
165   {
166     mRoot->SetUpdated(true);
167   }
168 }
169
170 int32_t Scene::GetSurfaceOrientation() const
171 {
172   return mSurfaceOrientation;
173 }
174
175 bool Scene::IsSurfaceRectChanged()
176 {
177   bool surfaceRectChanged = mSurfaceRectChanged;
178   mSurfaceRectChanged     = false;
179
180   return surfaceRectChanged;
181 }
182
183 void Scene::SetRotationCompletedAcknowledgement()
184 {
185   mRotationCompletedAcknowledgement = true;
186 }
187
188 bool Scene::IsRotationCompletedAcknowledgementSet()
189 {
190   bool setRotationCompletedAcknowledgement = mRotationCompletedAcknowledgement;
191   mRotationCompletedAcknowledgement        = false;
192   return setRotationCompletedAcknowledgement;
193 }
194
195 std::vector<DirtyRect>& Scene::GetItemsDirtyRects()
196 {
197   return mItemsDirtyRects;
198 }
199
200 } // namespace SceneGraph
201
202 } // namespace Internal
203
204 } // namespace Dali