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>
25 #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>
34 namespace TizenPlatform
36 class TizenPlatformAbstraction;
50 ApplicationPtr Application::New(
53 const std::string& name,
54 const DeviceLayout& baseLayout,
55 Dali::Application::WINDOW_MODE windowMode)
57 ApplicationPtr application ( new Application (argc, argv, name, baseLayout, windowMode ) );
61 Application::Application( int* argc, char** argv[], const std::string& name, const DeviceLayout& baseLayout, Dali::Application::WINDOW_MODE windowMode)
69 mLanguageChangedSignal(),
70 mRegionChangedSignal(),
75 mCommandLineOptions( NULL ),
76 mSingletonService( SingletonService::New() ),
79 mWindowMode( windowMode ),
81 mInitialized( false ),
82 mBaseLayout( baseLayout ),
85 mCommandLineOptions = new CommandLineOptions(argc, argv);
87 mFramework = new Framework(*this, argc, argv, name);
90 Application::~Application()
92 mSingletonService.UnregisterAll();
95 delete mCommandLineOptions;
100 void Application::CreateWindow()
102 PositionSize windowPosition(0, 0, 0, 0); // this will use full screen
104 if( mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0 )
106 // let the command line options over ride
107 windowPosition = PositionSize( 0, 0, mCommandLineOptions->stageWidth, mCommandLineOptions->stageHeight );
110 mWindow = Dali::Window::New( windowPosition, mName, mWindowMode == Dali::Application::TRANSPARENT );
113 void Application::CreateAdaptor()
115 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
117 mAdaptor = &Dali::Adaptor::New( mWindow, mBaseLayout, mContextLossConfiguration );
119 std::string dpiStr = mCommandLineOptions->stageDPI;
122 // Use DPI from command line.
123 unsigned int hDPI = 0;
124 unsigned int vDPI = 0;
126 sscanf(dpiStr.c_str(), "%ux%u", &hDPI, &vDPI);
128 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetDpi(hDPI, vDPI);
131 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
134 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
136 mContextLossConfiguration = configuration;
138 // Run the application
142 void Application::Lower()
144 // Lower the application without quitting it.
148 void Application::Quit()
150 // Actually quit the application.
151 AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ) );
154 void Application::QuitFromMainLoop()
158 Dali::Application application(this);
159 mTerminateSignal.Emit( application );
162 // This will trigger OnTerminate(), below, after the main loop has completed.
163 mInitialized = false;
166 void Application::OnInit()
168 mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
176 // Check if user requires no vsyncing and set on X11 Adaptor
177 if (mCommandLineOptions->noVSyncOnRender)
179 mAdaptor->SetUseHardwareVSync(false);
182 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
183 if( mCommandLineOptions->viewMode != 0 )
185 ViewMode viewMode = MONO;
186 if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
188 viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
190 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
195 // Wire up the LifecycleController
196 Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
198 InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
199 TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
200 PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
201 ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
202 ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
203 ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
204 LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );
206 Dali::Application application(this);
207 mInitSignal.Emit( application );
209 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetCore().SceneCreated();
212 void Application::OnTerminate()
214 // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
215 // delete the window as ecore_x has been destroyed by AppCore
218 mInitialized = false;
221 void Application::OnPause()
224 Dali::Application application(this);
225 mPauseSignal.Emit( application );
228 void Application::OnResume()
231 Dali::Application application(this);
232 mResumeSignal.Emit( application );
235 void Application::OnReset()
238 * usually, reset callback was called when a caller request to launch this application via aul.
239 * because Application class already handled initialization in OnInit(), OnReset do nothing.
241 Dali::Application application(this);
242 mResetSignal.Emit( application );
247 void Application::OnAppControl(void *data)
249 Dali::Application application(this);
250 mAppControlSignal.Emit( application , data );
253 void Application::OnLanguageChanged()
255 mAdaptor->NotifyLanguageChanged();
258 void Application::OnRegionChanged()
260 Dali::Application application(this);
261 mRegionChangedSignal.Emit( application );
264 void Application::OnBatteryLow()
266 Dali::Application application(this);
267 mBatteryLowSignal.Emit( application );
270 void Application::OnMemoryLow()
272 Dali::Application application(this);
273 mMemoryLowSignal.Emit( application );
276 void Application::OnResize(Dali::Adaptor& adaptor)
278 Dali::Application application(this);
279 mResizeSignal.Emit( application );
282 bool Application::AddIdle( CallbackBase* callback )
284 return mAdaptor->AddIdle( callback );
287 Dali::Adaptor& Application::GetAdaptor()
292 Dali::Window Application::GetWindow()
297 const std::string& Application::GetTheme()
299 return Dali::StyleMonitor::Get().GetTheme();
302 void Application::SetTheme(const std::string& themeFilePath)
304 return Dali::StyleMonitor::Get().SetTheme(themeFilePath);
309 void Application::SetViewMode( ViewMode viewMode )
311 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
314 ViewMode Application::GetViewMode() const
316 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
319 void Application::SetStereoBase( float stereoBase )
321 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
324 float Application::GetStereoBase() const
326 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
330 void Application::ReplaceWindow(PositionSize windowPosition, const std::string& name)
332 Dali::Window newWindow = Dali::Window::New( windowPosition, name, mWindowMode == Dali::Application::TRANSPARENT );
333 Window& windowImpl = GetImplementation(newWindow);
334 windowImpl.SetAdaptor(*mAdaptor);
335 newWindow.ShowIndicator(Dali::Window::INVISIBLE);
336 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
338 Any nativeWindow = newWindow.GetNativeHandle();
339 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(nativeWindow, *renderSurface);
343 } // namespace Adaptor
345 } // namespace Internal