Fix the synchronization issue when window is resized or rotated
[platform/core/uifw/dali-core.git] / dali / internal / update / common / scene-graph-scene.cpp
1 /*
2  * Copyright (c) 2020 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/update/render-tasks/scene-graph-render-task-list.h>
22 #include <dali/internal/render/gl-resources/context.h>
23
24 namespace Dali
25 {
26 namespace Internal
27 {
28 namespace SceneGraph
29 {
30
31 Scene::Scene()
32 : mContext( nullptr ),
33   mFrameRenderedCallbacks(),
34   mFramePresentedCallbacks(),
35   mSkipRendering( false ),
36   mSurfaceRect(),
37   mSurfaceOrientation( 0 ),
38   mSurfaceRectChanged( false )
39 {
40 }
41
42 Scene::~Scene()
43 {
44   mFrameRenderedCallbacks.clear();
45   mFramePresentedCallbacks.clear();
46 }
47
48 void Scene::Initialize( Context& context )
49 {
50   mContext = &context;
51 }
52
53 Context* Scene::GetContext()
54 {
55   return mContext;
56 }
57
58 RenderInstructionContainer& Scene::GetRenderInstructions()
59 {
60   return mInstructions;
61 }
62
63 void Scene::AddFrameRenderedCallback( CallbackBase* callback, int32_t frameId )
64 {
65   mFrameRenderedCallbacks.push_back( std::make_pair( std::unique_ptr< CallbackBase >( callback ), frameId ) );
66 }
67
68 void Scene::AddFramePresentedCallback( CallbackBase* callback, int32_t frameId )
69 {
70   mFramePresentedCallbacks.push_back( std::make_pair( std::unique_ptr< CallbackBase >( callback ), frameId ) );
71 }
72
73 void Scene::GetFrameRenderedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks )
74 {
75   // Transfer owership of the callbacks
76   for( auto&& iter : mFrameRenderedCallbacks )
77   {
78     callbacks.push_back( std::make_pair( std::move( iter.first ), iter.second ) );
79   }
80
81   mFrameRenderedCallbacks.clear();
82 }
83
84 void Scene::GetFramePresentedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks )
85 {
86   // Transfer owership of the callbacks
87   for( auto&& iter : mFramePresentedCallbacks )
88   {
89     callbacks.push_back( std::make_pair( std::move( iter.first ), iter.second ) );
90   }
91
92   mFramePresentedCallbacks.clear();
93 }
94
95 void Scene::SetSkipRendering( bool skip )
96 {
97   mSkipRendering = skip;
98 }
99
100 bool Scene::IsRenderingSkipped() const
101 {
102   return mSkipRendering;
103 }
104
105 void Scene::SetSurfaceRect( const Rect<int32_t>& rect )
106 {
107   mSurfaceRect = rect;
108   mSurfaceRectChanged = true;
109 }
110
111 const Rect<int32_t>& Scene::GetSurfaceRect() const
112 {
113   return mSurfaceRect;
114 }
115
116 void Scene::SetSurfaceOrientation( int32_t orientation )
117 {
118   mSurfaceOrientation = orientation;
119 }
120
121 int32_t Scene::GetSurfaceOrientation() const
122 {
123   return mSurfaceOrientation;
124 }
125
126 bool Scene::IsSurfaceRectChanged()
127 {
128   bool surfaceRectChanged = mSurfaceRectChanged;
129   mSurfaceRectChanged = false;
130
131   return surfaceRectChanged;
132 }
133
134 } //SceneGraph
135
136 } //Internal
137
138 } //Dali