Changed SceneHolder's RenderTarget initialization
[platform/core/uifw/dali-core.git] / dali / internal / update / common / scene-graph-scene.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 // CLASS HEADER
18 #include <dali/internal/update/common/scene-graph-scene.h>
19
20 // INTERNAL INCLUDES
21 #include <dali/integration-api/core-enumerations.h>
22 #include <dali/internal/update/render-tasks/scene-graph-render-task-list.h>
23
24 namespace Dali
25 {
26 namespace Internal
27 {
28 namespace SceneGraph
29 {
30 Scene::Scene()
31 : mFrameRenderedCallbacks(),
32   mFramePresentedCallbacks(),
33   mSkipRendering(false),
34   mSurfaceRect(),
35   mSurfaceOrientation(0),
36   mSurfaceRectChanged(false),
37   mRotationCompletedAcknowledgement(false)
38 {
39 }
40
41 Scene::~Scene()
42 {
43   mFrameRenderedCallbacks.clear();
44   mFramePresentedCallbacks.clear();
45 }
46
47 void Scene::Initialize(Graphics::Controller& graphicsController, Integration::DepthBufferAvailable depthBufferAvailable, Integration::StencilBufferAvailable stencilBufferAvailable)
48 {
49   mGraphicsController = &graphicsController;
50
51   // Create the render target for the surface. It should already have been sent via message.
52   mRenderTarget = mGraphicsController->CreateRenderTarget(mRenderTargetCreateInfo, std::move(mRenderTarget));
53
54   // Create the render pass for the surface
55   std::vector<Graphics::AttachmentDescription> attachmentDescriptions;
56
57   // Default behaviour for color attachments is to CLEAR and STORE
58   mClearValues.clear();
59   mClearValues.emplace_back();
60
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);
66
67   if(depthBufferAvailable == Integration::DepthBufferAvailable::TRUE ||
68      stencilBufferAvailable == Integration::StencilBufferAvailable::TRUE)
69   {
70     // Depth
71     desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
72     desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
73
74     // Stencil
75     desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::CLEAR);
76     desc.SetStencilStoreOp(Graphics::AttachmentStoreOp::STORE);
77     attachmentDescriptions.push_back(desc);
78
79     mClearValues.emplace_back();
80     mClearValues.back().depthStencil.depth   = 0;
81     mClearValues.back().depthStencil.stencil = 0;
82   }
83
84   Graphics::RenderPassCreateInfo rpInfo{};
85   rpInfo.SetAttachments(attachmentDescriptions);
86
87   // Add default render pass (loadOp = clear)
88   mRenderPass = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
89
90   desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
91   attachmentDescriptions[0] = desc;
92   if(attachmentDescriptions.size() > 1)
93   {
94     desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
95     desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::LOAD);
96     attachmentDescriptions.back() = desc;
97   }
98
99   mRenderPassNoClear = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
100 }
101
102 RenderInstructionContainer& Scene::GetRenderInstructions()
103 {
104   return mInstructions;
105 }
106
107 void Scene::AddFrameRenderedCallback(CallbackBase* callback, int32_t frameId)
108 {
109   mFrameRenderedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
110 }
111
112 void Scene::AddFramePresentedCallback(CallbackBase* callback, int32_t frameId)
113 {
114   mFramePresentedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
115 }
116
117 void Scene::GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
118 {
119   // Transfer owership of the callbacks
120   for(auto&& iter : mFrameRenderedCallbacks)
121   {
122     callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
123   }
124
125   mFrameRenderedCallbacks.clear();
126 }
127
128 void Scene::GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
129 {
130   // Transfer owership of the callbacks
131   for(auto&& iter : mFramePresentedCallbacks)
132   {
133     callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
134   }
135
136   mFramePresentedCallbacks.clear();
137 }
138
139 void Scene::SetSkipRendering(bool skip)
140 {
141   mSkipRendering = skip;
142 }
143
144 bool Scene::IsRenderingSkipped() const
145 {
146   return mSkipRendering;
147 }
148
149 void Scene::SetSurfaceRect(const Rect<int32_t>& rect)
150 {
151   mSurfaceRect        = rect;
152   mSurfaceRectChanged = true;
153 }
154
155 const Rect<int32_t>& Scene::GetSurfaceRect() const
156 {
157   return mSurfaceRect;
158 }
159
160 void Scene::SetSurfaceOrientation(int32_t orientation)
161 {
162   mSurfaceOrientation = orientation;
163 }
164
165 int32_t Scene::GetSurfaceOrientation() const
166 {
167   return mSurfaceOrientation;
168 }
169
170 bool Scene::IsSurfaceRectChanged()
171 {
172   bool surfaceRectChanged = mSurfaceRectChanged;
173   mSurfaceRectChanged     = false;
174
175   return surfaceRectChanged;
176 }
177
178 void Scene::SetRotationCompletedAcknowledgement()
179 {
180   mRotationCompletedAcknowledgement = true;
181 }
182
183 bool Scene::IsRotationCompletedAcknowledgementSet()
184 {
185   bool setRotationCompletedAcknowledgement = mRotationCompletedAcknowledgement;
186   mRotationCompletedAcknowledgement        = false;
187   return setRotationCompletedAcknowledgement;
188 }
189
190 std::vector<DirtyRect>& Scene::GetItemsDirtyRects()
191 {
192   return mItemsDirtyRects;
193 }
194
195 void Scene::SetSurfaceRenderTargetCreateInfo(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo)
196 {
197   if(mRenderTarget != nullptr &&
198      mRenderTargetCreateInfo.surface != renderTargetCreateInfo.surface)
199   {
200     // Only recreate if the surface has changed.
201     mRenderTargetCreateInfo = renderTargetCreateInfo;
202     mRenderTarget           = mGraphicsController->CreateRenderTarget(renderTargetCreateInfo, std::move(mRenderTarget));
203   }
204   else
205   {
206     // 2nd Stage initialization happens in RenderManager, not UpdateManager, so is delayed.
207     mRenderTargetCreateInfo = renderTargetCreateInfo;
208   }
209 }
210
211 } // namespace SceneGraph
212
213 } // namespace Internal
214
215 } // namespace Dali