2 * Copyright (c) 2018 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>
31 #include <dali/internal/window-system/common/window-render-surface.h>
36 namespace TizenPlatform
38 class TizenPlatformAbstraction;
52 ApplicationPtr Application::gPreInitializedApplication( NULL );
54 ApplicationPtr Application::New(
57 const std::string& stylesheet,
58 Dali::Application::WINDOW_MODE windowMode,
59 const PositionSize& positionSize,
60 Framework::Type applicationType)
62 ApplicationPtr application ( new Application (argc, argv, stylesheet, windowMode, positionSize, applicationType ) );
66 void Application::PreInitialize( int* argc, char** argv[] )
68 if( !gPreInitializedApplication )
70 gPreInitializedApplication = new Application ( argc, argv, "", Dali::Application::OPAQUE, PositionSize(), Framework::NORMAL );
72 gPreInitializedApplication->CreateWindow(); // Only create window
74 gPreInitializedApplication->mLaunchpadState = Launchpad::PRE_INITIALIZED;
78 Application::Application( int* argc, char** argv[], const std::string& stylesheet,
79 Dali::Application::WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType )
87 mLanguageChangedSignal(),
88 mRegionChangedSignal(),
93 mContextLossConfiguration( Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS ),
94 mCommandLineOptions( NULL ),
95 mSingletonService( SingletonService::New() ),
98 mWindowMode( windowMode ),
100 mStylesheet( stylesheet ),
101 mEnvironmentOptions(),
102 mWindowPositionSize( positionSize ),
103 mLaunchpadState( Launchpad::NONE ),
104 mSlotDelegate( this )
106 // Get mName from environment options
107 mName = mEnvironmentOptions.GetWindowName();
108 if( mName.empty() && argc && ( *argc > 0 ) )
110 // Set mName from command-line args if environment option not set
114 mCommandLineOptions = new CommandLineOptions(argc, argv);
115 mFramework = new Framework( *this, argc, argv, applicationType );
116 mUseRemoteSurface = (applicationType == Framework::WATCH);
119 Application::~Application()
121 mSingletonService.UnregisterAll();
125 delete mCommandLineOptions;
129 void Application::CreateWindow()
131 if( mWindowPositionSize.width == 0 && mWindowPositionSize.height == 0 )
133 if( mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0 )
135 // Command line options override environment options and full screen
136 mWindowPositionSize.width = mCommandLineOptions->stageWidth;
137 mWindowPositionSize.height = mCommandLineOptions->stageHeight;
139 else if( mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight() )
141 // Environment options override full screen functionality if command line arguments not provided
142 mWindowPositionSize.width = mEnvironmentOptions.GetWindowWidth();
143 mWindowPositionSize.height = mEnvironmentOptions.GetWindowHeight();
147 const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName();
148 mWindow = Dali::Window::New( mWindowPositionSize, mName, windowClassName, mWindowMode == Dali::Application::TRANSPARENT );
150 int indicatorVisibleMode = mEnvironmentOptions.GetIndicatorVisibleMode();
151 if( indicatorVisibleMode >= Dali::Window::INVISIBLE && indicatorVisibleMode <= Dali::Window::AUTO )
153 GetImplementation( mWindow ).SetIndicatorVisibleMode( static_cast< Dali::Window::IndicatorVisibleMode >( indicatorVisibleMode ) );
156 // Quit the application when the window is closed
157 GetImplementation( mWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit );
160 void Application::CreateAdaptor()
162 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
164 mAdaptor = Dali::Internal::Adaptor::Adaptor::New( mWindow, mContextLossConfiguration, &mEnvironmentOptions );
166 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
168 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( mUseRemoteSurface );
171 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
173 mContextLossConfiguration = configuration;
175 // Run the application
179 void Application::Lower()
181 // Lower the application without quitting it.
185 void Application::Quit()
187 // Actually quit the application.
188 // Force a call to Quit even if adaptor is not running.
189 Internal::Adaptor::Adaptor::GetImplementation(*mAdaptor).AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ), false, true );
192 void Application::QuitFromMainLoop()
197 // This will trigger OnTerminate(), below, after the main loop has completed.
200 void Application::DoInit()
202 // If an application was pre-initialized, a window was made in advance
203 if( mLaunchpadState == Launchpad::NONE )
213 // Check if user requires no vsyncing and set Adaptor
214 if (mCommandLineOptions->noVSyncOnRender)
216 mAdaptor->SetUseHardwareVSync(false);
219 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
220 if( mCommandLineOptions->viewMode != 0 )
222 ViewMode viewMode = MONO;
223 if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
225 viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
227 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
230 if( ! mStylesheet.empty() )
232 Dali::StyleMonitor::Get().SetTheme( mStylesheet );
236 void Application::DoStart()
238 mAdaptor->NotifySceneCreated();
241 void Application::DoTerminate()
245 // Ensure that the render-thread is not using the surface(window) after we delete it
252 void Application::DoPause()
257 void Application::DoResume()
262 void Application::DoLanguageChange()
264 mAdaptor->NotifyLanguageChanged();
267 void Application::OnInit()
269 mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
273 // Wire up the LifecycleController
274 Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
276 InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
277 TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
278 PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
279 ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
280 ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
281 ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
282 LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );
284 Dali::Application application(this);
285 mInitSignal.Emit( application );
290 void Application::OnTerminate()
292 // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
293 // delete the window as ecore_x has been destroyed by AppCore
295 Dali::Application application(this);
296 mTerminateSignal.Emit( application );
301 void Application::OnPause()
303 // A DALi app should handle Pause/Resume events.
304 // DALi just delivers the framework Pause event to the application, but not actually pause DALi core.
305 // Pausing DALi core only occurs on the Window Hidden framework event
306 Dali::Application application(this);
307 mPauseSignal.Emit( application );
310 void Application::OnResume()
312 // Emit the signal first so the application can queue any messages before we do an update/render
313 // This ensures we do not just redraw the last frame before pausing if that's not required
314 Dali::Application application(this);
315 mResumeSignal.Emit( application );
317 // DALi just delivers the framework Resume event to the application.
318 // Resuming DALi core only occurs on the Window Show framework event
320 // Trigger processing of events queued up while paused
321 CoreEventInterface& coreEventInterface = Internal::Adaptor::Adaptor::GetImplementation( GetAdaptor() );
322 coreEventInterface.ProcessCoreEvents();
325 void Application::OnReset()
328 * usually, reset callback was called when a caller request to launch this application via aul.
329 * because Application class already handled initialization in OnInit(), OnReset do nothing.
331 Dali::Application application(this);
332 mResetSignal.Emit( application );
335 void Application::OnAppControl(void *data)
337 Dali::Application application(this);
338 mAppControlSignal.Emit( application , data );
341 void Application::OnLanguageChanged()
344 Dali::Application application(this);
345 mLanguageChangedSignal.Emit( application );
348 void Application::OnRegionChanged()
350 Dali::Application application(this);
351 mRegionChangedSignal.Emit( application );
354 void Application::OnBatteryLow( Dali::DeviceStatus::Battery::Status status )
356 Dali::Application application(this);
357 mBatteryLowSignal.Emit( application );
359 mLowBatterySignal.Emit( status );
362 void Application::OnMemoryLow( Dali::DeviceStatus::Memory::Status status )
364 Dali::Application application(this);
365 mMemoryLowSignal.Emit( application );
367 mLowMemorySignal.Emit( status );
369 void Application::OnResize(Dali::Adaptor& adaptor)
371 Dali::Application application(this);
372 mResizeSignal.Emit( application );
375 bool Application::AddIdle( CallbackBase* callback, bool hasReturnValue )
377 return mAdaptor->AddIdle( callback, hasReturnValue );
380 std::string Application::GetRegion() const
382 return mFramework->GetRegion();
385 std::string Application::GetLanguage() const
387 return mFramework->GetLanguage();
390 Dali::Adaptor& Application::GetAdaptor()
395 Dali::Window Application::GetWindow()
402 void Application::SetViewMode( ViewMode viewMode )
404 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
407 ViewMode Application::GetViewMode() const
409 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
412 void Application::SetStereoBase( float stereoBase )
414 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
417 float Application::GetStereoBase() const
419 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
423 void Application::ReplaceWindow( const PositionSize& positionSize, const std::string& name )
425 Dali::Window newWindow = Dali::Window::New( positionSize, name, mWindowMode == Dali::Application::TRANSPARENT );
426 Window& windowImpl = GetImplementation(newWindow);
427 windowImpl.SetAdaptor(*mAdaptor);
429 int indicatorVisibleMode = mEnvironmentOptions.GetIndicatorVisibleMode();
430 if( indicatorVisibleMode >= Dali::Window::INVISIBLE && indicatorVisibleMode <= Dali::Window::AUTO )
432 GetImplementation( newWindow ).SetIndicatorVisibleMode( static_cast< Dali::Window::IndicatorVisibleMode >( indicatorVisibleMode ) );
435 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
437 Any nativeWindow = newWindow.GetNativeHandle();
438 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(nativeWindow, *renderSurface);
440 mWindowPositionSize = positionSize;
443 std::string Application::GetResourcePath()
445 return Internal::Adaptor::Framework::GetResourcePath();
448 void Application::SetStyleSheet( const std::string& stylesheet )
450 mStylesheet = stylesheet;
454 ApplicationPtr Application::GetPreInitializedApplication()
456 return gPreInitializedApplication;
459 } // namespace Adaptor
461 } // namespace Internal