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 );
99 Application::~Application()
101 mSingletonService.UnregisterAll();
104 delete mCommandLineOptions;
109 void Application::CreateWindow()
111 PositionSize windowPosition(0, 0, 0, 0); // this will use full screen
113 if( mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0 )
115 // Command line options override environment options and full screen
116 windowPosition = PositionSize( 0, 0, mCommandLineOptions->stageWidth, mCommandLineOptions->stageHeight );
118 else if( mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight() )
120 // Environment options override full screen functionality if command line arguments not provided
121 windowPosition = PositionSize( 0, 0, mEnvironmentOptions.GetWindowWidth(), mEnvironmentOptions.GetWindowHeight() );
124 const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName();
125 mWindow = Dali::Window::New( windowPosition, mName, windowClassName, mWindowMode == Dali::Application::TRANSPARENT );
127 // Quit the application when the window is closed
128 GetImplementation( mWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit );
131 void Application::CreateAdaptor()
133 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
135 mAdaptor = Dali::Internal::Adaptor::Adaptor::New( mWindow, mContextLossConfiguration, &mEnvironmentOptions );
137 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
140 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
142 mContextLossConfiguration = configuration;
144 // Run the application
148 void Application::Lower()
150 // Lower the application without quitting it.
154 void Application::Quit()
156 // Actually quit the application.
157 AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ) );
160 void Application::QuitFromMainLoop()
165 // This will trigger OnTerminate(), below, after the main loop has completed.
168 void Application::OnInit()
170 mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
178 // Check if user requires no vsyncing and set on X11 Adaptor
179 if (mCommandLineOptions->noVSyncOnRender)
181 mAdaptor->SetUseHardwareVSync(false);
184 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
185 if( mCommandLineOptions->viewMode != 0 )
187 ViewMode viewMode = MONO;
188 if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
190 viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
192 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
195 if( ! mStylesheet.empty() )
197 Dali::StyleMonitor::Get().SetTheme( mStylesheet );
200 // Wire up the LifecycleController
201 Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
203 InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
204 TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
205 PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
206 ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
207 ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
208 ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
209 LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );
211 Dali::Application application(this);
212 mInitSignal.Emit( application );
214 mAdaptor->NotifySceneCreated();
217 void Application::OnTerminate()
219 // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
220 // delete the window as ecore_x has been destroyed by AppCore
222 Dali::Application application(this);
223 mTerminateSignal.Emit( application );
227 // Ensure that the render-thread is not using the surface(window) after we delete it
234 void Application::OnPause()
237 Dali::Application application(this);
238 mPauseSignal.Emit( application );
241 void Application::OnResume()
243 // Emit the signal first so the application can queue any messages before we do an update/render
244 // This ensures we do not just redraw the last frame before pausing if that's not required
245 Dali::Application application(this);
246 mResumeSignal.Emit( application );
250 void Application::OnReset()
253 * usually, reset callback was called when a caller request to launch this application via aul.
254 * because Application class already handled initialization in OnInit(), OnReset do nothing.
256 Dali::Application application(this);
257 mResetSignal.Emit( application );
260 void Application::OnAppControl(void *data)
262 Dali::Application application(this);
263 mAppControlSignal.Emit( application , data );
266 void Application::OnLanguageChanged()
268 mAdaptor->NotifyLanguageChanged();
269 Dali::Application application(this);
270 mLanguageChangedSignal.Emit( application );
273 void Application::OnRegionChanged()
275 Dali::Application application(this);
276 mRegionChangedSignal.Emit( application );
279 void Application::OnBatteryLow()
281 Dali::Application application(this);
282 mBatteryLowSignal.Emit( application );
285 void Application::OnMemoryLow()
287 Dali::Application application(this);
288 mMemoryLowSignal.Emit( application );
291 void Application::OnResize(Dali::Adaptor& adaptor)
293 Dali::Application application(this);
294 mResizeSignal.Emit( application );
297 bool Application::AddIdle( CallbackBase* callback )
299 return mAdaptor->AddIdle( callback );
302 Dali::Adaptor& Application::GetAdaptor()
307 Dali::Window Application::GetWindow()
314 void Application::SetViewMode( ViewMode viewMode )
316 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
319 ViewMode Application::GetViewMode() const
321 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
324 void Application::SetStereoBase( float stereoBase )
326 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
329 float Application::GetStereoBase() const
331 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
335 void Application::ReplaceWindow(PositionSize windowPosition, const std::string& name)
337 Dali::Window newWindow = Dali::Window::New( windowPosition, name, mWindowMode == Dali::Application::TRANSPARENT );
338 Window& windowImpl = GetImplementation(newWindow);
339 windowImpl.SetAdaptor(*mAdaptor);
340 newWindow.ShowIndicator(Dali::Window::INVISIBLE);
341 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
343 Any nativeWindow = newWindow.GetNativeHandle();
344 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(nativeWindow, *renderSurface);
348 } // namespace Adaptor
350 } // namespace Internal