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 <singleton-service-impl.h>
29 #include <lifecycle-controller-impl.h>
34 namespace TizenPlatform
36 class TizenPlatformAbstraction;
50 ApplicationPtr Application::New(
53 const std::string& stylesheet,
54 Dali::Application::WINDOW_MODE windowMode,
55 Framework::Type applicationType)
57 ApplicationPtr application ( new Application (argc, argv, stylesheet, windowMode, applicationType ) );
61 Application::Application( int* argc, char** argv[], const std::string& stylesheet,
62 Dali::Application::WINDOW_MODE windowMode, Framework::Type applicationType )
70 mLanguageChangedSignal(),
71 mRegionChangedSignal(),
76 mContextLossConfiguration( Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS ),
77 mCommandLineOptions( NULL ),
78 mSingletonService( SingletonService::New() ),
81 mWindowMode( windowMode ),
83 mStylesheet( stylesheet ),
84 mEnvironmentOptions(),
87 // Get mName from environment options
88 mName = mEnvironmentOptions.GetWindowName();
89 if( mName.empty() && argc && ( *argc > 0 ) )
91 // Set mName from command-line args if environment option not set
95 mCommandLineOptions = new CommandLineOptions(argc, argv);
96 mFramework = new Framework( *this, argc, argv, applicationType );
97 mUseRemoteSurface = (applicationType == Framework::WATCH);
100 Application::~Application()
102 mSingletonService.UnregisterAll();
105 delete mCommandLineOptions;
110 void Application::CreateWindow()
112 PositionSize windowPosition(0, 0, 0, 0); // this will use full screen
114 if( mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0 )
116 // Command line options override environment options and full screen
117 windowPosition = PositionSize( 0, 0, mCommandLineOptions->stageWidth, mCommandLineOptions->stageHeight );
119 else if( mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight() )
121 // Environment options override full screen functionality if command line arguments not provided
122 windowPosition = PositionSize( 0, 0, mEnvironmentOptions.GetWindowWidth(), mEnvironmentOptions.GetWindowHeight() );
125 const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName();
126 mWindow = Dali::Window::New( windowPosition, mName, windowClassName, mWindowMode == Dali::Application::TRANSPARENT );
128 // Quit the application when the window is closed
129 GetImplementation( mWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit );
132 void Application::CreateAdaptor()
134 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
136 mAdaptor = Dali::Internal::Adaptor::Adaptor::New( mWindow, mContextLossConfiguration, &mEnvironmentOptions );
138 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
140 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( mUseRemoteSurface );
143 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
145 mContextLossConfiguration = configuration;
147 // Run the application
151 void Application::Lower()
153 // Lower the application without quitting it.
157 void Application::Quit()
159 // Actually quit the application.
160 AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ) );
163 void Application::QuitFromMainLoop()
168 // This will trigger OnTerminate(), below, after the main loop has completed.
171 void Application::OnInit()
173 mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
181 // Check if user requires no vsyncing and set on X11 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 );
203 // Wire up the LifecycleController
204 Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
206 InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
207 TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
208 PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
209 ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
210 ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
211 ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
212 LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );
214 Dali::Application application(this);
215 mInitSignal.Emit( application );
217 mAdaptor->NotifySceneCreated();
220 void Application::OnTerminate()
222 // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
223 // delete the window as ecore_x has been destroyed by AppCore
225 Dali::Application application(this);
226 mTerminateSignal.Emit( application );
230 // Ensure that the render-thread is not using the surface(window) after we delete it
237 void Application::OnPause()
240 Dali::Application application(this);
241 mPauseSignal.Emit( application );
244 void Application::OnResume()
246 // Emit the signal first so the application can queue any messages before we do an update/render
247 // This ensures we do not just redraw the last frame before pausing if that's not required
248 Dali::Application application(this);
249 mResumeSignal.Emit( application );
253 void Application::OnReset()
256 * usually, reset callback was called when a caller request to launch this application via aul.
257 * because Application class already handled initialization in OnInit(), OnReset do nothing.
259 Dali::Application application(this);
260 mResetSignal.Emit( application );
263 void Application::OnAppControl(void *data)
265 Dali::Application application(this);
266 mAppControlSignal.Emit( application , data );
269 void Application::OnLanguageChanged()
271 mAdaptor->NotifyLanguageChanged();
272 Dali::Application application(this);
273 mLanguageChangedSignal.Emit( application );
276 void Application::OnRegionChanged()
278 Dali::Application application(this);
279 mRegionChangedSignal.Emit( application );
282 void Application::OnBatteryLow()
284 Dali::Application application(this);
285 mBatteryLowSignal.Emit( application );
288 void Application::OnMemoryLow()
290 Dali::Application application(this);
291 mMemoryLowSignal.Emit( application );
294 void Application::OnResize(Dali::Adaptor& adaptor)
296 Dali::Application application(this);
297 mResizeSignal.Emit( application );
300 bool Application::AddIdle( CallbackBase* callback )
302 return mAdaptor->AddIdle( callback );
305 Dali::Adaptor& Application::GetAdaptor()
310 Dali::Window Application::GetWindow()
317 void Application::SetViewMode( ViewMode viewMode )
319 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
322 ViewMode Application::GetViewMode() const
324 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
327 void Application::SetStereoBase( float stereoBase )
329 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
332 float Application::GetStereoBase() const
334 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
338 void Application::ReplaceWindow(PositionSize windowPosition, const std::string& name)
340 Dali::Window newWindow = Dali::Window::New( windowPosition, name, mWindowMode == Dali::Application::TRANSPARENT );
341 Window& windowImpl = GetImplementation(newWindow);
342 windowImpl.SetAdaptor(*mAdaptor);
343 newWindow.ShowIndicator(Dali::Window::INVISIBLE);
344 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
346 Any nativeWindow = newWindow.GetNativeHandle();
347 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(nativeWindow, *renderSurface);
351 } // namespace Adaptor
353 } // namespace Internal