Merge "Updated all code to new format" 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/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)
48 {
49   mContext = &context;
50 }
51
52 Context* Scene::GetContext()
53 {
54   return mContext;
55 }
56
57 RenderInstructionContainer& Scene::GetRenderInstructions()
58 {
59   return mInstructions;
60 }
61
62 void Scene::AddFrameRenderedCallback(CallbackBase* callback, int32_t frameId)
63 {
64   mFrameRenderedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
65 }
66
67 void Scene::AddFramePresentedCallback(CallbackBase* callback, int32_t frameId)
68 {
69   mFramePresentedCallbacks.push_back(std::make_pair(std::unique_ptr<CallbackBase>(callback), frameId));
70 }
71
72 void Scene::GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
73 {
74   // Transfer owership of the callbacks
75   for(auto&& iter : mFrameRenderedCallbacks)
76   {
77     callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
78   }
79
80   mFrameRenderedCallbacks.clear();
81 }
82
83 void Scene::GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
84 {
85   // Transfer owership of the callbacks
86   for(auto&& iter : mFramePresentedCallbacks)
87   {
88     callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
89   }
90
91   mFramePresentedCallbacks.clear();
92 }
93
94 void Scene::SetSkipRendering(bool skip)
95 {
96   mSkipRendering = skip;
97 }
98
99 bool Scene::IsRenderingSkipped() const
100 {
101   return mSkipRendering;
102 }
103
104 void Scene::SetSurfaceRect(const Rect<int32_t>& rect)
105 {
106   mSurfaceRect        = rect;
107   mSurfaceRectChanged = true;
108 }
109
110 const Rect<int32_t>& Scene::GetSurfaceRect() const
111 {
112   return mSurfaceRect;
113 }
114
115 void Scene::SetSurfaceOrientation(int32_t orientation)
116 {
117   mSurfaceOrientation = orientation;
118 }
119
120 int32_t Scene::GetSurfaceOrientation() const
121 {
122   return mSurfaceOrientation;
123 }
124
125 bool Scene::IsSurfaceRectChanged()
126 {
127   bool surfaceRectChanged = mSurfaceRectChanged;
128   mSurfaceRectChanged     = false;
129
130   return surfaceRectChanged;
131 }
132
133 } // namespace SceneGraph
134
135 } // namespace Internal
136
137 } // namespace Dali