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()
98 delete mCommandLineOptions;
103 void Application::CreateWindow()
106 PositionSize windowPosition(0, 0, DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
108 PositionSize windowPosition(0, 0, 0, 0); // this will use full screen
110 if (mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0)
112 // let the command line options over ride
113 windowPosition = PositionSize(0,0,mCommandLineOptions->stageWidth,mCommandLineOptions->stageHeight);
116 mWindow = Dali::Window::New( windowPosition, mName, mWindowMode == Dali::Application::TRANSPARENT );
119 void Application::CreateAdaptor()
121 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
123 mAdaptor = &Dali::Adaptor::New( mWindow, mBaseLayout, mContextLossConfiguration );
125 // Allow DPI to be overridden from command line.
126 unsigned int hDPI=DEFAULT_HORIZONTAL_DPI;
127 unsigned int vDPI=DEFAULT_VERTICAL_DPI;
129 std::string dpiStr = mCommandLineOptions->stageDPI;
132 sscanf(dpiStr.c_str(), "%ux%u", &hDPI, &vDPI);
134 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetDpi(hDPI, vDPI);
136 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
139 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
141 mContextLossConfiguration = configuration;
143 // Run the application
147 void Application::Lower()
149 // Lower the application without quitting it.
153 void Application::Quit()
155 // Actually quit the application.
156 AddIdle(boost::bind(&Application::QuitFromMainLoop, this));
159 void Application::QuitFromMainLoop()
163 Dali::Application application(this);
164 mTerminateSignalV2.Emit( application );
167 // This will trigger OnTerminate(), below, after the main loop has completed.
168 mInitialized = false;
171 void Application::OnInit()
173 mFramework->AddAbortCallback(boost::bind(&Application::QuitFromMainLoop, this));
181 // Check if user requires no vsyncing and set on X11 Adaptor
182 if (mCommandLineOptions->noVSyncOnRender)
184 mAdaptor->SetUseHardwareVSync(false);
187 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
188 if( mCommandLineOptions->viewMode != 0 )
190 ViewMode viewMode = MONO;
191 if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
193 viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
195 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
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 mInitSignalV2.Emit( application );
215 void Application::OnTerminate()
217 // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
218 // delete the window as ecore_x has been destroyed by AppCore
221 mInitialized = false;
224 void Application::OnPause()
227 Dali::Application application(this);
228 mPauseSignalV2.Emit( application );
231 void Application::OnResume()
234 Dali::Application application(this);
235 mResumeSignalV2.Emit( application );
238 void Application::OnReset()
241 * usually, reset callback was called when a caller request to launch this application via aul.
242 * because Application class already handled initialization in OnInit(), OnReset do nothing.
244 Dali::Application application(this);
245 mResetSignalV2.Emit( application );
250 void Application::OnLanguageChanged()
252 mAdaptor->NotifyLanguageChanged();
255 void Application::OnResize(Dali::Adaptor& adaptor)
257 Dali::Application application(this);
258 mResizeSignalV2.Emit( application );
261 bool Application::AddIdle(boost::function<void(void)> callBack)
263 return mAdaptor->AddIdle(callBack);
266 Dali::Adaptor& Application::GetAdaptor()
271 Dali::Window Application::GetWindow()
276 const std::string& Application::GetTheme()
278 return Dali::StyleMonitor::Get().GetTheme();
281 void Application::SetTheme(const std::string& themeFilePath)
283 return Dali::StyleMonitor::Get().SetTheme(themeFilePath);
288 void Application::SetViewMode( ViewMode viewMode )
290 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
293 ViewMode Application::GetViewMode() const
295 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
298 void Application::SetStereoBase( float stereoBase )
300 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
303 float Application::GetStereoBase() const
305 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
309 void Application::ReplaceWindow(PositionSize windowPosition, const std::string& name)
311 Dali::Window newWindow = Dali::Window::New( windowPosition, name, mWindowMode == Dali::Application::TRANSPARENT );
312 Window& windowImpl = GetImplementation(newWindow);
313 windowImpl.SetAdaptor(*mAdaptor);
314 newWindow.ShowIndicator(Dali::Window::INVISIBLE);
315 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
316 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(*renderSurface);
320 } // namespace Adaptor
322 } // namespace Internal