2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali/internal/update/common/scene-graph-scene.h>
21 #include <dali/integration-api/core-enumerations.h>
22 #include <dali/internal/update/render-tasks/scene-graph-render-task-list.h>
31 : mFrameRenderedCallbacks(),
32 mFramePresentedCallbacks(),
33 mSkipRendering(false),
35 mSurfaceOrientation(0),
36 mScreenOrientation(0),
37 mSurfaceRectChanged(false),
38 mRotationCompletedAcknowledgement(false)
44 mFrameRenderedCallbacks.clear();
45 mFramePresentedCallbacks.clear();
48 void Scene::Initialize(Graphics::Controller& graphicsController, Integration::DepthBufferAvailable depthBufferAvailable, Integration::StencilBufferAvailable stencilBufferAvailable)
50 mGraphicsController = &graphicsController;
52 // Create the render target for the surface. It should already have been sent via message.
53 mRenderTarget = graphicsController.CreateRenderTarget(mRenderTargetCreateInfo, std::move(mRenderTarget));
55 // Create the render pass for the surface
56 std::vector<Graphics::AttachmentDescription> attachmentDescriptions;
58 // Default behaviour for color attachments is to CLEAR and STORE
60 mClearValues.emplace_back();
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);
68 if(depthBufferAvailable == Integration::DepthBufferAvailable::TRUE ||
69 stencilBufferAvailable == Integration::StencilBufferAvailable::TRUE)
72 desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
73 desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
76 desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::CLEAR);
77 desc.SetStencilStoreOp(Graphics::AttachmentStoreOp::STORE);
78 attachmentDescriptions.push_back(desc);
80 mClearValues.emplace_back();
81 mClearValues.back().depthStencil.depth = 0;
82 mClearValues.back().depthStencil.stencil = 0;
85 Graphics::RenderPassCreateInfo rpInfo{};
86 rpInfo.SetAttachments(attachmentDescriptions);
88 // Add default render pass (loadOp = clear)
89 mRenderPass = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
91 desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
92 attachmentDescriptions[0] = desc;
93 if(attachmentDescriptions.size() > 1)
95 desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
96 desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::LOAD);
97 attachmentDescriptions.back() = desc;
100 mRenderPassNoClear = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
103 RenderInstructionContainer& Scene::GetRenderInstructions()
105 return mInstructions;
108 void Scene::AddFrameRenderedCallback(CallbackBase* callback, int32_t frameId)
110 mFrameRenderedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
113 void Scene::AddFramePresentedCallback(CallbackBase* callback, int32_t frameId)
115 mFramePresentedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
118 void Scene::GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
120 // Transfer owership of the callbacks
121 for(auto&& iter : mFrameRenderedCallbacks)
123 callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
126 mFrameRenderedCallbacks.clear();
129 void Scene::GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
131 // Transfer owership of the callbacks
132 for(auto&& iter : mFramePresentedCallbacks)
134 callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
137 mFramePresentedCallbacks.clear();
140 void Scene::SetSkipRendering(bool skip)
142 mSkipRendering = skip;
145 bool Scene::IsRenderingSkipped() const
147 return mSkipRendering;
150 void Scene::SetSurfaceRect(const Rect<int32_t>& rect)
153 mSurfaceRectChanged = true;
155 DALI_LOG_RELEASE_INFO("update surfce rect in scene-graph, width[%d], height[%d]\n", mSurfaceRect.width, mSurfaceRect.height);
159 mRoot->SetUpdated(true);
163 const Rect<int32_t>& Scene::GetSurfaceRect() const
168 bool Scene::IsSurfaceRectChanged()
170 bool surfaceRectChanged = mSurfaceRectChanged;
171 mSurfaceRectChanged = false;
173 return surfaceRectChanged;
176 void Scene::SetSurfaceOrientations(int32_t windowOrientation, int32_t screenOrienation)
178 mSurfaceOrientation = windowOrientation;
179 mScreenOrientation = screenOrienation;
183 mRoot->SetUpdated(true);
186 DALI_LOG_RELEASE_INFO("update orientation in scene-graph, surface [%d], screen[%d]\n", mSurfaceOrientation, mScreenOrientation);
189 int32_t Scene::GetSurfaceOrientation() const
191 return mSurfaceOrientation;
194 int32_t Scene::GetScreenOrientation() const
196 return mScreenOrientation;
199 void Scene::SetRotationCompletedAcknowledgement()
201 mRotationCompletedAcknowledgement = true;
204 bool Scene::IsRotationCompletedAcknowledgementSet()
206 bool setRotationCompletedAcknowledgement = mRotationCompletedAcknowledgement;
207 mRotationCompletedAcknowledgement = false;
208 return setRotationCompletedAcknowledgement;
211 std::vector<DirtyRect>& Scene::GetItemsDirtyRects()
213 return mItemsDirtyRects;
216 void Scene::SetSurfaceRenderTargetCreateInfo(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo)
218 if(mRenderTarget != nullptr &&
219 mRenderTargetCreateInfo.surface != renderTargetCreateInfo.surface)
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.
225 mRenderTarget = mGraphicsController->CreateRenderTarget(renderTargetCreateInfo, std::move(mRenderTarget));
230 // 2nd Stage initialization happens in RenderManager, not UpdateManager, so is delayed.
231 mRenderTargetCreateInfo = renderTargetCreateInfo;
235 } // namespace SceneGraph
237 } // namespace Internal