2 * Copyright (c) 2023 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(),
34 mSurfaceOrientation(0),
35 mScreenOrientation(0),
36 mSurfaceRectChanged(false),
37 mRotationCompletedAcknowledgement(false),
38 mSkipRendering(false),
39 mNeedFullUpdate(false)
45 mFrameRenderedCallbacks.clear();
46 mFramePresentedCallbacks.clear();
49 void Scene::Initialize(Graphics::Controller& graphicsController, Integration::DepthBufferAvailable depthBufferAvailable, Integration::StencilBufferAvailable stencilBufferAvailable)
51 mGraphicsController = &graphicsController;
53 // Create the render target for the surface. It should already have been sent via message.
54 mRenderTarget = graphicsController.CreateRenderTarget(mRenderTargetCreateInfo, std::move(mRenderTarget));
56 // Create the render pass for the surface
57 std::vector<Graphics::AttachmentDescription> attachmentDescriptions;
59 // Default behaviour for color attachments is to CLEAR and STORE
61 mClearValues.emplace_back();
63 // Assume single color attachment
64 Graphics::AttachmentDescription desc{};
65 desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
66 desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
67 attachmentDescriptions.push_back(desc);
69 if(depthBufferAvailable == Integration::DepthBufferAvailable::TRUE ||
70 stencilBufferAvailable == Integration::StencilBufferAvailable::TRUE)
73 desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
74 desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
77 desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::CLEAR);
78 desc.SetStencilStoreOp(Graphics::AttachmentStoreOp::STORE);
79 attachmentDescriptions.push_back(desc);
81 mClearValues.emplace_back();
82 mClearValues.back().depthStencil.depth = 0;
83 mClearValues.back().depthStencil.stencil = 0;
86 Graphics::RenderPassCreateInfo rpInfo{};
87 rpInfo.SetAttachments(attachmentDescriptions);
89 // Add default render pass (loadOp = clear)
90 mRenderPass = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
92 desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
93 attachmentDescriptions[0] = desc;
94 if(attachmentDescriptions.size() > 1)
96 desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
97 desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::LOAD);
98 attachmentDescriptions.back() = desc;
101 mRenderPassNoClear = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
104 RenderInstructionContainer& Scene::GetRenderInstructions()
106 return mInstructions;
109 void Scene::AddFrameRenderedCallback(CallbackBase* callback, int32_t frameId)
111 mFrameRenderedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
114 void Scene::AddFramePresentedCallback(CallbackBase* callback, int32_t frameId)
116 mFramePresentedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
119 void Scene::GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
121 // Transfer owership of the callbacks
122 for(auto&& iter : mFrameRenderedCallbacks)
124 callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
127 mFrameRenderedCallbacks.clear();
130 void Scene::GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
132 // Transfer owership of the callbacks
133 for(auto&& iter : mFramePresentedCallbacks)
135 callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
138 mFramePresentedCallbacks.clear();
141 void Scene::SetSkipRendering(bool skip)
143 mSkipRendering = skip;
146 bool Scene::IsRenderingSkipped() const
148 return mSkipRendering;
151 void Scene::SetSurfaceRect(const Rect<int32_t>& rect)
154 mSurfaceRectChanged = true;
156 DALI_LOG_RELEASE_INFO("update surfce rect in scene-graph, width[%d], height[%d]\n", mSurfaceRect.width, mSurfaceRect.height);
160 mRoot->SetUpdated(true);
164 const Rect<int32_t>& Scene::GetSurfaceRect() const
169 bool Scene::IsSurfaceRectChanged()
171 bool surfaceRectChanged = mSurfaceRectChanged;
172 mSurfaceRectChanged = false;
174 return surfaceRectChanged;
177 void Scene::SetSurfaceOrientations(int32_t windowOrientation, int32_t screenOrienation)
179 mSurfaceOrientation = windowOrientation;
180 mScreenOrientation = screenOrienation;
184 mRoot->SetUpdated(true);
187 DALI_LOG_RELEASE_INFO("update orientation in scene-graph, surface [%d], screen[%d]\n", mSurfaceOrientation, mScreenOrientation);
190 int32_t Scene::GetSurfaceOrientation() const
192 return mSurfaceOrientation;
195 int32_t Scene::GetScreenOrientation() const
197 return mScreenOrientation;
200 void Scene::SetRotationCompletedAcknowledgement()
202 mRotationCompletedAcknowledgement = true;
205 bool Scene::IsRotationCompletedAcknowledgementSet()
207 bool setRotationCompletedAcknowledgement = mRotationCompletedAcknowledgement;
208 mRotationCompletedAcknowledgement = false;
209 return setRotationCompletedAcknowledgement;
212 Scene::ItemsDirtyRectsContainer& Scene::GetItemsDirtyRects()
214 return mItemsDirtyRects;
217 void Scene::SetSurfaceRenderTargetCreateInfo(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo)
219 if(mRenderTarget != nullptr &&
220 mRenderTargetCreateInfo.surface != renderTargetCreateInfo.surface)
222 // Only recreate if the surface has changed.
223 mRenderTargetCreateInfo = renderTargetCreateInfo;
224 if(mGraphicsController) // shouldn't be null, as we can't have already set mRenderTarget unless graphics controller exists.
226 mRenderTarget = mGraphicsController->CreateRenderTarget(renderTargetCreateInfo, std::move(mRenderTarget));
231 // 2nd Stage initialization happens in RenderManager, not UpdateManager, so is delayed.
232 mRenderTargetCreateInfo = renderTargetCreateInfo;
236 void Scene::KeepRendering(float durationSeconds)
238 mKeepRenderingSeconds = std::max(mKeepRenderingSeconds, durationSeconds);
241 bool Scene::KeepRenderingCheck(float elapsedSeconds)
243 if(mKeepRenderingSeconds > 0.0f)
245 mNeedFullUpdate = true; // Full update if KeepRendering is required
246 mKeepRenderingSeconds = std::max(0.0f, mKeepRenderingSeconds - elapsedSeconds);
250 mNeedFullUpdate = false;
251 mKeepRenderingSeconds = 0.0f;
255 } // namespace SceneGraph
257 } // namespace Internal