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;
52 // Defaults taken from H2 device
53 const unsigned int DEFAULT_WINDOW_WIDTH = 480;
54 const unsigned int DEFAULT_WINDOW_HEIGHT = 800;
55 const float DEFAULT_HORIZONTAL_DPI = 220;
56 const float DEFAULT_VERTICAL_DPI = 217;
59 ApplicationPtr Application::New(
62 const std::string& name,
63 const DeviceLayout& baseLayout,
64 Dali::Application::WINDOW_MODE windowMode)
66 ApplicationPtr application ( new Application (argc, argv, name, baseLayout, windowMode ) );
70 Application::Application( int* argc, char** argv[], const std::string& name, const DeviceLayout& baseLayout, Dali::Application::WINDOW_MODE windowMode)
78 mLanguageChangedSignal(),
79 mRegionChangedSignal(),
84 mCommandLineOptions( NULL ),
85 mSingletonService( SingletonService::New() ),
88 mWindowMode( windowMode ),
90 mInitialized( false ),
91 mBaseLayout( baseLayout ),
94 mCommandLineOptions = new CommandLineOptions(argc, argv);
96 mFramework = new Framework(*this, argc, argv, name);
99 Application::~Application()
101 mSingletonService.UnregisterAll();
104 delete mCommandLineOptions;
109 void Application::CreateWindow()
112 PositionSize windowPosition(0, 0, DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
114 PositionSize windowPosition(0, 0, 0, 0); // this will use full screen
116 if (mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0)
118 // let the command line options over ride
119 windowPosition = PositionSize(0,0,mCommandLineOptions->stageWidth,mCommandLineOptions->stageHeight);
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::Adaptor::New( mWindow, mBaseLayout, mContextLossConfiguration );
131 // Allow DPI to be overridden from command line.
132 unsigned int hDPI=DEFAULT_HORIZONTAL_DPI;
133 unsigned int vDPI=DEFAULT_VERTICAL_DPI;
135 std::string dpiStr = mCommandLineOptions->stageDPI;
138 sscanf(dpiStr.c_str(), "%ux%u", &hDPI, &vDPI);
140 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetDpi(hDPI, vDPI);
142 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
145 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
147 mContextLossConfiguration = configuration;
149 // Run the application
153 void Application::Lower()
155 // Lower the application without quitting it.
159 void Application::Quit()
161 // Actually quit the application.
162 AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ) );
165 void Application::QuitFromMainLoop()
169 Dali::Application application(this);
170 mTerminateSignal.Emit( application );
173 // This will trigger OnTerminate(), below, after the main loop has completed.
174 mInitialized = false;
177 void Application::OnInit()
179 mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
187 // Check if user requires no vsyncing and set on X11 Adaptor
188 if (mCommandLineOptions->noVSyncOnRender)
190 mAdaptor->SetUseHardwareVSync(false);
193 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
194 if( mCommandLineOptions->viewMode != 0 )
196 ViewMode viewMode = MONO;
197 if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
199 viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
201 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
206 // Wire up the LifecycleController
207 Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
209 InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
210 TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
211 PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
212 ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
213 ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
214 ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
215 LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );
217 Dali::Application application(this);
218 mInitSignal.Emit( application );
220 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetCore().SceneCreated();
223 void Application::OnTerminate()
225 // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
226 // delete the window as ecore_x has been destroyed by AppCore
229 mInitialized = false;
232 void Application::OnPause()
235 Dali::Application application(this);
236 mPauseSignal.Emit( application );
239 void Application::OnResume()
242 Dali::Application application(this);
243 mResumeSignal.Emit( application );
246 void Application::OnReset()
249 * usually, reset callback was called when a caller request to launch this application via aul.
250 * because Application class already handled initialization in OnInit(), OnReset do nothing.
252 Dali::Application application(this);
253 mResetSignal.Emit( application );
258 void Application::OnAppControl(void *data)
260 Dali::Application application(this);
261 mAppControlSignal.Emit( application , data );
264 void Application::OnLanguageChanged()
266 mAdaptor->NotifyLanguageChanged();
269 void Application::OnRegionChanged()
271 Dali::Application application(this);
272 mRegionChangedSignal.Emit( application );
275 void Application::OnBatteryLow()
277 Dali::Application application(this);
278 mBatteryLowSignal.Emit( application );
281 void Application::OnMemoryLow()
283 Dali::Application application(this);
284 mMemoryLowSignal.Emit( application );
287 void Application::OnResize(Dali::Adaptor& adaptor)
289 Dali::Application application(this);
290 mResizeSignal.Emit( application );
293 bool Application::AddIdle( CallbackBase* callback )
295 return mAdaptor->AddIdle( callback );
298 Dali::Adaptor& Application::GetAdaptor()
303 Dali::Window Application::GetWindow()
308 const std::string& Application::GetTheme()
310 return Dali::StyleMonitor::Get().GetTheme();
313 void Application::SetTheme(const std::string& themeFilePath)
315 return Dali::StyleMonitor::Get().SetTheme(themeFilePath);
320 void Application::SetViewMode( ViewMode viewMode )
322 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
325 ViewMode Application::GetViewMode() const
327 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
330 void Application::SetStereoBase( float stereoBase )
332 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
335 float Application::GetStereoBase() const
337 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
341 void Application::ReplaceWindow(PositionSize windowPosition, const std::string& name)
343 Dali::Window newWindow = Dali::Window::New( windowPosition, name, mWindowMode == Dali::Application::TRANSPARENT );
344 Window& windowImpl = GetImplementation(newWindow);
345 windowImpl.SetAdaptor(*mAdaptor);
346 newWindow.ShowIndicator(Dali::Window::INVISIBLE);
347 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
348 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(*renderSurface);
352 } // namespace Adaptor
354 } // namespace Internal