RenderPass and presentation
[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/internal/render/gl-resources/context.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 : mContext(nullptr),
32   mFrameRenderedCallbacks(),
33   mFramePresentedCallbacks(),
34   mSkipRendering(false),
35   mSurfaceRect(),
36   mSurfaceOrientation(0),
37   mSurfaceRectChanged(false)
38 {
39 }
40
41 Scene::~Scene()
42 {
43   mFrameRenderedCallbacks.clear();
44   mFramePresentedCallbacks.clear();
45 }
46
47 void Scene::Initialize(Context& context, Graphics::Controller& graphicsController)
48 {
49   mContext = &context;
50
51   // Create the render pass for the surface
52   std::vector<Graphics::AttachmentDescription> attachmentDescriptions;
53
54   // Default behaviour for color attachments is to CLEAR and STORE
55   mClearValues.clear();
56   Graphics::AttachmentDescription desc{};
57   desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
58   desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
59   attachmentDescriptions.push_back(desc);
60   mClearValues.emplace_back();
61
62   Graphics::RenderPassCreateInfo rpInfo{};
63   rpInfo.SetAttachments(attachmentDescriptions);
64
65   // Add default render pass (loadOp = clear)
66   mRenderPass = graphicsController.CreateRenderPass(rpInfo, nullptr);
67
68   desc.SetLoadOp( Graphics::AttachmentLoadOp::LOAD );
69   attachmentDescriptions[0] = desc;
70   mRenderPassNoClear = graphicsController.CreateRenderPass(rpInfo, nullptr);
71 }
72
73 Context* Scene::GetContext()
74 {
75   return mContext;
76 }
77
78 RenderInstructionContainer& Scene::GetRenderInstructions()
79 {
80   return mInstructions;
81 }
82
83 void Scene::AddFrameRenderedCallback(CallbackBase* callback, int32_t frameId)
84 {
85   mFrameRenderedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
86 }
87
88 void Scene::AddFramePresentedCallback(CallbackBase* callback, int32_t frameId)
89 {
90   mFramePresentedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
91 }
92
93 void Scene::GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
94 {
95   // Transfer owership of the callbacks
96   for(auto&& iter : mFrameRenderedCallbacks)
97   {
98     callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
99   }
100
101   mFrameRenderedCallbacks.clear();
102 }
103
104 void Scene::GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
105 {
106   // Transfer owership of the callbacks
107   for(auto&& iter : mFramePresentedCallbacks)
108   {
109     callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
110   }
111
112   mFramePresentedCallbacks.clear();
113 }
114
115 void Scene::SetSkipRendering(bool skip)
116 {
117   mSkipRendering = skip;
118 }
119
120 bool Scene::IsRenderingSkipped() const
121 {
122   return mSkipRendering;
123 }
124
125 void Scene::SetSurfaceRect(const Rect<int32_t>& rect)
126 {
127   mSurfaceRect        = rect;
128   mSurfaceRectChanged = true;
129 }
130
131 const Rect<int32_t>& Scene::GetSurfaceRect() const
132 {
133   return mSurfaceRect;
134 }
135
136 void Scene::SetSurfaceOrientation(int32_t orientation)
137 {
138   mSurfaceOrientation = orientation;
139 }
140
141 int32_t Scene::GetSurfaceOrientation() const
142 {
143   return mSurfaceOrientation;
144 }
145
146 bool Scene::IsSurfaceRectChanged()
147 {
148   bool surfaceRectChanged = mSurfaceRectChanged;
149   mSurfaceRectChanged     = false;
150
151   return surfaceRectChanged;
152 }
153
154 } // namespace SceneGraph
155
156 } // namespace Internal
157
158 } // namespace Dali