Merge "(Scene) Add frame rendered/presented callback" into devel/master
[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 #include <dali/internal/update/render-tasks/scene-graph-render-task-list.h>
21
22 namespace Dali
23 {
24 namespace Internal
25 {
26 namespace SceneGraph
27 {
28
29 Scene::Scene()
30 : mContext( nullptr ),
31   mFrameRenderedCallbacks(),
32   mFramePresentedCallbacks()
33 {
34 }
35
36 Scene::~Scene()
37 {
38   if ( mContext )
39   {
40     mContext->GlContextDestroyed();
41
42     delete mContext;
43     mContext = nullptr;
44   }
45
46   mFrameRenderedCallbacks.clear();
47   mFramePresentedCallbacks.clear();
48 }
49
50 void Scene::GlContextDestroyed()
51 {
52   if ( mContext )
53   {
54     mContext->GlContextDestroyed();
55   }
56 }
57
58 void Scene::Initialize( Context& context )
59 {
60   if ( mContext != &context )
61   {
62     if ( mContext )
63     {
64       mContext->GlContextDestroyed();
65       delete mContext;
66     }
67
68     mContext = &context;
69     mContext->GlContextCreated();
70   }
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 } //SceneGraph
116
117 } //Internal
118
119 } //Dali