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 // Get mName from environment options
87 mName = mEnvironmentOptions.GetWindowName();
88 if( mName.empty() && argc && ( *argc > 0 ) )
90 // Set mName from command-line args if environment option not set
94 mCommandLineOptions = new CommandLineOptions(argc, argv);
96 mFramework = new Framework( *this, argc, argv );
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 );
128 void Application::CreateAdaptor()
130 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
132 mAdaptor = Dali::Internal::Adaptor::Adaptor::New( mWindow, mContextLossConfiguration, &mEnvironmentOptions );
134 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
137 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
139 mContextLossConfiguration = configuration;
141 // Run the application
145 void Application::Lower()
147 // Lower the application without quitting it.
151 void Application::Quit()
153 // Actually quit the application.
154 AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ) );
157 void Application::QuitFromMainLoop()
161 Dali::Application application(this);
162 mTerminateSignal.Emit( application );
165 // This will trigger OnTerminate(), below, after the main loop has completed.
166 mInitialized = false;
169 void Application::OnInit()
171 mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
179 // Check if user requires no vsyncing and set on X11 Adaptor
180 if (mCommandLineOptions->noVSyncOnRender)
182 mAdaptor->SetUseHardwareVSync(false);
185 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
186 if( mCommandLineOptions->viewMode != 0 )
188 ViewMode viewMode = MONO;
189 if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
191 viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
193 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
196 if( ! mStylesheet.empty() )
198 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
226 mInitialized = false;
229 void Application::OnPause()
232 Dali::Application application(this);
233 mPauseSignal.Emit( application );
236 void Application::OnResume()
239 Dali::Application application(this);
240 mResumeSignal.Emit( application );
243 void Application::OnReset()
246 * usually, reset callback was called when a caller request to launch this application via aul.
247 * because Application class already handled initialization in OnInit(), OnReset do nothing.
249 Dali::Application application(this);
250 mResetSignal.Emit( application );
255 void Application::OnAppControl(void *data)
257 Dali::Application application(this);
258 mAppControlSignal.Emit( application , data );
261 void Application::OnLanguageChanged()
263 mAdaptor->NotifyLanguageChanged();
264 Dali::Application application(this);
265 mLanguageChangedSignal.Emit( application );
268 void Application::OnRegionChanged()
270 Dali::Application application(this);
271 mRegionChangedSignal.Emit( application );
274 void Application::OnBatteryLow()
276 Dali::Application application(this);
277 mBatteryLowSignal.Emit( application );
280 void Application::OnMemoryLow()
282 Dali::Application application(this);
283 mMemoryLowSignal.Emit( application );
286 void Application::OnResize(Dali::Adaptor& adaptor)
288 Dali::Application application(this);
289 mResizeSignal.Emit( application );
292 bool Application::AddIdle( CallbackBase* callback )
294 return mAdaptor->AddIdle( callback );
297 Dali::Adaptor& Application::GetAdaptor()
302 Dali::Window Application::GetWindow()
309 void Application::SetViewMode( ViewMode viewMode )
311 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
314 ViewMode Application::GetViewMode() const
316 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
319 void Application::SetStereoBase( float stereoBase )
321 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
324 float Application::GetStereoBase() const
326 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
330 void Application::ReplaceWindow(PositionSize windowPosition, const std::string& name)
332 Dali::Window newWindow = Dali::Window::New( windowPosition, name, mWindowMode == Dali::Application::TRANSPARENT );
333 Window& windowImpl = GetImplementation(newWindow);
334 windowImpl.SetAdaptor(*mAdaptor);
335 newWindow.ShowIndicator(Dali::Window::INVISIBLE);
336 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
338 Any nativeWindow = newWindow.GetNativeHandle();
339 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(nativeWindow, *renderSurface);
343 } // namespace Adaptor
345 } // namespace Internal