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>
23 #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)
77 mLanguageChangedSignalV2(),
80 mCommandLineOptions( NULL ),
81 mSingletonService( SingletonService::New() ),
84 mWindowMode( windowMode ),
86 mInitialized( false ),
87 mBaseLayout( baseLayout ),
90 mCommandLineOptions = new CommandLineOptions(argc, argv);
92 mFramework = new Framework(*this, argc, argv, name);
95 Application::~Application()
97 mSingletonService.UnregisterAll();
100 delete mCommandLineOptions;
105 void Application::CreateWindow()
108 PositionSize windowPosition(0, 0, DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
110 PositionSize windowPosition(0, 0, 0, 0); // this will use full screen
112 if (mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0)
114 // let the command line options over ride
115 windowPosition = PositionSize(0,0,mCommandLineOptions->stageWidth,mCommandLineOptions->stageHeight);
118 mWindow = Dali::Window::New( windowPosition, mName, mWindowMode == Dali::Application::TRANSPARENT );
121 void Application::CreateAdaptor()
123 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
125 mAdaptor = &Dali::Adaptor::New( mWindow, mBaseLayout, mContextLossConfiguration );
127 // Allow DPI to be overridden from command line.
128 unsigned int hDPI=DEFAULT_HORIZONTAL_DPI;
129 unsigned int vDPI=DEFAULT_VERTICAL_DPI;
131 std::string dpiStr = mCommandLineOptions->stageDPI;
134 sscanf(dpiStr.c_str(), "%ux%u", &hDPI, &vDPI);
136 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetDpi(hDPI, vDPI);
138 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
141 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
143 mContextLossConfiguration = configuration;
145 // Run the application
149 void Application::Lower()
151 // Lower the application without quitting it.
155 void Application::Quit()
157 // Actually quit the application.
158 AddIdle(boost::bind(&Application::QuitFromMainLoop, this));
161 void Application::QuitFromMainLoop()
165 Dali::Application application(this);
166 mTerminateSignalV2.Emit( application );
169 // This will trigger OnTerminate(), below, after the main loop has completed.
170 mInitialized = false;
173 void Application::OnInit()
175 mFramework->AddAbortCallback(boost::bind(&Application::QuitFromMainLoop, this));
183 // Check if user requires no vsyncing and set on X11 Adaptor
184 if (mCommandLineOptions->noVSyncOnRender)
186 mAdaptor->SetUseHardwareVSync(false);
189 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
190 if( mCommandLineOptions->viewMode != 0 )
192 ViewMode viewMode = MONO;
193 if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
195 viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
197 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
202 // Wire up the LifecycleController
203 Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
205 InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
206 TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
207 PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
208 ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
209 ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
210 ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
211 LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );
213 Dali::Application application(this);
214 mInitSignalV2.Emit( application );
216 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetCore().SceneCreated();
219 void Application::OnTerminate()
221 // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
222 // delete the window as ecore_x has been destroyed by AppCore
225 mInitialized = false;
228 void Application::OnPause()
231 Dali::Application application(this);
232 mPauseSignalV2.Emit( application );
235 void Application::OnResume()
238 Dali::Application application(this);
239 mResumeSignalV2.Emit( application );
242 void Application::OnReset()
245 * usually, reset callback was called when a caller request to launch this application via aul.
246 * because Application class already handled initialization in OnInit(), OnReset do nothing.
248 Dali::Application application(this);
249 mResetSignalV2.Emit( application );
254 void Application::OnLanguageChanged()
256 mAdaptor->NotifyLanguageChanged();
259 void Application::OnResize(Dali::Adaptor& adaptor)
261 Dali::Application application(this);
262 mResizeSignalV2.Emit( application );
265 bool Application::AddIdle(boost::function<void(void)> callBack)
267 return mAdaptor->AddIdle(callBack);
270 Dali::Adaptor& Application::GetAdaptor()
275 Dali::Window Application::GetWindow()
280 const std::string& Application::GetTheme()
282 return Dali::StyleMonitor::Get().GetTheme();
285 void Application::SetTheme(const std::string& themeFilePath)
287 return Dali::StyleMonitor::Get().SetTheme(themeFilePath);
292 void Application::SetViewMode( ViewMode viewMode )
294 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
297 ViewMode Application::GetViewMode() const
299 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
302 void Application::SetStereoBase( float stereoBase )
304 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
307 float Application::GetStereoBase() const
309 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
313 void Application::ReplaceWindow(PositionSize windowPosition, const std::string& name)
315 Dali::Window newWindow = Dali::Window::New( windowPosition, name, mWindowMode == Dali::Application::TRANSPARENT );
316 Window& windowImpl = GetImplementation(newWindow);
317 windowImpl.SetAdaptor(*mAdaptor);
318 newWindow.ShowIndicator(Dali::Window::INVISIBLE);
319 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
320 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(*renderSurface);
324 } // namespace Adaptor
326 } // namespace Internal