2 * Copyright (c) 2016 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 Framework::Type applicationType)
58 ApplicationPtr application ( new Application (argc, argv, stylesheet, windowMode, applicationType ) );
62 Application::Application( int* argc, char** argv[], const std::string& stylesheet,
63 Dali::Application::WINDOW_MODE windowMode, Framework::Type applicationType )
71 mLanguageChangedSignal(),
72 mRegionChangedSignal(),
77 mContextLossConfiguration( Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS ),
78 mCommandLineOptions( NULL ),
79 mSingletonService( SingletonService::New() ),
82 mWindowMode( windowMode ),
84 mStylesheet( stylesheet ),
85 mEnvironmentOptions(),
86 mInitialized( false ),
89 // Get mName from environment options
90 mName = mEnvironmentOptions.GetWindowName();
91 if( mName.empty() && argc && ( *argc > 0 ) )
93 // Set mName from command-line args if environment option not set
97 mCommandLineOptions = new CommandLineOptions(argc, argv);
98 mFramework = new Framework( *this, argc, argv, applicationType );
99 mUseRemoteSurface = (applicationType == Framework::WATCH);
102 Application::~Application()
104 mSingletonService.UnregisterAll();
108 delete mCommandLineOptions;
112 void Application::CreateWindow()
114 PositionSize windowPosition(0, 0, 0, 0); // this will use full screen
116 if( mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0 )
118 // Command line options override environment options and full screen
119 windowPosition = PositionSize( 0, 0, mCommandLineOptions->stageWidth, mCommandLineOptions->stageHeight );
121 else if( mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight() )
123 // Environment options override full screen functionality if command line arguments not provided
124 windowPosition = PositionSize( 0, 0, mEnvironmentOptions.GetWindowWidth(), mEnvironmentOptions.GetWindowHeight() );
127 const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName();
128 mWindow = Dali::Window::New( windowPosition, mName, windowClassName, mWindowMode == Dali::Application::TRANSPARENT );
130 // Quit the application when the window is closed
131 GetImplementation( mWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit );
134 void Application::CreateAdaptor()
136 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
138 mAdaptor = Dali::Internal::Adaptor::Adaptor::New( mWindow, mContextLossConfiguration, &mEnvironmentOptions );
140 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
142 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( mUseRemoteSurface );
145 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
147 mContextLossConfiguration = configuration;
149 // Run the application
153 void Application::Lower()
155 // Lower the application without quitting it.
159 void Application::Quit()
161 // Actually quit the application.
162 AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ) );
165 void Application::QuitFromMainLoop()
170 // This will trigger OnTerminate(), below, after the main loop has completed.
173 void Application::DoInit()
181 // Check if user requires no vsyncing and set Adaptor
182 if (mCommandLineOptions->noVSyncOnRender)
184 mAdaptor->SetUseHardwareVSync(false);
187 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
188 if( mCommandLineOptions->viewMode != 0 )
190 ViewMode viewMode = MONO;
191 if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
193 viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
195 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
198 if( ! mStylesheet.empty() )
200 Dali::StyleMonitor::Get().SetTheme( mStylesheet );
205 mAdaptor->NotifySceneCreated();
210 void Application::DoTerminate()
214 // Ensure that the render-thread is not using the surface(window) after we delete it
221 void Application::DoPause()
226 void Application::DoResume()
231 void Application::DoLanguageChange()
233 mAdaptor->NotifyLanguageChanged();
236 void Application::OnInit()
238 mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
244 // Wire up the LifecycleController
245 Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
247 InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
248 TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
249 PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
250 ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
251 ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
252 ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
253 LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );
255 Dali::Application application(this);
256 mInitSignal.Emit( application );
258 mAdaptor->NotifySceneCreated();
261 void Application::OnTerminate()
263 // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
264 // delete the window as ecore_x has been destroyed by AppCore
266 Dali::Application application(this);
267 mTerminateSignal.Emit( application );
272 void Application::OnPause()
275 Dali::Application application(this);
276 mPauseSignal.Emit( application );
279 void Application::OnResume()
281 // Emit the signal first so the application can queue any messages before we do an update/render
282 // This ensures we do not just redraw the last frame before pausing if that's not required
283 Dali::Application application(this);
284 mResumeSignal.Emit( application );
288 void Application::OnReset()
291 * usually, reset callback was called when a caller request to launch this application via aul.
292 * because Application class already handled initialization in OnInit(), OnReset do nothing.
294 Dali::Application application(this);
295 mResetSignal.Emit( application );
298 void Application::OnAppControl(void *data)
300 Dali::Application application(this);
301 mAppControlSignal.Emit( application , data );
304 void Application::OnLanguageChanged()
307 Dali::Application application(this);
308 mLanguageChangedSignal.Emit( application );
311 void Application::OnRegionChanged()
313 Dali::Application application(this);
314 mRegionChangedSignal.Emit( application );
317 void Application::OnBatteryLow()
319 Dali::Application application(this);
320 mBatteryLowSignal.Emit( application );
323 void Application::OnMemoryLow()
325 Dali::Application application(this);
326 mMemoryLowSignal.Emit( application );
329 void Application::OnResize(Dali::Adaptor& adaptor)
331 Dali::Application application(this);
332 mResizeSignal.Emit( application );
335 bool Application::AddIdle( CallbackBase* callback )
337 return mAdaptor->AddIdle( callback );
340 Dali::Adaptor& Application::GetAdaptor()
345 Dali::Window Application::GetWindow()
352 void Application::SetViewMode( ViewMode viewMode )
354 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
357 ViewMode Application::GetViewMode() const
359 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
362 void Application::SetStereoBase( float stereoBase )
364 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
367 float Application::GetStereoBase() const
369 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
373 void Application::ReplaceWindow(PositionSize windowPosition, const std::string& name)
375 Dali::Window newWindow = Dali::Window::New( windowPosition, name, mWindowMode == Dali::Application::TRANSPARENT );
376 Window& windowImpl = GetImplementation(newWindow);
377 windowImpl.SetAdaptor(*mAdaptor);
378 newWindow.ShowIndicator(Dali::Window::INVISIBLE);
379 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
381 Any nativeWindow = newWindow.GetNativeHandle();
382 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SurfaceSizeChanged( windowPosition );
383 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(nativeWindow, *renderSurface);
387 std::string Application::GetResourcePath()
389 return Internal::Adaptor::Framework::GetResourcePath();
392 } // namespace Adaptor
394 } // namespace Internal