2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/adaptor/common/application-impl.h>
22 #include <dali/integration-api/debug.h>
25 #include <dali/devel-api/adaptor-framework/style-monitor.h>
26 #include <dali/internal/system/common/command-line-options.h>
27 #include <dali/internal/adaptor/common/adaptor-impl.h>
28 #include <dali/internal/adaptor/common/framework.h>
29 #include <dali/internal/system/common/singleton-service-impl.h>
30 #include <dali/internal/adaptor/common/lifecycle-controller-impl.h>
35 namespace TizenPlatform
37 class TizenPlatformAbstraction;
51 ApplicationPtr Application::gPreInitializedApplication( NULL );
53 ApplicationPtr Application::New(
56 const std::string& stylesheet,
57 Dali::Application::WINDOW_MODE windowMode,
58 const PositionSize& positionSize,
59 Framework::Type applicationType)
61 ApplicationPtr application ( new Application (argc, argv, stylesheet, windowMode, positionSize, applicationType ) );
65 void Application::PreInitialize( int* argc, char** argv[] )
67 if( !gPreInitializedApplication )
69 gPreInitializedApplication = new Application ( argc, argv, "", Dali::Application::OPAQUE, PositionSize(), Framework::NORMAL );
71 gPreInitializedApplication->CreateWindow(); // Only create window
73 gPreInitializedApplication->mLaunchpadState = Launchpad::PRE_INITIALIZED;
77 Application::Application( int* argc, char** argv[], const std::string& stylesheet,
78 Dali::Application::WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType )
86 mLanguageChangedSignal(),
87 mRegionChangedSignal(),
92 mContextLossConfiguration( Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS ),
93 mCommandLineOptions( NULL ),
94 mSingletonService( SingletonService::New() ),
97 mWindowMode( windowMode ),
99 mStylesheet( stylesheet ),
100 mEnvironmentOptions(),
101 mWindowPositionSize( positionSize ),
102 mLaunchpadState( Launchpad::NONE ),
103 mSlotDelegate( this )
105 // Get mName from environment options
106 mName = mEnvironmentOptions.GetWindowName();
107 if( mName.empty() && argc && ( *argc > 0 ) )
109 // Set mName from command-line args if environment option not set
113 mCommandLineOptions = new CommandLineOptions(argc, argv);
114 mFramework = new Framework( *this, argc, argv, applicationType );
115 mUseRemoteSurface = (applicationType == Framework::WATCH);
118 Application::~Application()
120 mSingletonService.UnregisterAll();
124 delete mCommandLineOptions;
128 void Application::CreateWindow()
130 if( mWindowPositionSize.width == 0 && mWindowPositionSize.height == 0 )
132 if( mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0 )
134 // Command line options override environment options and full screen
135 mWindowPositionSize.width = mCommandLineOptions->stageWidth;
136 mWindowPositionSize.height = mCommandLineOptions->stageHeight;
138 else if( mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight() )
140 // Environment options override full screen functionality if command line arguments not provided
141 mWindowPositionSize.width = mEnvironmentOptions.GetWindowWidth();
142 mWindowPositionSize.height = mEnvironmentOptions.GetWindowHeight();
146 const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName();
147 mWindow = Dali::Window::New( mWindowPositionSize, mName, windowClassName, mWindowMode == Dali::Application::TRANSPARENT );
149 int indicatorVisibleMode = mEnvironmentOptions.GetIndicatorVisibleMode();
150 if( indicatorVisibleMode >= Dali::Window::INVISIBLE && indicatorVisibleMode <= Dali::Window::AUTO )
152 GetImplementation( mWindow ).SetIndicatorVisibleMode( static_cast< Dali::Window::IndicatorVisibleMode >( indicatorVisibleMode ) );
155 // Quit the application when the window is closed
156 GetImplementation( mWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit );
159 void Application::CreateAdaptor()
161 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
163 mAdaptor = Dali::Internal::Adaptor::Adaptor::New( mWindow, mContextLossConfiguration, &mEnvironmentOptions );
165 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
167 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( mUseRemoteSurface );
170 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
172 mContextLossConfiguration = configuration;
174 // Run the application
178 void Application::Lower()
180 // Lower the application without quitting it.
184 void Application::Quit()
186 // Actually quit the application.
187 // Force a call to Quit even if adaptor is not running.
188 Internal::Adaptor::Adaptor::GetImplementation(*mAdaptor).AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ), true );
191 void Application::QuitFromMainLoop()
196 // This will trigger OnTerminate(), below, after the main loop has completed.
199 void Application::DoInit()
201 // If an application was pre-initialized, a window was made in advance
202 if( mLaunchpadState == Launchpad::NONE )
212 // Check if user requires no vsyncing and set Adaptor
213 if (mCommandLineOptions->noVSyncOnRender)
215 mAdaptor->SetUseHardwareVSync(false);
218 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
219 if( mCommandLineOptions->viewMode != 0 )
221 ViewMode viewMode = MONO;
222 if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
224 viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
226 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
229 if( ! mStylesheet.empty() )
231 Dali::StyleMonitor::Get().SetTheme( mStylesheet );
235 void Application::DoStart()
237 mAdaptor->NotifySceneCreated();
240 void Application::DoTerminate()
244 // Ensure that the render-thread is not using the surface(window) after we delete it
251 void Application::DoPause()
256 void Application::DoResume()
261 void Application::DoLanguageChange()
263 mAdaptor->NotifyLanguageChanged();
266 void Application::OnInit()
268 mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
272 // Wire up the LifecycleController
273 Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
275 InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
276 TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
277 PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
278 ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
279 ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
280 ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
281 LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );
283 Dali::Application application(this);
284 mInitSignal.Emit( application );
289 void Application::OnTerminate()
291 // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
292 // delete the window as ecore_x has been destroyed by AppCore
294 Dali::Application application(this);
295 mTerminateSignal.Emit( application );
300 void Application::OnPause()
302 // A DALi app should handle Pause/Resume events.
303 // DALi just delivers the framework Pause event to the application, but not actually pause DALi core.
304 // Pausing DALi core only occurs on the Window Hidden framework event
305 Dali::Application application(this);
306 mPauseSignal.Emit( application );
309 void Application::OnResume()
311 // Emit the signal first so the application can queue any messages before we do an update/render
312 // This ensures we do not just redraw the last frame before pausing if that's not required
313 Dali::Application application(this);
314 mResumeSignal.Emit( application );
316 // DALi just delivers the framework Resume event to the application.
317 // Resuming DALi core only occurs on the Window Show framework event
319 // Trigger processing of events queued up while paused
320 CoreEventInterface& coreEventInterface = Internal::Adaptor::Adaptor::GetImplementation( GetAdaptor() );
321 coreEventInterface.ProcessCoreEvents();
324 void Application::OnReset()
327 * usually, reset callback was called when a caller request to launch this application via aul.
328 * because Application class already handled initialization in OnInit(), OnReset do nothing.
330 Dali::Application application(this);
331 mResetSignal.Emit( application );
334 void Application::OnAppControl(void *data)
336 Dali::Application application(this);
337 mAppControlSignal.Emit( application , data );
340 void Application::OnLanguageChanged()
343 Dali::Application application(this);
344 mLanguageChangedSignal.Emit( application );
347 void Application::OnRegionChanged()
349 Dali::Application application(this);
350 mRegionChangedSignal.Emit( application );
353 void Application::OnBatteryLow( Dali::DeviceStatus::Battery::Status status )
355 Dali::Application application(this);
356 mBatteryLowSignal.Emit( application );
358 mLowBatterySignal.Emit( status );
361 void Application::OnMemoryLow( Dali::DeviceStatus::Memory::Status status )
363 Dali::Application application(this);
364 mMemoryLowSignal.Emit( application );
366 mLowMemorySignal.Emit( status );
368 void Application::OnResize(Dali::Adaptor& adaptor)
370 Dali::Application application(this);
371 mResizeSignal.Emit( application );
374 bool Application::AddIdle( CallbackBase* callback )
376 return mAdaptor->AddIdle( callback );
379 std::string Application::GetRegion() const
381 return mFramework->GetRegion();
384 std::string Application::GetLanguage() const
386 return mFramework->GetLanguage();
389 Dali::Adaptor& Application::GetAdaptor()
394 Dali::Window Application::GetWindow()
401 void Application::SetViewMode( ViewMode viewMode )
403 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
406 ViewMode Application::GetViewMode() const
408 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
411 void Application::SetStereoBase( float stereoBase )
413 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
416 float Application::GetStereoBase() const
418 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
422 void Application::ReplaceWindow( const PositionSize& positionSize, const std::string& name )
424 Dali::Window newWindow = Dali::Window::New( positionSize, name, mWindowMode == Dali::Application::TRANSPARENT );
425 Window& windowImpl = GetImplementation(newWindow);
426 windowImpl.SetAdaptor(*mAdaptor);
428 int indicatorVisibleMode = mEnvironmentOptions.GetIndicatorVisibleMode();
429 if( indicatorVisibleMode >= Dali::Window::INVISIBLE && indicatorVisibleMode <= Dali::Window::AUTO )
431 GetImplementation( newWindow ).SetIndicatorVisibleMode( static_cast< Dali::Window::IndicatorVisibleMode >( indicatorVisibleMode ) );
434 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
436 Any nativeWindow = newWindow.GetNativeHandle();
437 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(nativeWindow, *renderSurface);
439 mWindowPositionSize = positionSize;
442 std::string Application::GetResourcePath()
444 return Internal::Adaptor::Framework::GetResourcePath();
447 void Application::SetStyleSheet( const std::string& stylesheet )
449 mStylesheet = stylesheet;
453 ApplicationPtr Application::GetPreInitializedApplication()
455 return gPreInitializedApplication;
458 } // namespace Adaptor
460 } // namespace Internal