Updates to handle context loss and regain
[platform/core/uifw/dali-core.git] / dali / public-api / common / stage.cpp
1 /*
2  * Copyright (c) 2014 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
18 // CLASS HEADER
19 #include <dali/public-api/common/stage.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/actors/actor.h>
23 #include <dali/public-api/render-tasks/render-task-list.h>
24 #include <dali/internal/event/common/stage-impl.h>
25 #include <dali/internal/common/core-impl.h>
26 #include <dali/public-api/actors/layer.h>
27 #include <dali/public-api/object/object-registry.h>
28
29 #include <dali/public-api/dynamics/dynamics-world.h>
30 #include <dali/public-api/dynamics/dynamics-world-config.h>
31
32 #ifdef DYNAMICS_SUPPORT
33 #include <dali/internal/event/dynamics/dynamics-declarations.h>
34 #include <dali/internal/event/dynamics/dynamics-world-config-impl.h>
35 #include <dali/internal/event/dynamics/dynamics-world-impl.h>
36 #endif
37
38 using namespace std;
39
40 namespace Dali
41 {
42
43 using Internal::Core;
44
45 const Vector4 Stage::DEFAULT_BACKGROUND_COLOR(0.0f, 0.0f, 0.0f, 1.0f);
46 const Vector4 Stage::DEBUG_BACKGROUND_COLOR(0.2f, 0.5f, 0.2f, 1.0f);
47
48 const char* const Stage::SIGNAL_KEY_EVENT = "key-event";
49 const char* const Stage::SIGNAL_EVENT_PROCESSING_FINISHED = "event-processing-finished";
50 const char* const Stage::SIGNAL_TOUCHED = "touched";
51
52 Stage::Stage()
53 {
54 }
55
56 Stage::~Stage()
57 {
58 }
59
60 Stage::Stage(const Stage& handle)
61 : BaseHandle(handle)
62 {
63 }
64
65 Stage& Stage::operator=(const Stage& rhs)
66 {
67   BaseHandle::operator=(rhs);
68   return *this;
69 }
70
71 Stage& Stage::operator=(BaseHandle::NullType* rhs)
72 {
73   DALI_ASSERT_ALWAYS( (rhs == NULL) && "Can only assign NULL pointer to handle");
74   Reset();
75   return *this;
76 }
77
78 Stage::Stage(Internal::Stage* internal)
79 : BaseHandle(internal)
80 {
81 }
82
83 Stage Stage::GetCurrent()
84 {
85   return Stage(Internal::Stage::GetCurrent());
86 }
87
88 bool Stage::IsInstalled()
89 {
90   return Internal::Stage::IsInstalled();
91 }
92
93 void Stage::Add(Actor& actor)
94 {
95   GetImplementation(*this).Add(GetImplementation(actor));
96 }
97
98 void Stage::Remove(Actor& actor)
99 {
100   GetImplementation(*this).Remove(GetImplementation(actor));
101 }
102
103 RenderTaskList Stage::GetRenderTaskList() const
104 {
105   return RenderTaskList( &GetImplementation(*this).GetRenderTaskList() );
106 }
107
108 Vector2 Stage::GetSize() const
109 {
110   return GetImplementation(*this).GetSize();
111 }
112
113 unsigned int Stage::GetLayerCount() const
114 {
115   return GetImplementation(*this).GetLayerCount();
116 }
117
118 Layer Stage::GetLayer(unsigned int depth) const
119 {
120   return GetImplementation(*this).GetLayer(depth);
121 }
122
123 Layer Stage::GetRootLayer() const
124 {
125   return GetImplementation(*this).GetRootLayer();
126 }
127
128 void Stage::SetBackgroundColor(Vector4 color)
129 {
130   GetImplementation(*this).SetBackgroundColor(color);
131 }
132
133 Vector4 Stage::GetBackgroundColor() const
134 {
135   return GetImplementation(*this).GetBackgroundColor();
136 }
137
138 Vector2 Stage::GetDpi() const
139 {
140   return GetImplementation(*this).GetDpi();
141 }
142
143 ObjectRegistry Stage::GetObjectRegistry() const
144 {
145   Internal::ObjectRegistry& internal = Internal::Stage::GetCurrent()->GetObjectRegistry();
146
147   return ObjectRegistry(&internal);
148 }
149
150 DynamicsWorld Stage::InitializeDynamics(DynamicsWorldConfig config)
151 {
152 #ifdef DYNAMICS_SUPPORT
153   Internal::DynamicsWorldConfigPtr configImpl( &(GetImplementation(config)) );
154
155   return DynamicsWorld( GetImplementation(*this).InitializeDynamics(configImpl).Get() );
156 #else
157   return DynamicsWorld();
158 #endif
159 }
160
161 DynamicsWorld Stage::GetDynamicsWorld()
162 {
163 #ifdef DYNAMICS_SUPPORT
164   return DynamicsWorld( GetImplementation(*this).GetDynamicsWorld().Get() );
165 #else
166   return DynamicsWorld();
167 #endif
168 }
169
170 void Stage::TerminateDynamics()
171 {
172 #ifdef DYNAMICS_SUPPORT
173   GetImplementation(*this).TerminateDynamics();
174 #endif
175 }
176
177 void Stage::KeepRendering( float durationSeconds )
178 {
179   GetImplementation(*this).KeepRendering( durationSeconds );
180 }
181
182 Stage::KeyEventSignalV2& Stage::KeyEventSignal()
183 {
184   return GetImplementation(*this).KeyEventSignal();
185 }
186
187 Stage::EventProcessingFinishedSignalV2& Stage::EventProcessingFinishedSignal()
188 {
189   return GetImplementation(*this).EventProcessingFinishedSignal();
190 }
191
192 Stage::TouchedSignalV2& Stage::TouchedSignal()
193 {
194   return GetImplementation(*this).TouchedSignal();
195 }
196
197
198 Stage::ContextStatusSignal& Stage::ContextLostSignal()
199 {
200   return GetImplementation(*this).ContextLostSignal();
201 }
202
203 Stage::ContextStatusSignal& Stage::ContextRegainedSignal()
204 {
205   return GetImplementation(*this).ContextRegainedSignal();
206 }
207
208 } // namespace Dali