2 * Copyright (c) 2021 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 mSurfaceRectChanged(false),
37 mRotationCompletedAcknowledgement(false)
43 mFrameRenderedCallbacks.clear();
44 mFramePresentedCallbacks.clear();
47 void Scene::Initialize(Graphics::Controller& graphicsController, Integration::DepthBufferAvailable depthBufferAvailable, Integration::StencilBufferAvailable stencilBufferAvailable)
49 mGraphicsController = &graphicsController;
51 // Create the render target for the surface. It should already have been sent via message.
52 mRenderTarget = mGraphicsController->CreateRenderTarget(mRenderTargetCreateInfo, std::move(mRenderTarget));
54 // Create the render pass for the surface
55 std::vector<Graphics::AttachmentDescription> attachmentDescriptions;
57 // Default behaviour for color attachments is to CLEAR and STORE
59 mClearValues.emplace_back();
61 // Assume single color attachment
62 Graphics::AttachmentDescription desc{};
63 desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
64 desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
65 attachmentDescriptions.push_back(desc);
67 if(depthBufferAvailable == Integration::DepthBufferAvailable::TRUE ||
68 stencilBufferAvailable == Integration::StencilBufferAvailable::TRUE)
71 desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
72 desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
75 desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::CLEAR);
76 desc.SetStencilStoreOp(Graphics::AttachmentStoreOp::STORE);
77 attachmentDescriptions.push_back(desc);
79 mClearValues.emplace_back();
80 mClearValues.back().depthStencil.depth = 0;
81 mClearValues.back().depthStencil.stencil = 0;
84 Graphics::RenderPassCreateInfo rpInfo{};
85 rpInfo.SetAttachments(attachmentDescriptions);
87 // Add default render pass (loadOp = clear)
88 mRenderPass = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
90 desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
91 attachmentDescriptions[0] = desc;
92 if(attachmentDescriptions.size() > 1)
94 desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
95 desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::LOAD);
96 attachmentDescriptions.back() = desc;
99 mRenderPassNoClear = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
102 RenderInstructionContainer& Scene::GetRenderInstructions()
104 return mInstructions;
107 void Scene::AddFrameRenderedCallback(CallbackBase* callback, int32_t frameId)
109 mFrameRenderedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
112 void Scene::AddFramePresentedCallback(CallbackBase* callback, int32_t frameId)
114 mFramePresentedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
117 void Scene::GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
119 // Transfer owership of the callbacks
120 for(auto&& iter : mFrameRenderedCallbacks)
122 callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
125 mFrameRenderedCallbacks.clear();
128 void Scene::GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
130 // Transfer owership of the callbacks
131 for(auto&& iter : mFramePresentedCallbacks)
133 callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
136 mFramePresentedCallbacks.clear();
139 void Scene::SetSkipRendering(bool skip)
141 mSkipRendering = skip;
144 bool Scene::IsRenderingSkipped() const
146 return mSkipRendering;
149 void Scene::SetSurfaceRect(const Rect<int32_t>& rect)
152 mSurfaceRectChanged = true;
155 const Rect<int32_t>& Scene::GetSurfaceRect() const
160 void Scene::SetSurfaceOrientation(int32_t orientation)
162 mSurfaceOrientation = orientation;
165 int32_t Scene::GetSurfaceOrientation() const
167 return mSurfaceOrientation;
170 bool Scene::IsSurfaceRectChanged()
172 bool surfaceRectChanged = mSurfaceRectChanged;
173 mSurfaceRectChanged = false;
175 return surfaceRectChanged;
178 void Scene::SetRotationCompletedAcknowledgement()
180 mRotationCompletedAcknowledgement = true;
183 bool Scene::IsRotationCompletedAcknowledgementSet()
185 bool setRotationCompletedAcknowledgement = mRotationCompletedAcknowledgement;
186 mRotationCompletedAcknowledgement = false;
187 return setRotationCompletedAcknowledgement;
190 std::vector<DirtyRect>& Scene::GetItemsDirtyRects()
192 return mItemsDirtyRects;
195 void Scene::SetSurfaceRenderTargetCreateInfo(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo)
197 if(mRenderTarget != nullptr &&
198 mRenderTargetCreateInfo.surface != renderTargetCreateInfo.surface)
200 // Only recreate if the surface has changed.
201 mRenderTargetCreateInfo = renderTargetCreateInfo;
202 mRenderTarget = mGraphicsController->CreateRenderTarget(renderTargetCreateInfo, std::move(mRenderTarget));
206 // 2nd Stage initialization happens in RenderManager, not UpdateManager, so is delayed.
207 mRenderTargetCreateInfo = renderTargetCreateInfo;
211 } // namespace SceneGraph
213 } // namespace Internal