2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include "application-impl.h"
22 #include <dali/integration-api/debug.h>
23 #include <dali/public-api/adaptor-framework/common/style-monitor.h>
26 #include <internal/command-line-options.h>
27 #include <internal/common/adaptor-impl.h>
28 #include <internal/common/ecore-x/ecore-x-render-surface.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;
57 boost::thread_specific_ptr<Application> gThreadLocalApplication;
60 ApplicationPtr Application::New(
63 const std::string& name,
64 const DeviceLayout& baseLayout,
65 Dali::Application::WINDOW_MODE windowMode)
67 ApplicationPtr application ( new Application (argc, argv, name, baseLayout, windowMode ) );
71 Application::Application(
74 const std::string& name,
75 const DeviceLayout& baseLayout,
76 Dali::Application::WINDOW_MODE windowMode)
78 mCommandLineOptions(NULL),
81 mWindowMode( windowMode ),
84 mBaseLayout(baseLayout),
87 // make sure we don't create the local thread application instance twice
88 DALI_ASSERT_ALWAYS(gThreadLocalApplication.get() == NULL && "Cannot create more than one Application per thread" );
90 // reset is used to store a new value associated with this thread
91 gThreadLocalApplication.reset(this);
93 mCommandLineOptions = new CommandLineOptions(argc, argv);
95 mFramework = new Framework(*this, argc, argv, name);
98 Application::~Application()
101 delete mCommandLineOptions;
104 gThreadLocalApplication.release();
107 void Application::CreateWindow()
110 PositionSize windowPosition(0, 0, DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
112 PositionSize windowPosition(0, 0, 0, 0); // this will use full screen
114 if (mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0)
116 // let the command line options over ride
117 windowPosition = PositionSize(0,0,mCommandLineOptions->stageWidth,mCommandLineOptions->stageHeight);
120 mWindow = Dali::Window::New( windowPosition, mName, mWindowMode == Dali::Application::TRANSPARENT );
123 void Application::CreateAdaptor()
125 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
127 mAdaptor = &Dali::Adaptor::New( mWindow, mBaseLayout);
129 // Allow DPI to be overridden from command line.
130 unsigned int hDPI=DEFAULT_HORIZONTAL_DPI;
131 unsigned int vDPI=DEFAULT_VERTICAL_DPI;
133 std::string dpiStr = mCommandLineOptions->stageDPI;
136 sscanf(dpiStr.c_str(), "%ux%u", &hDPI, &vDPI);
138 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetDpi(hDPI, vDPI);
140 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
143 void Application::MainLoop()
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 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).DisableVSync();
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 Dali::Application application(this);
203 mInitSignalV2.Emit( application );
206 void Application::OnTerminate()
208 // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
209 // delete the window as ecore_x has been destroyed by AppCore
212 mInitialized = false;
215 void Application::OnPause()
218 Dali::Application application(this);
219 mPauseSignalV2.Emit( application );
222 void Application::OnResume()
225 Dali::Application application(this);
226 mResumeSignalV2.Emit( application );
229 void Application::OnReset()
232 * usually, reset callback was called when a caller request to launch this application via aul.
233 * because Application class already handled initialization in OnInit(), OnReset do nothing.
235 Dali::Application application(this);
236 mResetSignalV2.Emit( application );
241 void Application::OnLanguageChanged()
243 mAdaptor->NotifyLanguageChanged();
246 void Application::OnResize(Dali::Adaptor& adaptor)
248 Dali::Application application(this);
249 mResizeSignalV2.Emit( application );
252 bool Application::AddIdle(boost::function<void(void)> callBack)
254 return mAdaptor->AddIdle(callBack);
257 Dali::Adaptor& Application::GetAdaptor()
262 Dali::Window Application::GetWindow()
267 Dali::Application Application::Get()
269 DALI_ASSERT_ALWAYS( gThreadLocalApplication.get() != NULL && "Application not instantiated" );
271 Dali::Application application(gThreadLocalApplication.get());
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();
308 } // namespace Adaptor
310 } // namespace Internal