Merge "Fixed an issue the triple tap did not work." into devel/master
[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 {
38 }
39
40 Scene::~Scene()
41 {
42   mFrameRenderedCallbacks.clear();
43   mFramePresentedCallbacks.clear();
44 }
45
46 void Scene::Initialize(Graphics::Controller& graphicsController, Integration::DepthBufferAvailable depthBufferAvailable, Integration::StencilBufferAvailable stencilBufferAvailable)
47 {
48   // Create the render pass for the surface
49   std::vector<Graphics::AttachmentDescription> attachmentDescriptions;
50
51   // Default behaviour for color attachments is to CLEAR and STORE
52   mClearValues.clear();
53   mClearValues.emplace_back();
54
55   // Assume single color attachment
56   Graphics::AttachmentDescription desc{};
57   desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
58   desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
59   attachmentDescriptions.push_back(desc);
60
61   if(depthBufferAvailable == Integration::DepthBufferAvailable::TRUE ||
62      stencilBufferAvailable == Integration::StencilBufferAvailable::TRUE)
63   {
64     // Depth
65     desc.SetLoadOp(Graphics::AttachmentLoadOp::CLEAR);
66     desc.SetStoreOp(Graphics::AttachmentStoreOp::STORE);
67
68     // Stencil
69     desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::CLEAR);
70     desc.SetStencilStoreOp(Graphics::AttachmentStoreOp::STORE);
71     attachmentDescriptions.push_back(desc);
72
73     mClearValues.emplace_back();
74     mClearValues.back().depthStencil.depth   = 0;
75     mClearValues.back().depthStencil.stencil = 0;
76   }
77
78   Graphics::RenderPassCreateInfo rpInfo{};
79   rpInfo.SetAttachments(attachmentDescriptions);
80
81   // Add default render pass (loadOp = clear)
82   mRenderPass = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
83
84   desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
85   attachmentDescriptions[0] = desc;
86   if(attachmentDescriptions.size() > 1)
87   {
88     desc.SetLoadOp(Graphics::AttachmentLoadOp::LOAD);
89     desc.SetStencilLoadOp(Graphics::AttachmentLoadOp::LOAD);
90     attachmentDescriptions.back() = desc;
91   }
92
93   mRenderPassNoClear = graphicsController.CreateRenderPass(rpInfo, nullptr); // Warning: Shallow ptr
94 }
95
96 RenderInstructionContainer& Scene::GetRenderInstructions()
97 {
98   return mInstructions;
99 }
100
101 void Scene::AddFrameRenderedCallback(CallbackBase* callback, int32_t frameId)
102 {
103   mFrameRenderedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
104 }
105
106 void Scene::AddFramePresentedCallback(CallbackBase* callback, int32_t frameId)
107 {
108   mFramePresentedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
109 }
110
111 void Scene::GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
112 {
113   // Transfer owership of the callbacks
114   for(auto&& iter : mFrameRenderedCallbacks)
115   {
116     callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
117   }
118
119   mFrameRenderedCallbacks.clear();
120 }
121
122 void Scene::GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
123 {
124   // Transfer owership of the callbacks
125   for(auto&& iter : mFramePresentedCallbacks)
126   {
127     callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
128   }
129
130   mFramePresentedCallbacks.clear();
131 }
132
133 void Scene::SetSkipRendering(bool skip)
134 {
135   mSkipRendering = skip;
136 }
137
138 bool Scene::IsRenderingSkipped() const
139 {
140   return mSkipRendering;
141 }
142
143 void Scene::SetSurfaceRect(const Rect<int32_t>& rect)
144 {
145   mSurfaceRect        = rect;
146   mSurfaceRectChanged = true;
147 }
148
149 const Rect<int32_t>& Scene::GetSurfaceRect() const
150 {
151   return mSurfaceRect;
152 }
153
154 void Scene::SetSurfaceOrientation(int32_t orientation)
155 {
156   mSurfaceOrientation = orientation;
157 }
158
159 int32_t Scene::GetSurfaceOrientation() const
160 {
161   return mSurfaceOrientation;
162 }
163
164 bool Scene::IsSurfaceRectChanged()
165 {
166   bool surfaceRectChanged = mSurfaceRectChanged;
167   mSurfaceRectChanged     = false;
168
169   return surfaceRectChanged;
170 }
171
172 } // namespace SceneGraph
173
174 } // namespace Internal
175
176 } // namespace Dali