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>
34 class SlpPlatformAbstraction;
50 // Defaults taken from H2 device
51 const unsigned int DEFAULT_WINDOW_WIDTH = 480;
52 const unsigned int DEFAULT_WINDOW_HEIGHT = 800;
53 const float DEFAULT_HORIZONTAL_DPI = 220;
54 const float DEFAULT_VERTICAL_DPI = 217;
56 boost::thread_specific_ptr<Application> gThreadLocalApplication;
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(
73 const std::string& name,
74 const DeviceLayout& baseLayout,
75 Dali::Application::WINDOW_MODE windowMode)
77 mCommandLineOptions(NULL),
80 mWindowMode( windowMode ),
83 mBaseLayout(baseLayout),
86 // make sure we don't create the local thread application instance twice
87 DALI_ASSERT_ALWAYS(gThreadLocalApplication.get() == NULL && "Cannot create more than one Application per thread" );
89 // reset is used to store a new value associated with this thread
90 gThreadLocalApplication.reset(this);
92 mCommandLineOptions = new CommandLineOptions(argc, argv);
94 mFramework = new Framework(*this, argc, argv, name);
97 Application::~Application()
100 delete mCommandLineOptions;
103 gThreadLocalApplication.release();
106 void Application::CreateWindow()
109 PositionSize windowPosition(0, 0, DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
111 PositionSize windowPosition(0, 0, 0, 0); // this will use full screen
113 if (mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0)
115 // let the command line options over ride
116 windowPosition = PositionSize(0,0,mCommandLineOptions->stageWidth,mCommandLineOptions->stageHeight);
119 mWindow = Dali::Window::New( windowPosition, mName, mWindowMode == Dali::Application::TRANSPARENT );
122 void Application::CreateAdaptor()
124 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
126 mAdaptor = &Dali::Adaptor::New( mWindow, mBaseLayout);
128 // Allow DPI to be overridden from command line.
129 unsigned int hDPI=DEFAULT_HORIZONTAL_DPI;
130 unsigned int vDPI=DEFAULT_VERTICAL_DPI;
132 std::string dpiStr = mCommandLineOptions->stageDPI;
135 sscanf(dpiStr.c_str(), "%ux%u", &hDPI, &vDPI);
137 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetDpi(hDPI, vDPI);
139 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
142 void Application::MainLoop()
144 // Run the application
148 void Application::Lower()
150 // Lower the application without quitting it.
154 void Application::Quit()
156 // Actually quit the application.
157 AddIdle(boost::bind(&Application::QuitFromMainLoop, this));
160 void Application::QuitFromMainLoop()
164 Dali::Application application(this);
165 mTerminateSignalV2.Emit( application );
168 // This will trigger OnTerminate(), below, after the main loop has completed.
169 mInitialized = false;
172 void Application::OnInit()
174 mFramework->AddAbortCallback(boost::bind(&Application::QuitFromMainLoop, this));
182 // Check if user requires no vsyncing and set on X11 Adaptor
183 if (mCommandLineOptions->noVSyncOnRender)
185 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).DisableVSync();
188 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
189 if( mCommandLineOptions->viewMode != 0 )
191 ViewMode viewMode = MONO;
192 if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
194 viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
196 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
201 // in default, auto hide indicator mode
202 mWindow.ShowIndicator(Dali::Window::AUTO);
204 Dali::Application application(this);
205 mInitSignalV2.Emit( application );
208 void Application::OnTerminate()
210 // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
211 // delete the window as ecore_x has been destroyed by AppCore
214 mInitialized = false;
217 void Application::OnPause()
220 Dali::Application application(this);
221 mPauseSignalV2.Emit( application );
224 void Application::OnResume()
227 Dali::Application application(this);
228 mResumeSignalV2.Emit( application );
231 void Application::OnReset()
234 * usually, reset callback was called when a caller request to launch this application via aul.
235 * because Application class already handled initialization in OnInit(), OnReset do nothing.
237 Dali::Application application(this);
238 mResetSignalV2.Emit( application );
243 void Application::OnLanguageChanged()
245 mAdaptor->NotifyLanguageChanged();
248 void Application::OnResize(Dali::Adaptor& adaptor)
250 Dali::Application application(this);
251 mResizeSignalV2.Emit( application );
254 bool Application::AddIdle(boost::function<void(void)> callBack)
256 return mAdaptor->AddIdle(callBack);
259 Dali::Adaptor& Application::GetAdaptor()
264 Dali::Window Application::GetWindow()
269 Dali::Application Application::Get()
271 DALI_ASSERT_ALWAYS( gThreadLocalApplication.get() != NULL && "Application not instantiated" );
273 Dali::Application application(gThreadLocalApplication.get());
278 const std::string& Application::GetTheme()
280 return Dali::StyleMonitor::Get().GetTheme();
283 void Application::SetTheme(const std::string& themeFilePath)
285 return Dali::StyleMonitor::Get().SetTheme(themeFilePath);
290 void Application::SetViewMode( ViewMode viewMode )
292 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
295 ViewMode Application::GetViewMode() const
297 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
300 void Application::SetStereoBase( float stereoBase )
302 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
305 float Application::GetStereoBase() const
307 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
310 } // namespace Adaptor
312 } // namespace Internal