Dali 3D User Interface Engine
application-impl.cpp
Go to the documentation of this file.
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 "application-impl.h"
20 
21 // EXTERNAL INCLUDES
23 
24 // INTERNAL INCLUDES
25 #include <style-monitor.h>
26 #include <command-line-options.h>
27 #include <common/adaptor-impl.h>
28 #include <singleton-service-impl.h>
30 
31 namespace Dali
32 {
33 
34 namespace TizenPlatform
35 {
37 }
38 
39 namespace Integration
40 {
41 class Core;
42 }
43 
44 namespace Internal
45 {
46 
47 namespace Adaptor
48 {
49 
51  int* argc,
52  char **argv[],
53  const std::string& stylesheet,
55 {
56  ApplicationPtr application ( new Application (argc, argv, stylesheet, windowMode ) );
57  return application;
58 }
59 
60 Application::Application( int* argc, char** argv[], const std::string& stylesheet, Dali::Application::WINDOW_MODE windowMode )
61 : mInitSignal(),
62  mTerminateSignal(),
63  mPauseSignal(),
64  mResumeSignal(),
65  mResetSignal(),
66  mResizeSignal(),
67  mAppControlSignal(),
68  mLanguageChangedSignal(),
69  mRegionChangedSignal(),
70  mBatteryLowSignal(),
71  mMemoryLowSignal(),
72  mEventLoop( NULL ),
73  mFramework( NULL ),
74  mContextLossConfiguration( Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS ),
75  mCommandLineOptions( NULL ),
76  mSingletonService( SingletonService::New() ),
77  mAdaptor( NULL ),
78  mWindow(),
79  mWindowMode( windowMode ),
80  mName(),
81  mStylesheet( stylesheet ),
82  mEnvironmentOptions(),
83  mSlotDelegate( this )
84 {
85  // Get mName from environment options
87  if( mName.empty() && argc && ( *argc > 0 ) )
88  {
89  // Set mName from command-line args if environment option not set
90  mName = (*argv)[0];
91  }
92 
93  mCommandLineOptions = new CommandLineOptions(argc, argv);
94 
95  mFramework = new Framework( *this, argc, argv );
96 }
97 
99 {
101 
102  delete mFramework;
103  delete mCommandLineOptions;
104  delete mAdaptor;
105  mWindow.Reset();
106 }
107 
109 {
110  PositionSize windowPosition(0, 0, 0, 0); // this will use full screen
111 
113  {
114  // Command line options override environment options and full screen
116  }
118  {
119  // Environment options override full screen functionality if command line arguments not provided
121  }
122 
123  const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName();
124  mWindow = Dali::Window::New( windowPosition, mName, windowClassName, mWindowMode == Dali::Application::TRANSPARENT );
125 
126  // Quit the application when the window is closed
127  GetImplementation( mWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit );
128 }
129 
131 {
132  DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
133 
135 
136  mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
137 }
138 
140 {
141  mContextLossConfiguration = configuration;
142 
143  // Run the application
144  mFramework->Run();
145 }
146 
148 {
149  // Lower the application without quitting it.
150  mWindow.Lower();
151 }
152 
154 {
155  // Actually quit the application.
157 }
158 
160 {
161  mAdaptor->Stop();
162 
163  Dali::Application application(this);
164  mTerminateSignal.Emit( application );
165 
166  mFramework->Quit();
167  // This will trigger OnTerminate(), below, after the main loop has completed.
168 }
169 
171 {
173 
174  CreateWindow();
175  CreateAdaptor();
176 
177  // Run the adaptor
178  mAdaptor->Start();
179 
180  // Check if user requires no vsyncing and set on X11 Adaptor
182  {
183  mAdaptor->SetUseHardwareVSync(false);
184  }
185 
187  if( mCommandLineOptions->viewMode != 0 )
188  {
189  ViewMode viewMode = MONO;
191  {
192  viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
193  }
195  }
196 
197  if( ! mStylesheet.empty() )
198  {
200  }
201 
202  // Wire up the LifecycleController
203  Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
204 
205  InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
206  TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
207  PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
208  ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
209  ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
210  ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
212 
213  Dali::Application application(this);
214  mInitSignal.Emit( application );
215 
216  mAdaptor->NotifySceneCreated();
217 }
218 
220 {
221  // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
222  // delete the window as ecore_x has been destroyed by AppCore
223 
224  if( mAdaptor )
225  {
226  // Ensure that the render-thread is not using the surface(window) after we delete it
227  mAdaptor->Stop();
228  }
229 
230  mWindow.Reset();
231 }
232 
234 {
235  mAdaptor->Pause();
236  Dali::Application application(this);
237  mPauseSignal.Emit( application );
238 }
239 
241 {
242  // Emit the signal first so the application can queue any messages before we do an update/render
243  // This ensures we do not just redraw the last frame before pausing if that's not required
244  Dali::Application application(this);
245  mResumeSignal.Emit( application );
246  mAdaptor->Resume();
247 }
248 
250 {
251  /*
252  * usually, reset callback was called when a caller request to launch this application via aul.
253  * because Application class already handled initialization in OnInit(), OnReset do nothing.
254  */
255  Dali::Application application(this);
256  mResetSignal.Emit( application );
257 }
258 
260 {
261  Dali::Application application(this);
262  mAppControlSignal.Emit( application , data );
263 }
264 
266 {
267  mAdaptor->NotifyLanguageChanged();
268  Dali::Application application(this);
269  mLanguageChangedSignal.Emit( application );
270 }
271 
273 {
274  Dali::Application application(this);
275  mRegionChangedSignal.Emit( application );
276 }
277 
279 {
280  Dali::Application application(this);
281  mBatteryLowSignal.Emit( application );
282 }
283 
285 {
286  Dali::Application application(this);
287  mMemoryLowSignal.Emit( application );
288 }
289 
290 void Application::OnResize(Dali::Adaptor& adaptor)
291 {
292  Dali::Application application(this);
293  mResizeSignal.Emit( application );
294 }
295 
297 {
298  return mAdaptor->AddIdle( callback );
299 }
300 
301 Dali::Adaptor& Application::GetAdaptor()
302 {
303  return *mAdaptor;
304 }
305 
307 {
308  return mWindow;
309 }
310 
311 // Stereoscopy
312 
314 {
316 }
317 
319 {
321 }
322 
323 void Application::SetStereoBase( float stereoBase )
324 {
326 }
327 
329 {
331 }
332 
333 
334 void Application::ReplaceWindow(PositionSize windowPosition, const std::string& name)
335 {
336  Dali::Window newWindow = Dali::Window::New( windowPosition, name, mWindowMode == Dali::Application::TRANSPARENT );
337  Window& windowImpl = GetImplementation(newWindow);
338  windowImpl.SetAdaptor(*mAdaptor);
340  Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
341 
342  Any nativeWindow = newWindow.GetNativeHandle();
343  Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(nativeWindow, *renderSurface);
344  mWindow = newWindow;
345 }
346 
347 } // namespace Adaptor
348 
349 } // namespace Internal
350 
351 } // namespace Dali
Dali Docs Home
Read more about Dali