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/devel-api/text-abstraction/font-client.h>
27 #include <dali/internal/system/common/command-line-options.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-impl.h>
32 #include <dali/internal/window-system/common/window-render-surface.h>
33 #include <dali/internal/window-system/common/render-surface-factory.h>
35 // To disable a macro with the same name from one of OpenGL headers
41 namespace TizenPlatform
43 class TizenPlatformAbstraction;
60 const float DEFAULT_STEREO_BASE( 65.0f );
62 } // unnamed namespace
64 ApplicationPtr Application::gPreInitializedApplication( NULL );
66 ApplicationPtr Application::New(
69 const std::string& stylesheet,
70 Dali::Application::WINDOW_MODE windowMode,
71 const PositionSize& positionSize,
72 Framework::Type applicationType)
74 ApplicationPtr application ( new Application (argc, argv, stylesheet, windowMode, positionSize, applicationType ) );
78 void Application::PreInitialize( int* argc, char** argv[] )
80 if( !gPreInitializedApplication )
82 gPreInitializedApplication = new Application ( argc, argv, "", Dali::Application::OPAQUE, PositionSize(), Framework::NORMAL );
84 gPreInitializedApplication->CreateWindow(); // Only create window
86 gPreInitializedApplication->mLaunchpadState = Launchpad::PRE_INITIALIZED;
88 //Make DefaultFontDescription cached
89 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
90 Dali::TextAbstraction::FontDescription defaultFontDescription;
91 fontClient.GetDefaultPlatformFontDescription( defaultFontDescription );
95 Application::Application( int* argc, char** argv[], const std::string& stylesheet,
96 Dali::Application::WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType )
104 mLanguageChangedSignal(),
105 mRegionChangedSignal(),
108 mEventLoop( nullptr ),
109 mFramework( nullptr ),
110 mContextLossConfiguration( Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS ),
111 mCommandLineOptions( nullptr ),
112 mSingletonService( SingletonService::New() ),
113 mAdaptorBuilder( nullptr ),
116 mMainWindowMode( windowMode ),
118 mMainWindowReplaced( false ),
119 mStylesheet( stylesheet ),
120 mEnvironmentOptions(),
121 mWindowPositionSize( positionSize ),
122 mLaunchpadState( Launchpad::NONE ),
123 mSlotDelegate( this ),
125 mStereoBase( DEFAULT_STEREO_BASE )
127 // Get mName from environment options
128 mMainWindowName = mEnvironmentOptions.GetWindowName();
129 if( mMainWindowName.empty() && argc && ( *argc > 0 ) )
131 // Set mName from command-line args if environment option not set
132 mMainWindowName = (*argv)[0];
135 mCommandLineOptions = new CommandLineOptions(argc, argv);
136 mFramework = new Framework( *this, argc, argv, applicationType );
137 mUseRemoteSurface = (applicationType == Framework::WATCH);
140 Application::~Application()
142 mSingletonService.UnregisterAll();
146 delete mAdaptorBuilder;
147 delete mCommandLineOptions;
151 void Application::CreateWindow()
153 if( mWindowPositionSize.width == 0 && mWindowPositionSize.height == 0 )
155 if( mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0 )
157 // Command line options override environment options and full screen
158 mWindowPositionSize.width = mCommandLineOptions->stageWidth;
159 mWindowPositionSize.height = mCommandLineOptions->stageHeight;
161 else if( mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight() )
163 // Environment options override full screen functionality if command line arguments not provided
164 mWindowPositionSize.width = mEnvironmentOptions.GetWindowWidth();
165 mWindowPositionSize.height = mEnvironmentOptions.GetWindowHeight();
169 const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName();
171 Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( mWindowPositionSize, mMainWindowName, windowClassName, mMainWindowMode == Dali::Application::TRANSPARENT );
172 mMainWindow = Dali::Window( window );
174 // Quit the application when the window is closed
175 GetImplementation( mMainWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit );
178 void Application::CreateAdaptor()
180 DALI_ASSERT_ALWAYS( mMainWindow && "Window required to create adaptor" );
182 auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
184 Integration::SceneHolder sceneHolder = Integration::SceneHolder( &Dali::GetImplementation( mMainWindow ) );
186 mAdaptor = Adaptor::New( graphicsFactory, sceneHolder, mContextLossConfiguration, &mEnvironmentOptions );
188 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
190 Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( mUseRemoteSurface );
193 void Application::CreateAdaptorBuilder()
195 mAdaptorBuilder = new AdaptorBuilder();
198 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
200 mContextLossConfiguration = configuration;
202 // Run the application
206 void Application::Lower()
208 // Lower the application without quitting it.
212 void Application::Quit()
214 // Actually quit the application.
215 // Force a call to Quit even if adaptor is not running.
216 Internal::Adaptor::Adaptor::GetImplementation(*mAdaptor).AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ), false, true );
219 void Application::QuitFromMainLoop()
224 // This will trigger OnTerminate(), below, after the main loop has completed.
227 void Application::OnInit()
229 mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
231 CreateAdaptorBuilder();
233 // If an application was pre-initialized, a window was made in advance
234 if( mLaunchpadState == Launchpad::NONE )
244 // Check if user requires no vsyncing and set Adaptor
245 if (mCommandLineOptions->noVSyncOnRender)
247 mAdaptor->SetUseHardwareVSync(false);
250 if( ! mStylesheet.empty() )
252 Dali::StyleMonitor::Get().SetTheme( mStylesheet );
255 // Wire up the LifecycleController
256 Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
258 InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
259 TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
260 PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
261 ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
262 ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
263 ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
264 LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );
266 Dali::Application application(this);
267 mInitSignal.Emit( application );
269 mAdaptor->NotifySceneCreated();
272 void Application::OnTerminate()
274 // We've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
275 // delete the window as ecore_x has been destroyed by AppCore
277 Dali::Application application(this);
278 mTerminateSignal.Emit( application );
282 // Ensure that the render-thread is not using the surface(window) after we delete it
286 mMainWindow.Reset(); // This only resets (clears) the default Window
289 void Application::OnPause()
291 // A DALi app should handle Pause/Resume events.
292 // DALi just delivers the framework Pause event to the application, but not actually pause DALi core.
293 // Pausing DALi core only occurs on the Window Hidden framework event
294 Dali::Application application(this);
295 mPauseSignal.Emit( application );
298 void Application::OnResume()
300 // Emit the signal first so the application can queue any messages before we do an update/render
301 // This ensures we do not just redraw the last frame before pausing if that's not required
302 Dali::Application application(this);
303 mResumeSignal.Emit( application );
305 // DALi just delivers the framework Resume event to the application.
306 // Resuming DALi core only occurs on the Window Show framework event
308 // Trigger processing of events queued up while paused
309 CoreEventInterface& coreEventInterface = Internal::Adaptor::Adaptor::GetImplementation( GetAdaptor() );
310 coreEventInterface.ProcessCoreEvents();
313 void Application::OnReset()
316 * usually, reset callback was called when a caller request to launch this application via aul.
317 * because Application class already handled initialization in OnInit(), OnReset do nothing.
319 Dali::Application application(this);
320 mResetSignal.Emit( application );
323 void Application::OnAppControl(void *data)
325 Dali::Application application(this);
326 mAppControlSignal.Emit( application , data );
329 void Application::OnLanguageChanged()
331 mAdaptor->NotifyLanguageChanged();
332 Dali::Application application(this);
333 mLanguageChangedSignal.Emit( application );
336 void Application::OnRegionChanged()
338 Dali::Application application(this);
339 mRegionChangedSignal.Emit( application );
342 void Application::OnBatteryLow( Dali::DeviceStatus::Battery::Status status )
344 Dali::Application application(this);
345 mBatteryLowSignal.Emit( application );
347 mLowBatterySignal.Emit( status );
350 void Application::OnMemoryLow( Dali::DeviceStatus::Memory::Status status )
352 Dali::Application application(this);
353 mMemoryLowSignal.Emit( application );
355 mLowMemorySignal.Emit( status );
358 void Application::OnResize(Dali::Adaptor& adaptor)
360 Dali::Application application(this);
361 mResizeSignal.Emit( application );
364 bool Application::AddIdle( CallbackBase* callback, bool hasReturnValue )
366 return mAdaptor->AddIdle( callback, hasReturnValue );
369 std::string Application::GetRegion() const
371 return mFramework->GetRegion();
374 std::string Application::GetLanguage() const
376 return mFramework->GetLanguage();
379 Dali::Adaptor& Application::GetAdaptor()
384 Dali::Window Application::GetWindow()
386 // Changed to return a different window handle after ReplaceWindow is called
387 // just for backward compatibility to make the test case pass
388 if ( mMainWindowReplaced )
390 Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( PositionSize(), "ReplacedWindow", "", false );
391 return Dali::Window( window );
401 void Application::SetViewMode( ViewMode viewMode )
403 mViewMode = viewMode;
406 ViewMode Application::GetViewMode() const
411 void Application::SetStereoBase( float stereoBase )
413 mStereoBase = stereoBase;
416 float Application::GetStereoBase() const
421 void Application::ReplaceWindow( const PositionSize& positionSize, const std::string& name )
423 // This API is kept just for backward compatibility to make the test case pass.
425 mMainWindowReplaced = true;
426 OnResize( *mAdaptor );
429 std::string Application::GetResourcePath()
431 return Internal::Adaptor::Framework::GetResourcePath();
434 std::string Application::GetDataPath()
436 return Internal::Adaptor::Framework::GetDataPath();
439 void Application::SetStyleSheet( const std::string& stylesheet )
441 mStylesheet = stylesheet;
444 ApplicationPtr Application::GetPreInitializedApplication()
446 return gPreInitializedApplication;
449 } // namespace Adaptor
451 } // namespace Internal