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>
36 class SlpPlatformAbstraction;
50 ApplicationPtr Application::New(
53 const std::string& name,
54 const DeviceLayout& baseLayout,
55 Dali::Application::WINDOW_MODE windowMode)
57 ApplicationPtr application ( new Application (argc, argv, name, baseLayout, windowMode ) );
61 Application::Application( int* argc, char** argv[], const std::string& name, const DeviceLayout& baseLayout, Dali::Application::WINDOW_MODE windowMode)
69 mLanguageChangedSignal(),
70 mRegionChangedSignal(),
75 mCommandLineOptions( NULL ),
76 mSingletonService( SingletonService::New() ),
79 mWindowMode( windowMode ),
81 mInitialized( false ),
82 mBaseLayout( baseLayout ),
85 mCommandLineOptions = new CommandLineOptions(argc, argv);
87 mFramework = new Framework(*this, argc, argv, name);
90 Application::~Application()
92 mSingletonService.UnregisterAll();
95 delete mCommandLineOptions;
100 void Application::CreateWindow()
102 PositionSize windowPosition(0, 0, 0, 0); // this will use full screen
104 if( mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0 )
106 // let the command line options over ride
107 windowPosition = PositionSize( 0, 0, mCommandLineOptions->stageWidth, mCommandLineOptions->stageHeight );
110 mWindow = Dali::Window::New( windowPosition, mName, mWindowMode == Dali::Application::TRANSPARENT );
113 void Application::CreateAdaptor()
115 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
117 mAdaptor = &Dali::Adaptor::New( mWindow, mBaseLayout, mContextLossConfiguration );
119 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
122 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
124 mContextLossConfiguration = configuration;
126 // Run the application
130 void Application::Lower()
132 // Lower the application without quitting it.
136 void Application::Quit()
138 // Actually quit the application.
139 AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ) );
142 void Application::QuitFromMainLoop()
146 Dali::Application application(this);
147 mTerminateSignal.Emit( application );
150 // This will trigger OnTerminate(), below, after the main loop has completed.
151 mInitialized = false;
154 void Application::OnInit()
156 mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
164 // Check if user requires no vsyncing and set on X11 Adaptor
165 if (mCommandLineOptions->noVSyncOnRender)
167 mAdaptor->SetUseHardwareVSync(false);
170 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
171 if( mCommandLineOptions->viewMode != 0 )
173 ViewMode viewMode = MONO;
174 if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
176 viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
178 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
183 // Wire up the LifecycleController
184 Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
186 InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
187 TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
188 PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
189 ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
190 ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
191 ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
192 LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );
194 Dali::Application application(this);
195 mInitSignal.Emit( application );
197 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetCore().SceneCreated();
200 void Application::OnTerminate()
202 // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
203 // delete the window as ecore_x has been destroyed by AppCore
206 mInitialized = false;
209 void Application::OnPause()
212 Dali::Application application(this);
213 mPauseSignal.Emit( application );
216 void Application::OnResume()
219 Dali::Application application(this);
220 mResumeSignal.Emit( application );
223 void Application::OnReset()
226 * usually, reset callback was called when a caller request to launch this application via aul.
227 * because Application class already handled initialization in OnInit(), OnReset do nothing.
229 Dali::Application application(this);
230 mResetSignal.Emit( application );
235 void Application::OnAppControl(void *data)
237 Dali::Application application(this);
238 mAppControlSignal.Emit( application , data );
241 void Application::OnLanguageChanged()
243 mAdaptor->NotifyLanguageChanged();
246 void Application::OnRegionChanged()
248 Dali::Application application(this);
249 mRegionChangedSignal.Emit( application );
252 void Application::OnBatteryLow()
254 Dali::Application application(this);
255 mBatteryLowSignal.Emit( application );
258 void Application::OnMemoryLow()
260 Dali::Application application(this);
261 mMemoryLowSignal.Emit( application );
264 void Application::OnResize(Dali::Adaptor& adaptor)
266 Dali::Application application(this);
267 mResizeSignal.Emit( application );
270 bool Application::AddIdle( CallbackBase* callback )
272 return mAdaptor->AddIdle( callback );
275 Dali::Adaptor& Application::GetAdaptor()
280 Dali::Window Application::GetWindow()
285 const std::string& Application::GetTheme()
287 return Dali::StyleMonitor::Get().GetTheme();
290 void Application::SetTheme(const std::string& themeFilePath)
292 return Dali::StyleMonitor::Get().SetTheme(themeFilePath);
297 void Application::SetViewMode( ViewMode viewMode )
299 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
302 ViewMode Application::GetViewMode() const
304 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
307 void Application::SetStereoBase( float stereoBase )
309 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
312 float Application::GetStereoBase() const
314 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
318 void Application::ReplaceWindow(PositionSize windowPosition, const std::string& name)
320 Dali::Window newWindow = Dali::Window::New( windowPosition, name, mWindowMode == Dali::Application::TRANSPARENT );
321 Window& windowImpl = GetImplementation(newWindow);
322 windowImpl.SetAdaptor(*mAdaptor);
323 newWindow.ShowIndicator(Dali::Window::INVISIBLE);
324 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
325 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(*renderSurface);
329 } // namespace Adaptor
331 } // namespace Internal