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;
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(),
90 mEventLoop( nullptr ),
91 mFramework( nullptr ),
92 mContextLossConfiguration( Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS ),
93 mCommandLineOptions( nullptr ),
94 mSingletonService( SingletonService::New() ),
95 mAdaptorBuilder( nullptr ),
98 mMainWindowMode( windowMode ),
100 mStylesheet( stylesheet ),
101 mEnvironmentOptions(),
102 mWindowPositionSize( positionSize ),
103 mLaunchpadState( Launchpad::NONE ),
104 mSlotDelegate( this )
106 // Get mName from environment options
107 mMainWindowName = mEnvironmentOptions.GetWindowName();
108 if( mMainWindowName.empty() && argc && ( *argc > 0 ) )
110 // Set mName from command-line args if environment option not set
111 mMainWindowName = (*argv)[0];
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 mAdaptorBuilder;
126 delete mCommandLineOptions;
130 void Application::CreateWindow()
132 if( mWindowPositionSize.width == 0 && mWindowPositionSize.height == 0 )
134 if( mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0 )
136 // Command line options override environment options and full screen
137 mWindowPositionSize.width = mCommandLineOptions->stageWidth;
138 mWindowPositionSize.height = mCommandLineOptions->stageHeight;
140 else if( mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight() )
142 // Environment options override full screen functionality if command line arguments not provided
143 mWindowPositionSize.width = mEnvironmentOptions.GetWindowWidth();
144 mWindowPositionSize.height = mEnvironmentOptions.GetWindowHeight();
148 const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName();
149 mMainWindow = Dali::Window::New( mWindowPositionSize, mMainWindowName, windowClassName, mMainWindowMode == Dali::Application::TRANSPARENT );
151 int indicatorVisibleMode = mEnvironmentOptions.GetIndicatorVisibleMode();
152 if( indicatorVisibleMode >= Dali::Window::INVISIBLE && indicatorVisibleMode <= Dali::Window::AUTO )
154 GetImplementation( mMainWindow ).SetIndicatorVisibleMode( static_cast< Dali::Window::IndicatorVisibleMode >( indicatorVisibleMode ) );
157 // Quit the application when the window is closed
158 GetImplementation( mMainWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit );
161 void Application::CreateAdaptor()
163 DALI_ASSERT_ALWAYS( mMainWindow && "Window required to create adaptor" );
165 auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
167 mAdaptor = Dali::Internal::Adaptor::Adaptor::New( graphicsFactory, mMainWindow, mContextLossConfiguration, &mEnvironmentOptions );
169 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
171 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( mUseRemoteSurface );
174 void Application::CreateAdaptorBuilder()
176 mAdaptorBuilder = new AdaptorBuilder();
179 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
181 mContextLossConfiguration = configuration;
183 // Run the application
187 void Application::Lower()
189 // Lower the application without quitting it.
193 void Application::Quit()
195 // Actually quit the application.
196 // Force a call to Quit even if adaptor is not running.
197 Internal::Adaptor::Adaptor::GetImplementation(*mAdaptor).AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ), false, true );
200 void Application::QuitFromMainLoop()
205 // This will trigger OnTerminate(), below, after the main loop has completed.
208 void Application::DoInit()
210 CreateAdaptorBuilder();
212 // If an application was pre-initialized, a window was made in advance
213 if( mLaunchpadState == Launchpad::NONE )
223 // Check if user requires no vsyncing and set Adaptor
224 if (mCommandLineOptions->noVSyncOnRender)
226 mAdaptor->SetUseHardwareVSync(false);
229 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
230 if( mCommandLineOptions->viewMode != 0 )
232 ViewMode viewMode = MONO;
233 if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
235 viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
237 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
240 if( ! mStylesheet.empty() )
242 Dali::StyleMonitor::Get().SetTheme( mStylesheet );
246 void Application::DoStart()
248 mAdaptor->NotifySceneCreated();
251 void Application::DoTerminate()
255 // Ensure that the render-thread is not using the surface(window) after we delete it
259 mMainWindow.Reset(); // This only resets (clears) the default Window
262 void Application::DoPause()
267 void Application::DoResume()
272 void Application::DoLanguageChange()
274 mAdaptor->NotifyLanguageChanged();
277 void Application::OnInit()
279 mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
283 // Wire up the LifecycleController
284 Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
286 InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
287 TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
288 PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
289 ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
290 ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
291 ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
292 LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );
294 Dali::Application application(this);
295 mInitSignal.Emit( application );
300 void Application::OnTerminate()
302 // We've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
303 // delete the window as ecore_x has been destroyed by AppCore
305 Dali::Application application(this);
306 mTerminateSignal.Emit( application );
311 void Application::OnPause()
313 // A DALi app should handle Pause/Resume events.
314 // DALi just delivers the framework Pause event to the application, but not actually pause DALi core.
315 // Pausing DALi core only occurs on the Window Hidden framework event
316 Dali::Application application(this);
317 mPauseSignal.Emit( application );
320 void Application::OnResume()
322 // Emit the signal first so the application can queue any messages before we do an update/render
323 // This ensures we do not just redraw the last frame before pausing if that's not required
324 Dali::Application application(this);
325 mResumeSignal.Emit( application );
327 // DALi just delivers the framework Resume event to the application.
328 // Resuming DALi core only occurs on the Window Show framework event
330 // Trigger processing of events queued up while paused
331 CoreEventInterface& coreEventInterface = Internal::Adaptor::Adaptor::GetImplementation( GetAdaptor() );
332 coreEventInterface.ProcessCoreEvents();
335 void Application::OnReset()
338 * usually, reset callback was called when a caller request to launch this application via aul.
339 * because Application class already handled initialization in OnInit(), OnReset do nothing.
341 Dali::Application application(this);
342 mResetSignal.Emit( application );
345 void Application::OnAppControl(void *data)
347 Dali::Application application(this);
348 mAppControlSignal.Emit( application , data );
351 void Application::OnLanguageChanged()
354 Dali::Application application(this);
355 mLanguageChangedSignal.Emit( application );
358 void Application::OnRegionChanged()
360 Dali::Application application(this);
361 mRegionChangedSignal.Emit( application );
364 void Application::OnBatteryLow( Dali::DeviceStatus::Battery::Status status )
366 Dali::Application application(this);
367 mBatteryLowSignal.Emit( application );
369 mLowBatterySignal.Emit( status );
372 void Application::OnMemoryLow( Dali::DeviceStatus::Memory::Status status )
374 Dali::Application application(this);
375 mMemoryLowSignal.Emit( application );
377 mLowMemorySignal.Emit( status );
379 void Application::OnResize(Dali::Adaptor& adaptor)
381 Dali::Application application(this);
382 mResizeSignal.Emit( application );
385 bool Application::AddIdle( CallbackBase* callback, bool hasReturnValue )
387 return mAdaptor->AddIdle( callback, hasReturnValue );
390 std::string Application::GetRegion() const
392 return mFramework->GetRegion();
395 std::string Application::GetLanguage() const
397 return mFramework->GetLanguage();
400 Dali::Adaptor& Application::GetAdaptor()
405 Dali::Window Application::GetWindow()
412 void Application::SetViewMode( ViewMode viewMode )
414 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
417 ViewMode Application::GetViewMode() const
419 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
422 void Application::SetStereoBase( float stereoBase )
424 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
427 float Application::GetStereoBase() const
429 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
432 void Application::ReplaceWindow( const PositionSize& positionSize, const std::string& name )
434 Dali::Window newWindow = Dali::Window::New( positionSize, name, mMainWindowMode == Dali::Application::TRANSPARENT );
435 Window& windowImpl = GetImplementation(newWindow);
436 windowImpl.SetAdaptor(*mAdaptor);
438 int indicatorVisibleMode = mEnvironmentOptions.GetIndicatorVisibleMode();
439 if( indicatorVisibleMode >= Dali::Window::INVISIBLE && indicatorVisibleMode <= Dali::Window::AUTO )
441 GetImplementation( newWindow ).SetIndicatorVisibleMode( static_cast< Dali::Window::IndicatorVisibleMode >( indicatorVisibleMode ) );
444 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
446 Any nativeWindow = newWindow.GetNativeHandle();
447 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(nativeWindow, *renderSurface);
448 mMainWindow = newWindow;
449 mWindowPositionSize = positionSize;
452 std::string Application::GetResourcePath()
454 return Internal::Adaptor::Framework::GetResourcePath();
457 void Application::SetStyleSheet( const std::string& stylesheet )
459 mStylesheet = stylesheet;
462 ApplicationPtr Application::GetPreInitializedApplication()
464 return gPreInitializedApplication;
467 } // namespace Adaptor
469 } // namespace Internal