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/render/gl-resources/context.h>
23 #include <dali/internal/update/render-tasks/scene-graph-render-task-list.h>
33 mFrameRenderedCallbacks(),
34 mFramePresentedCallbacks(),
35 mSkipRendering(false),
37 mSurfaceOrientation(0),
38 mSurfaceRectChanged(false)
44 mFrameRenderedCallbacks.clear();
45 mFramePresentedCallbacks.clear();
48 void Scene::Initialize(Context& context, Graphics::Controller& graphicsController, Integration::DepthBufferAvailable depthBufferAvailable, Integration::StencilBufferAvailable stencilBufferAvailable)
52 // Create the render pass for the surface
53 std::vector<Graphics::AttachmentDescription> attachmentDescriptions;
55 // Default behaviour for color attachments is to CLEAR and STORE
57 mClearValues.emplace_back();
59 // Assume single color attachment
60 Graphics::AttachmentDescription desc{};
61 desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
62 desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
63 attachmentDescriptions.push_back(desc);
65 if(depthBufferAvailable == Integration::DepthBufferAvailable::TRUE ||
66 stencilBufferAvailable == Integration::StencilBufferAvailable::TRUE)
69 desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
70 desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
73 desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::CLEAR);
74 desc.SetStencilStoreOp(Graphics::AttachmentStoreOp::STORE);
75 attachmentDescriptions.push_back(desc);
77 mClearValues.emplace_back();
78 mClearValues.back().depthStencil.depth = 0;
79 mClearValues.back().depthStencil.stencil = 0;
82 Graphics::RenderPassCreateInfo rpInfo{};
83 rpInfo.SetAttachments(attachmentDescriptions);
85 // Add default render pass (loadOp = clear)
86 mRenderPass = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
88 desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
89 attachmentDescriptions[0] = desc;
90 if(attachmentDescriptions.size() > 1)
92 desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
93 desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::LOAD);
94 attachmentDescriptions.back() = desc;
97 mRenderPassNoClear = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
100 Context* Scene::GetContext()
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)
155 mSurfaceRectChanged = true;
158 const Rect<int32_t>& Scene::GetSurfaceRect() const
163 void Scene::SetSurfaceOrientation(int32_t orientation)
165 mSurfaceOrientation = orientation;
168 int32_t Scene::GetSurfaceOrientation() const
170 return mSurfaceOrientation;
173 bool Scene::IsSurfaceRectChanged()
175 bool surfaceRectChanged = mSurfaceRectChanged;
176 mSurfaceRectChanged = false;
178 return surfaceRectChanged;
181 } // namespace SceneGraph
183 } // namespace Internal