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/framework.h>
28 #include <dali/internal/system/common/singleton-service-impl.h>
29 #include <dali/internal/adaptor/common/lifecycle-controller-impl.h>
30 #include <dali/internal/window-system/common/window-render-surface.h>
35 namespace TizenPlatform
37 class TizenPlatformAbstraction;
54 const float DEFAULT_STEREO_BASE( 65.0f );
56 } // unnamed namespace
58 ApplicationPtr Application::gPreInitializedApplication( NULL );
60 ApplicationPtr Application::New(
63 const std::string& stylesheet,
64 Dali::Application::WINDOW_MODE windowMode,
65 const PositionSize& positionSize,
66 Framework::Type applicationType)
68 ApplicationPtr application ( new Application (argc, argv, stylesheet, windowMode, positionSize, applicationType ) );
72 void Application::PreInitialize( int* argc, char** argv[] )
74 if( !gPreInitializedApplication )
76 gPreInitializedApplication = new Application ( argc, argv, "", Dali::Application::OPAQUE, PositionSize(), Framework::NORMAL );
78 gPreInitializedApplication->CreateWindow(); // Only create window
80 gPreInitializedApplication->mLaunchpadState = Launchpad::PRE_INITIALIZED;
84 Application::Application( int* argc, char** argv[], const std::string& stylesheet,
85 Dali::Application::WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType )
93 mLanguageChangedSignal(),
94 mRegionChangedSignal(),
97 mEventLoop( nullptr ),
98 mFramework( nullptr ),
99 mContextLossConfiguration( Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS ),
100 mCommandLineOptions( nullptr ),
101 mSingletonService( SingletonService::New() ),
102 mAdaptorBuilder( nullptr ),
105 mMainWindowMode( windowMode ),
107 mStylesheet( stylesheet ),
108 mEnvironmentOptions(),
109 mWindowPositionSize( positionSize ),
110 mLaunchpadState( Launchpad::NONE ),
111 mSlotDelegate( this ),
113 mStereoBase( DEFAULT_STEREO_BASE )
115 // Get mName from environment options
116 mMainWindowName = mEnvironmentOptions.GetWindowName();
117 if( mMainWindowName.empty() && argc && ( *argc > 0 ) )
119 // Set mName from command-line args if environment option not set
120 mMainWindowName = (*argv)[0];
123 mCommandLineOptions = new CommandLineOptions(argc, argv);
124 mFramework = new Framework( *this, argc, argv, applicationType );
125 mUseRemoteSurface = (applicationType == Framework::WATCH);
128 Application::~Application()
130 mSingletonService.UnregisterAll();
134 delete mAdaptorBuilder;
135 delete mCommandLineOptions;
139 void Application::CreateWindow()
141 if( mWindowPositionSize.width == 0 && mWindowPositionSize.height == 0 )
143 if( mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0 )
145 // Command line options override environment options and full screen
146 mWindowPositionSize.width = mCommandLineOptions->stageWidth;
147 mWindowPositionSize.height = mCommandLineOptions->stageHeight;
149 else if( mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight() )
151 // Environment options override full screen functionality if command line arguments not provided
152 mWindowPositionSize.width = mEnvironmentOptions.GetWindowWidth();
153 mWindowPositionSize.height = mEnvironmentOptions.GetWindowHeight();
157 const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName();
158 mMainWindow = Dali::Window::New( mWindowPositionSize, mMainWindowName, windowClassName, mMainWindowMode == Dali::Application::TRANSPARENT );
160 int indicatorVisibleMode = mEnvironmentOptions.GetIndicatorVisibleMode();
161 if( indicatorVisibleMode >= Dali::Window::INVISIBLE && indicatorVisibleMode <= Dali::Window::AUTO )
163 GetImplementation( mMainWindow ).SetIndicatorVisibleMode( static_cast< Dali::Window::IndicatorVisibleMode >( indicatorVisibleMode ) );
166 // Quit the application when the window is closed
167 GetImplementation( mMainWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit );
170 void Application::CreateAdaptor()
172 DALI_ASSERT_ALWAYS( mMainWindow && "Window required to create adaptor" );
174 auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
176 mAdaptor = Dali::Internal::Adaptor::Adaptor::New( graphicsFactory, mMainWindow, mContextLossConfiguration, &mEnvironmentOptions );
178 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
180 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( mUseRemoteSurface );
183 void Application::CreateAdaptorBuilder()
185 mAdaptorBuilder = new AdaptorBuilder();
188 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
190 mContextLossConfiguration = configuration;
192 // Run the application
196 void Application::Lower()
198 // Lower the application without quitting it.
202 void Application::Quit()
204 // Actually quit the application.
205 // Force a call to Quit even if adaptor is not running.
206 Internal::Adaptor::Adaptor::GetImplementation(*mAdaptor).AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ), false, true );
209 void Application::QuitFromMainLoop()
214 // This will trigger OnTerminate(), below, after the main loop has completed.
217 void Application::DoInit()
219 CreateAdaptorBuilder();
221 // If an application was pre-initialized, a window was made in advance
222 if( mLaunchpadState == Launchpad::NONE )
232 // Check if user requires no vsyncing and set Adaptor
233 if (mCommandLineOptions->noVSyncOnRender)
235 mAdaptor->SetUseHardwareVSync(false);
238 if( ! mStylesheet.empty() )
240 Dali::StyleMonitor::Get().SetTheme( mStylesheet );
244 void Application::DoStart()
246 mAdaptor->NotifySceneCreated();
249 void Application::DoTerminate()
253 // Ensure that the render-thread is not using the surface(window) after we delete it
257 mMainWindow.Reset(); // This only resets (clears) the default Window
260 void Application::DoPause()
265 void Application::DoResume()
270 void Application::DoLanguageChange()
272 mAdaptor->NotifyLanguageChanged();
275 void Application::OnInit()
277 mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
281 // Wire up the LifecycleController
282 Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
284 InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
285 TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
286 PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
287 ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
288 ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
289 ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
290 LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );
292 Dali::Application application(this);
293 mInitSignal.Emit( application );
298 void Application::OnTerminate()
300 // We've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
301 // delete the window as ecore_x has been destroyed by AppCore
303 Dali::Application application(this);
304 mTerminateSignal.Emit( application );
309 void Application::OnPause()
311 // A DALi app should handle Pause/Resume events.
312 // DALi just delivers the framework Pause event to the application, but not actually pause DALi core.
313 // Pausing DALi core only occurs on the Window Hidden framework event
314 Dali::Application application(this);
315 mPauseSignal.Emit( application );
318 void Application::OnResume()
320 // Emit the signal first so the application can queue any messages before we do an update/render
321 // This ensures we do not just redraw the last frame before pausing if that's not required
322 Dali::Application application(this);
323 mResumeSignal.Emit( application );
325 // DALi just delivers the framework Resume event to the application.
326 // Resuming DALi core only occurs on the Window Show framework event
328 // Trigger processing of events queued up while paused
329 CoreEventInterface& coreEventInterface = Internal::Adaptor::Adaptor::GetImplementation( GetAdaptor() );
330 coreEventInterface.ProcessCoreEvents();
333 void Application::OnReset()
336 * usually, reset callback was called when a caller request to launch this application via aul.
337 * because Application class already handled initialization in OnInit(), OnReset do nothing.
339 Dali::Application application(this);
340 mResetSignal.Emit( application );
343 void Application::OnAppControl(void *data)
345 Dali::Application application(this);
346 mAppControlSignal.Emit( application , data );
349 void Application::OnLanguageChanged()
352 Dali::Application application(this);
353 mLanguageChangedSignal.Emit( application );
356 void Application::OnRegionChanged()
358 Dali::Application application(this);
359 mRegionChangedSignal.Emit( application );
362 void Application::OnBatteryLow( Dali::DeviceStatus::Battery::Status status )
364 Dali::Application application(this);
365 mBatteryLowSignal.Emit( application );
367 mLowBatterySignal.Emit( status );
370 void Application::OnMemoryLow( Dali::DeviceStatus::Memory::Status status )
372 Dali::Application application(this);
373 mMemoryLowSignal.Emit( application );
375 mLowMemorySignal.Emit( status );
377 void Application::OnResize(Dali::Adaptor& adaptor)
379 Dali::Application application(this);
380 mResizeSignal.Emit( application );
383 bool Application::AddIdle( CallbackBase* callback, bool hasReturnValue )
385 return mAdaptor->AddIdle( callback, hasReturnValue );
388 std::string Application::GetRegion() const
390 return mFramework->GetRegion();
393 std::string Application::GetLanguage() const
395 return mFramework->GetLanguage();
398 Dali::Adaptor& Application::GetAdaptor()
403 Dali::Window Application::GetWindow()
410 void Application::SetViewMode( ViewMode viewMode )
412 mViewMode = viewMode;
415 ViewMode Application::GetViewMode() const
420 void Application::SetStereoBase( float stereoBase )
422 mStereoBase = stereoBase;
425 float Application::GetStereoBase() const
430 void Application::ReplaceWindow( const PositionSize& positionSize, const std::string& name )
432 Dali::Window newWindow = Dali::Window::New( positionSize, name, mMainWindowMode == Dali::Application::TRANSPARENT );
433 Window& windowImpl = GetImplementation(newWindow);
434 windowImpl.SetAdaptor(*mAdaptor);
436 int indicatorVisibleMode = mEnvironmentOptions.GetIndicatorVisibleMode();
437 if( indicatorVisibleMode >= Dali::Window::INVISIBLE && indicatorVisibleMode <= Dali::Window::AUTO )
439 GetImplementation( newWindow ).SetIndicatorVisibleMode( static_cast< Dali::Window::IndicatorVisibleMode >( indicatorVisibleMode ) );
442 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
444 Any nativeWindow = newWindow.GetNativeHandle();
445 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(nativeWindow, *renderSurface);
446 mMainWindow = newWindow;
447 mWindowPositionSize = positionSize;
450 std::string Application::GetResourcePath()
452 return Internal::Adaptor::Framework::GetResourcePath();
455 std::string Application::GetDataPath()
457 return Internal::Adaptor::Framework::GetDataPath();
460 void Application::SetStyleSheet( const std::string& stylesheet )
462 mStylesheet = stylesheet;
465 ApplicationPtr Application::GetPreInitializedApplication()
467 return gPreInitializedApplication;
470 } // namespace Adaptor
472 } // namespace Internal