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 mSurfaceRectChangedCount(0u),
37 mRotationCompletedAcknowledgement(false),
38 mSkipRendering(false),
39 mNeedFullUpdate(false),
40 mPartialUpdateEnabled(true)
46 mFrameRenderedCallbacks.clear();
47 mFramePresentedCallbacks.clear();
50 void Scene::Initialize(Graphics::Controller& graphicsController, Integration::DepthBufferAvailable depthBufferAvailable, Integration::StencilBufferAvailable stencilBufferAvailable)
52 mGraphicsController = &graphicsController;
54 // Create the render target for the surface. It should already have been sent via message.
55 mRenderTarget = graphicsController.CreateRenderTarget(mRenderTargetCreateInfo, std::move(mRenderTarget));
57 // Create the render pass for the surface
58 std::vector<Graphics::AttachmentDescription> attachmentDescriptions;
60 // Default behaviour for color attachments is to CLEAR and STORE
62 mClearValues.emplace_back();
64 // Assume single color attachment
65 Graphics::AttachmentDescription desc{};
66 desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
67 desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
68 attachmentDescriptions.push_back(desc);
70 if(depthBufferAvailable == Integration::DepthBufferAvailable::TRUE ||
71 stencilBufferAvailable == Integration::StencilBufferAvailable::TRUE)
74 desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
75 desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
78 desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::CLEAR);
79 desc.SetStencilStoreOp(Graphics::AttachmentStoreOp::STORE);
80 attachmentDescriptions.push_back(desc);
82 mClearValues.emplace_back();
83 mClearValues.back().depthStencil.depth = 0;
84 mClearValues.back().depthStencil.stencil = 0;
87 Graphics::RenderPassCreateInfo rpInfo{};
88 rpInfo.SetAttachments(attachmentDescriptions);
90 // Add default render pass (loadOp = clear)
91 mRenderPass = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
93 desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
94 attachmentDescriptions[0] = desc;
95 if(attachmentDescriptions.size() > 1)
97 desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
98 desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::LOAD);
99 attachmentDescriptions.back() = desc;
102 mRenderPassNoClear = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
105 RenderInstructionContainer& Scene::GetRenderInstructions()
107 return mInstructions;
110 void Scene::AddFrameRenderedCallback(CallbackBase* callback, int32_t frameId)
112 mFrameRenderedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
115 void Scene::AddFramePresentedCallback(CallbackBase* callback, int32_t frameId)
117 mFramePresentedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
120 void Scene::GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
122 // Transfer owership of the callbacks
123 for(auto&& iter : mFrameRenderedCallbacks)
125 callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
128 mFrameRenderedCallbacks.clear();
131 void Scene::GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
133 // Transfer owership of the callbacks
134 for(auto&& iter : mFramePresentedCallbacks)
136 callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
139 mFramePresentedCallbacks.clear();
142 void Scene::SetSkipRendering(bool skip)
144 mSkipRendering = skip;
147 bool Scene::IsRenderingSkipped() const
149 return mSkipRendering;
152 void Scene::SetSurfaceRect(const Rect<int32_t>& rect)
154 DALI_LOG_RELEASE_INFO("update surfce rect in scene-graph, from width[%d], height[%d], to width[%d], height[%d]. Changed count [%d]\n", mSurfaceRect.width, mSurfaceRect.height, rect.width, rect.height, mSurfaceRectChangedCount + 1u);
157 ++mSurfaceRectChangedCount;
161 mRoot->SetUpdated(true);
165 const Rect<int32_t>& Scene::GetSurfaceRect() const
170 uint32_t Scene::GetSurfaceRectChangedCount()
172 uint32_t surfaceRectChangedCount = mSurfaceRectChangedCount;
173 mSurfaceRectChangedCount = 0u;
175 return surfaceRectChangedCount;
178 void Scene::SetSurfaceOrientations(int32_t windowOrientation, int32_t screenOrienation)
180 DALI_LOG_RELEASE_INFO("update orientation in scene-graph, from surface [%d], screen[%d], to surface [%d], screen[%d]\n", mSurfaceOrientation, mScreenOrientation, windowOrientation, screenOrienation);
182 mSurfaceOrientation = windowOrientation;
183 mScreenOrientation = screenOrienation;
187 mRoot->SetUpdated(true);
191 int32_t Scene::GetSurfaceOrientation() const
193 return mSurfaceOrientation;
196 int32_t Scene::GetScreenOrientation() const
198 return mScreenOrientation;
201 void Scene::SetRotationCompletedAcknowledgement()
203 mRotationCompletedAcknowledgement = true;
206 bool Scene::IsRotationCompletedAcknowledgementSet()
208 bool setRotationCompletedAcknowledgement = mRotationCompletedAcknowledgement;
209 mRotationCompletedAcknowledgement = false;
210 return setRotationCompletedAcknowledgement;
213 Scene::ItemsDirtyRectsContainer& Scene::GetItemsDirtyRects()
215 return mItemsDirtyRects;
218 void Scene::SetSurfaceRenderTargetCreateInfo(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo)
220 if(mRenderTarget != nullptr &&
221 mRenderTargetCreateInfo.surface != renderTargetCreateInfo.surface)
223 // Only recreate if the surface has changed.
224 mRenderTargetCreateInfo = renderTargetCreateInfo;
225 if(mGraphicsController) // shouldn't be null, as we can't have already set mRenderTarget unless graphics controller exists.
227 mRenderTarget = mGraphicsController->CreateRenderTarget(renderTargetCreateInfo, std::move(mRenderTarget));
232 // 2nd Stage initialization happens in RenderManager, not UpdateManager, so is delayed.
233 mRenderTargetCreateInfo = renderTargetCreateInfo;
237 void Scene::KeepRendering(float durationSeconds)
239 mKeepRenderingSeconds = std::max(mKeepRenderingSeconds, durationSeconds);
242 bool Scene::KeepRenderingCheck(float elapsedSeconds)
244 if(mKeepRenderingSeconds > 0.0f)
246 mNeedFullUpdate = true; // Full update if KeepRendering is required
247 mKeepRenderingSeconds = std::max(0.0f, mKeepRenderingSeconds - elapsedSeconds);
251 mNeedFullUpdate = false;
252 mKeepRenderingSeconds = 0.0f;
256 void Scene::SetPartialUpdateEnabled(bool enabled)
258 mPartialUpdateEnabled = enabled;
261 bool Scene::IsPartialUpdateEnabled() const
263 return mPartialUpdateEnabled;
266 } // namespace SceneGraph
268 } // namespace Internal