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>
35 class SlpPlatformAbstraction;
51 // Defaults taken from H2 device
52 const unsigned int DEFAULT_WINDOW_WIDTH = 480;
53 const unsigned int DEFAULT_WINDOW_HEIGHT = 800;
54 const float DEFAULT_HORIZONTAL_DPI = 220;
55 const float DEFAULT_VERTICAL_DPI = 217;
58 ApplicationPtr Application::New(
61 const std::string& name,
62 const DeviceLayout& baseLayout,
63 Dali::Application::WINDOW_MODE windowMode)
65 ApplicationPtr application ( new Application (argc, argv, name, baseLayout, windowMode ) );
69 Application::Application( int* argc, char** argv[], const std::string& name, const DeviceLayout& baseLayout, Dali::Application::WINDOW_MODE windowMode)
76 mLanguageChangedSignalV2(),
79 mCommandLineOptions( NULL ),
80 mSingletonService( SingletonService::New() ),
83 mWindowMode( windowMode ),
85 mInitialized( false ),
86 mBaseLayout( baseLayout ),
89 mCommandLineOptions = new CommandLineOptions(argc, argv);
91 mFramework = new Framework(*this, argc, argv, name);
94 Application::~Application()
97 delete mCommandLineOptions;
102 void Application::CreateWindow()
105 PositionSize windowPosition(0, 0, DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
107 PositionSize windowPosition(0, 0, 0, 0); // this will use full screen
109 if (mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0)
111 // let the command line options over ride
112 windowPosition = PositionSize(0,0,mCommandLineOptions->stageWidth,mCommandLineOptions->stageHeight);
115 mWindow = Dali::Window::New( windowPosition, mName, mWindowMode == Dali::Application::TRANSPARENT );
118 void Application::CreateAdaptor()
120 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
122 mAdaptor = &Dali::Adaptor::New( mWindow, mBaseLayout, mContextLossConfiguration );
124 // Allow DPI to be overridden from command line.
125 unsigned int hDPI=DEFAULT_HORIZONTAL_DPI;
126 unsigned int vDPI=DEFAULT_VERTICAL_DPI;
128 std::string dpiStr = mCommandLineOptions->stageDPI;
131 sscanf(dpiStr.c_str(), "%ux%u", &hDPI, &vDPI);
133 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetDpi(hDPI, vDPI);
135 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
138 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
140 mContextLossConfiguration = configuration;
142 // Run the application
146 void Application::Lower()
148 // Lower the application without quitting it.
152 void Application::Quit()
154 // Actually quit the application.
155 AddIdle(boost::bind(&Application::QuitFromMainLoop, this));
158 void Application::QuitFromMainLoop()
162 Dali::Application application(this);
163 mTerminateSignalV2.Emit( application );
166 // This will trigger OnTerminate(), below, after the main loop has completed.
167 mInitialized = false;
170 void Application::OnInit()
172 mFramework->AddAbortCallback(boost::bind(&Application::QuitFromMainLoop, this));
180 // Check if user requires no vsyncing and set on X11 Adaptor
181 if (mCommandLineOptions->noVSyncOnRender)
183 mAdaptor->SetUseHardwareVSync(false);
186 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
187 if( mCommandLineOptions->viewMode != 0 )
189 ViewMode viewMode = MONO;
190 if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
192 viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
194 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
199 Dali::Application application(this);
200 mInitSignalV2.Emit( application );
203 void Application::OnTerminate()
205 // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
206 // delete the window as ecore_x has been destroyed by AppCore
209 mInitialized = false;
212 void Application::OnPause()
215 Dali::Application application(this);
216 mPauseSignalV2.Emit( application );
219 void Application::OnResume()
222 Dali::Application application(this);
223 mResumeSignalV2.Emit( application );
226 void Application::OnReset()
229 * usually, reset callback was called when a caller request to launch this application via aul.
230 * because Application class already handled initialization in OnInit(), OnReset do nothing.
232 Dali::Application application(this);
233 mResetSignalV2.Emit( application );
238 void Application::OnLanguageChanged()
240 mAdaptor->NotifyLanguageChanged();
243 void Application::OnResize(Dali::Adaptor& adaptor)
245 Dali::Application application(this);
246 mResizeSignalV2.Emit( application );
249 bool Application::AddIdle(boost::function<void(void)> callBack)
251 return mAdaptor->AddIdle(callBack);
254 Dali::Adaptor& Application::GetAdaptor()
259 Dali::Window Application::GetWindow()
264 const std::string& Application::GetTheme()
266 return Dali::StyleMonitor::Get().GetTheme();
269 void Application::SetTheme(const std::string& themeFilePath)
271 return Dali::StyleMonitor::Get().SetTheme(themeFilePath);
276 void Application::SetViewMode( ViewMode viewMode )
278 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
281 ViewMode Application::GetViewMode() const
283 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
286 void Application::SetStereoBase( float stereoBase )
288 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
291 float Application::GetStereoBase() const
293 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
297 void Application::ReplaceWindow(PositionSize windowPosition, const std::string& name)
299 Dali::Window newWindow = Dali::Window::New( windowPosition, name, mWindowMode == Dali::Application::TRANSPARENT );
300 Window& windowImpl = GetImplementation(newWindow);
301 windowImpl.SetAdaptor(*mAdaptor);
302 newWindow.ShowIndicator(Dali::Window::INVISIBLE);
303 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
304 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(*renderSurface);
308 } // namespace Adaptor
310 } // namespace Internal