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(),
83 mInitialized( false ),
86 // Copy mName from command-line args
87 if( argc && ( *argc > 0 ) )
92 mCommandLineOptions = new CommandLineOptions(argc, argv);
94 mFramework = new Framework( *this, argc, argv );
97 Application::~Application()
99 mSingletonService.UnregisterAll();
102 delete mCommandLineOptions;
107 void Application::CreateWindow()
109 PositionSize windowPosition(0, 0, 0, 0); // this will use full screen
111 if( mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0 )
113 // Command line options override environment options and full screen
114 windowPosition = PositionSize( 0, 0, mCommandLineOptions->stageWidth, mCommandLineOptions->stageHeight );
116 else if( mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight() )
118 // Environment options override full screen functionality if command line arguments not provided
119 windowPosition = PositionSize( 0, 0, mEnvironmentOptions.GetWindowWidth(), mEnvironmentOptions.GetWindowHeight() );
122 mWindow = Dali::Window::New( windowPosition, mName, mWindowMode == Dali::Application::TRANSPARENT );
125 void Application::CreateAdaptor()
127 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
129 mAdaptor = Dali::Internal::Adaptor::Adaptor::New( mWindow, mContextLossConfiguration, &mEnvironmentOptions );
131 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
134 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
136 mContextLossConfiguration = configuration;
138 // Run the application
142 void Application::Lower()
144 // Lower the application without quitting it.
148 void Application::Quit()
150 // Actually quit the application.
151 AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ) );
154 void Application::QuitFromMainLoop()
158 Dali::Application application(this);
159 mTerminateSignal.Emit( application );
162 // This will trigger OnTerminate(), below, after the main loop has completed.
163 mInitialized = false;
166 void Application::OnInit()
168 mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
176 // Check if user requires no vsyncing and set on X11 Adaptor
177 if (mCommandLineOptions->noVSyncOnRender)
179 mAdaptor->SetUseHardwareVSync(false);
182 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
183 if( mCommandLineOptions->viewMode != 0 )
185 ViewMode viewMode = MONO;
186 if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
188 viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
190 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
193 if( ! mStylesheet.empty() )
195 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 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetCore().SceneCreated();
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
223 mInitialized = false;
226 void Application::OnPause()
229 Dali::Application application(this);
230 mPauseSignal.Emit( application );
233 void Application::OnResume()
236 Dali::Application application(this);
237 mResumeSignal.Emit( application );
240 void Application::OnReset()
243 * usually, reset callback was called when a caller request to launch this application via aul.
244 * because Application class already handled initialization in OnInit(), OnReset do nothing.
246 Dali::Application application(this);
247 mResetSignal.Emit( application );
252 void Application::OnAppControl(void *data)
254 Dali::Application application(this);
255 mAppControlSignal.Emit( application , data );
258 void Application::OnLanguageChanged()
260 mAdaptor->NotifyLanguageChanged();
261 Dali::Application application(this);
262 mLanguageChangedSignal.Emit( application );
265 void Application::OnRegionChanged()
267 Dali::Application application(this);
268 mRegionChangedSignal.Emit( application );
271 void Application::OnBatteryLow()
273 Dali::Application application(this);
274 mBatteryLowSignal.Emit( application );
277 void Application::OnMemoryLow()
279 Dali::Application application(this);
280 mMemoryLowSignal.Emit( application );
283 void Application::OnResize(Dali::Adaptor& adaptor)
285 Dali::Application application(this);
286 mResizeSignal.Emit( application );
289 bool Application::AddIdle( CallbackBase* callback )
291 return mAdaptor->AddIdle( callback );
294 Dali::Adaptor& Application::GetAdaptor()
299 Dali::Window Application::GetWindow()
306 void Application::SetViewMode( ViewMode viewMode )
308 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
311 ViewMode Application::GetViewMode() const
313 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
316 void Application::SetStereoBase( float stereoBase )
318 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
321 float Application::GetStereoBase() const
323 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
327 void Application::ReplaceWindow(PositionSize windowPosition, const std::string& name)
329 Dali::Window newWindow = Dali::Window::New( windowPosition, name, mWindowMode == Dali::Application::TRANSPARENT );
330 Window& windowImpl = GetImplementation(newWindow);
331 windowImpl.SetAdaptor(*mAdaptor);
332 newWindow.ShowIndicator(Dali::Window::INVISIBLE);
333 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
335 Any nativeWindow = newWindow.GetNativeHandle();
336 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(nativeWindow, *renderSurface);
340 } // namespace Adaptor
342 } // namespace Internal