2 * Copyright (c) 2014 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)
56 ApplicationPtr application ( new Application (argc, argv, stylesheet, windowMode ) );
60 Application::Application( int* argc, char** argv[], const std::string& stylesheet, Dali::Application::WINDOW_MODE windowMode )
68 mLanguageChangedSignal(),
69 mRegionChangedSignal(),
74 mContextLossConfiguration( Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS ),
75 mCommandLineOptions( NULL ),
76 mSingletonService( SingletonService::New() ),
79 mWindowMode( windowMode ),
81 mStylesheet( stylesheet ),
82 mEnvironmentOptions(),
85 // Get mName from environment options
86 mName = mEnvironmentOptions.GetWindowName();
87 if( mName.empty() && argc && ( *argc > 0 ) )
89 // Set mName from command-line args if environment option not set
93 mCommandLineOptions = new CommandLineOptions(argc, argv);
95 mFramework = new Framework( *this, argc, argv );
98 Application::~Application()
100 mSingletonService.UnregisterAll();
103 delete mCommandLineOptions;
108 void Application::CreateWindow()
110 PositionSize windowPosition(0, 0, 0, 0); // this will use full screen
112 if( mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0 )
114 // Command line options override environment options and full screen
115 windowPosition = PositionSize( 0, 0, mCommandLineOptions->stageWidth, mCommandLineOptions->stageHeight );
117 else if( mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight() )
119 // Environment options override full screen functionality if command line arguments not provided
120 windowPosition = PositionSize( 0, 0, mEnvironmentOptions.GetWindowWidth(), mEnvironmentOptions.GetWindowHeight() );
123 const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName();
124 mWindow = Dali::Window::New( windowPosition, mName, windowClassName, mWindowMode == Dali::Application::TRANSPARENT );
126 // Quit the application when the window is closed
127 GetImplementation( mWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit );
130 void Application::CreateAdaptor()
132 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
134 mAdaptor = Dali::Internal::Adaptor::Adaptor::New( mWindow, mContextLossConfiguration, &mEnvironmentOptions );
136 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
139 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
141 mContextLossConfiguration = configuration;
143 // Run the application
147 void Application::Lower()
149 // Lower the application without quitting it.
153 void Application::Quit()
155 // Actually quit the application.
156 AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ) );
159 void Application::QuitFromMainLoop()
164 // This will trigger OnTerminate(), below, after the main loop has completed.
167 void Application::OnInit()
169 mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
177 // Check if user requires no vsyncing and set on X11 Adaptor
178 if (mCommandLineOptions->noVSyncOnRender)
180 mAdaptor->SetUseHardwareVSync(false);
183 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
184 if( mCommandLineOptions->viewMode != 0 )
186 ViewMode viewMode = MONO;
187 if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
189 viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
191 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
194 if( ! mStylesheet.empty() )
196 Dali::StyleMonitor::Get().SetTheme( mStylesheet );
199 // Wire up the LifecycleController
200 Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
202 InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
203 TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
204 PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
205 ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
206 ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
207 ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
208 LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );
210 Dali::Application application(this);
211 mInitSignal.Emit( application );
213 mAdaptor->NotifySceneCreated();
216 void Application::OnTerminate()
218 // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
219 // delete the window as ecore_x has been destroyed by AppCore
221 Dali::Application application(this);
222 mTerminateSignal.Emit( application );
226 // Ensure that the render-thread is not using the surface(window) after we delete it
233 void Application::OnPause()
236 Dali::Application application(this);
237 mPauseSignal.Emit( application );
240 void Application::OnResume()
242 // Emit the signal first so the application can queue any messages before we do an update/render
243 // This ensures we do not just redraw the last frame before pausing if that's not required
244 Dali::Application application(this);
245 mResumeSignal.Emit( application );
249 void Application::OnReset()
252 * usually, reset callback was called when a caller request to launch this application via aul.
253 * because Application class already handled initialization in OnInit(), OnReset do nothing.
255 Dali::Application application(this);
256 mResetSignal.Emit( application );
259 void Application::OnAppControl(void *data)
261 Dali::Application application(this);
262 mAppControlSignal.Emit( application , data );
265 void Application::OnLanguageChanged()
267 mAdaptor->NotifyLanguageChanged();
268 Dali::Application application(this);
269 mLanguageChangedSignal.Emit( application );
272 void Application::OnRegionChanged()
274 Dali::Application application(this);
275 mRegionChangedSignal.Emit( application );
278 void Application::OnBatteryLow()
280 Dali::Application application(this);
281 mBatteryLowSignal.Emit( application );
284 void Application::OnMemoryLow()
286 Dali::Application application(this);
287 mMemoryLowSignal.Emit( application );
290 void Application::OnResize(Dali::Adaptor& adaptor)
292 Dali::Application application(this);
293 mResizeSignal.Emit( application );
296 bool Application::AddIdle( CallbackBase* callback )
298 return mAdaptor->AddIdle( callback );
301 Dali::Adaptor& Application::GetAdaptor()
306 Dali::Window Application::GetWindow()
313 void Application::SetViewMode( ViewMode viewMode )
315 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
318 ViewMode Application::GetViewMode() const
320 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
323 void Application::SetStereoBase( float stereoBase )
325 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
328 float Application::GetStereoBase() const
330 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
334 void Application::ReplaceWindow(PositionSize windowPosition, const std::string& name)
336 Dali::Window newWindow = Dali::Window::New( windowPosition, name, mWindowMode == Dali::Application::TRANSPARENT );
337 Window& windowImpl = GetImplementation(newWindow);
338 windowImpl.SetAdaptor(*mAdaptor);
339 newWindow.ShowIndicator(Dali::Window::INVISIBLE);
340 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
342 Any nativeWindow = newWindow.GetNativeHandle();
343 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(nativeWindow, *renderSurface);
347 } // namespace Adaptor
349 } // namespace Internal