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 "application-impl.h"
22 #include <dali/integration-api/debug.h>
25 #include <style-monitor.h>
26 #include <command-line-options.h>
27 #include <common/adaptor-impl.h>
28 #include <common/framework.h>
29 #include <singleton-service-impl.h>
30 #include <lifecycle-controller-impl.h>
35 namespace TizenPlatform
37 class TizenPlatformAbstraction;
51 ApplicationPtr Application::New(
54 const std::string& stylesheet,
55 Dali::Application::WINDOW_MODE windowMode,
56 const PositionSize& positionSize,
57 Framework::Type applicationType)
59 ApplicationPtr application ( new Application (argc, argv, stylesheet, windowMode, positionSize, applicationType ) );
63 Application::Application( int* argc, char** argv[], const std::string& stylesheet,
64 Dali::Application::WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType )
72 mLanguageChangedSignal(),
73 mRegionChangedSignal(),
78 mContextLossConfiguration( Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS ),
79 mCommandLineOptions( NULL ),
80 mSingletonService( SingletonService::New() ),
83 mWindowMode( windowMode ),
85 mStylesheet( stylesheet ),
86 mEnvironmentOptions(),
87 mWindowPositionSize( positionSize ),
90 // Get mName from environment options
91 mName = mEnvironmentOptions.GetWindowName();
92 if( mName.empty() && argc && ( *argc > 0 ) )
94 // Set mName from command-line args if environment option not set
98 mCommandLineOptions = new CommandLineOptions(argc, argv);
99 mFramework = new Framework( *this, argc, argv, applicationType );
100 mUseRemoteSurface = (applicationType == Framework::WATCH);
103 Application::~Application()
105 mSingletonService.UnregisterAll();
109 delete mCommandLineOptions;
113 void Application::CreateWindow()
115 if( mWindowPositionSize.width == 0 && mWindowPositionSize.height == 0 )
117 if( mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0 )
119 // Command line options override environment options and full screen
120 mWindowPositionSize.width = mCommandLineOptions->stageWidth;
121 mWindowPositionSize.height = mCommandLineOptions->stageHeight;
123 else if( mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight() )
125 // Environment options override full screen functionality if command line arguments not provided
126 mWindowPositionSize.width = mEnvironmentOptions.GetWindowWidth();
127 mWindowPositionSize.height = mEnvironmentOptions.GetWindowHeight();
131 const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName();
132 mWindow = Dali::Window::New( mWindowPositionSize, mName, windowClassName, mWindowMode == Dali::Application::TRANSPARENT );
134 // Quit the application when the window is closed
135 GetImplementation( mWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit );
138 void Application::CreateAdaptor()
140 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
142 mAdaptor = Dali::Internal::Adaptor::Adaptor::New( mWindow, mContextLossConfiguration, &mEnvironmentOptions );
144 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
146 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( mUseRemoteSurface );
149 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
151 mContextLossConfiguration = configuration;
153 // Run the application
157 void Application::Lower()
159 // Lower the application without quitting it.
163 void Application::Quit()
165 // Actually quit the application.
166 AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ) );
169 void Application::QuitFromMainLoop()
174 // This will trigger OnTerminate(), below, after the main loop has completed.
177 void Application::DoInit()
185 // Check if user requires no vsyncing and set Adaptor
186 if (mCommandLineOptions->noVSyncOnRender)
188 mAdaptor->SetUseHardwareVSync(false);
191 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
192 if( mCommandLineOptions->viewMode != 0 )
194 ViewMode viewMode = MONO;
195 if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
197 viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
199 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
202 if( ! mStylesheet.empty() )
204 Dali::StyleMonitor::Get().SetTheme( mStylesheet );
208 void Application::DoStart()
210 mAdaptor->NotifySceneCreated();
213 void Application::DoTerminate()
217 // Ensure that the render-thread is not using the surface(window) after we delete it
224 void Application::DoPause()
229 void Application::DoResume()
234 void Application::DoLanguageChange()
236 mAdaptor->NotifyLanguageChanged();
239 void Application::OnInit()
241 mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
245 // Wire up the LifecycleController
246 Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
248 InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
249 TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
250 PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
251 ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
252 ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
253 ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
254 LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );
256 Dali::Application application(this);
257 mInitSignal.Emit( application );
262 void Application::OnTerminate()
264 // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
265 // delete the window as ecore_x has been destroyed by AppCore
267 Dali::Application application(this);
268 mTerminateSignal.Emit( application );
273 void Application::OnPause()
275 // A DALi app should handle Pause/Resume events.
276 // DALi just delivers the framework Pause event to the application, but not actually pause DALi core.
277 // Pausing DALi core only occurs on the Window Hidden framework event
278 Dali::Application application(this);
279 mPauseSignal.Emit( application );
282 void Application::OnResume()
284 // Emit the signal first so the application can queue any messages before we do an update/render
285 // This ensures we do not just redraw the last frame before pausing if that's not required
286 Dali::Application application(this);
287 mResumeSignal.Emit( application );
289 // DALi just delivers the framework Resume event to the application.
290 // Resuming DALi core only occurs on the Window Show framework event
293 void Application::OnReset()
296 * usually, reset callback was called when a caller request to launch this application via aul.
297 * because Application class already handled initialization in OnInit(), OnReset do nothing.
299 Dali::Application application(this);
300 mResetSignal.Emit( application );
303 void Application::OnAppControl(void *data)
305 Dali::Application application(this);
306 mAppControlSignal.Emit( application , data );
309 void Application::OnLanguageChanged()
312 Dali::Application application(this);
313 mLanguageChangedSignal.Emit( application );
316 void Application::OnRegionChanged()
318 Dali::Application application(this);
319 mRegionChangedSignal.Emit( application );
322 void Application::OnBatteryLow()
324 Dali::Application application(this);
325 mBatteryLowSignal.Emit( application );
328 void Application::OnMemoryLow()
330 Dali::Application application(this);
331 mMemoryLowSignal.Emit( application );
334 void Application::OnResize(Dali::Adaptor& adaptor)
336 Dali::Application application(this);
337 mResizeSignal.Emit( application );
340 bool Application::AddIdle( CallbackBase* callback )
342 return mAdaptor->AddIdle( callback );
345 Dali::Adaptor& Application::GetAdaptor()
350 Dali::Window Application::GetWindow()
357 void Application::SetViewMode( ViewMode viewMode )
359 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
362 ViewMode Application::GetViewMode() const
364 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
367 void Application::SetStereoBase( float stereoBase )
369 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
372 float Application::GetStereoBase() const
374 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
378 void Application::ReplaceWindow( const PositionSize& positionSize, const std::string& name )
380 Dali::Window newWindow = Dali::Window::New( positionSize, name, mWindowMode == Dali::Application::TRANSPARENT );
381 Window& windowImpl = GetImplementation(newWindow);
382 windowImpl.SetAdaptor(*mAdaptor);
383 newWindow.ShowIndicator(Dali::Window::INVISIBLE);
384 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
386 Any nativeWindow = newWindow.GetNativeHandle();
387 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SurfaceSizeChanged( Dali::Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
388 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(nativeWindow, *renderSurface);
390 mWindowPositionSize = positionSize;
393 std::string Application::GetResourcePath()
395 return Internal::Adaptor::Framework::GetResourcePath();
398 } // namespace Adaptor
400 } // namespace Internal