2 * Copyright (c) 2016 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 <common/framework.h>
29 #include <singleton-service-impl.h>
30 #include <lifecycle-controller-impl.h>
35 namespace TizenPlatform
37 class TizenPlatformAbstraction;
51 ApplicationPtr Application::New(
54 const std::string& stylesheet,
55 Dali::Application::WINDOW_MODE windowMode,
56 Framework::Type applicationType)
58 ApplicationPtr application ( new Application (argc, argv, stylesheet, windowMode, applicationType ) );
62 Application::Application( int* argc, char** argv[], const std::string& stylesheet,
63 Dali::Application::WINDOW_MODE windowMode, Framework::Type applicationType )
71 mLanguageChangedSignal(),
72 mRegionChangedSignal(),
77 mContextLossConfiguration( Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS ),
78 mCommandLineOptions( NULL ),
79 mSingletonService( SingletonService::New() ),
82 mWindowMode( windowMode ),
84 mStylesheet( stylesheet ),
85 mEnvironmentOptions(),
88 // Get mName from environment options
89 mName = mEnvironmentOptions.GetWindowName();
90 if( mName.empty() && argc && ( *argc > 0 ) )
92 // Set mName from command-line args if environment option not set
96 mCommandLineOptions = new CommandLineOptions(argc, argv);
97 mFramework = new Framework( *this, argc, argv, applicationType );
98 mUseRemoteSurface = (applicationType == Framework::WATCH);
101 Application::~Application()
103 mSingletonService.UnregisterAll();
107 delete mCommandLineOptions;
111 void Application::CreateWindow()
113 PositionSize windowPosition(0, 0, 0, 0); // this will use full screen
115 if( mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0 )
117 // Command line options override environment options and full screen
118 windowPosition = PositionSize( 0, 0, mCommandLineOptions->stageWidth, mCommandLineOptions->stageHeight );
120 else if( mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight() )
122 // Environment options override full screen functionality if command line arguments not provided
123 windowPosition = PositionSize( 0, 0, mEnvironmentOptions.GetWindowWidth(), mEnvironmentOptions.GetWindowHeight() );
126 const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName();
127 mWindow = Dali::Window::New( windowPosition, mName, windowClassName, mWindowMode == Dali::Application::TRANSPARENT );
129 // Quit the application when the window is closed
130 GetImplementation( mWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit );
133 void Application::CreateAdaptor()
135 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
137 mAdaptor = Dali::Internal::Adaptor::Adaptor::New( mWindow, mContextLossConfiguration, &mEnvironmentOptions );
139 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
141 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( mUseRemoteSurface );
144 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
146 mContextLossConfiguration = configuration;
148 // Run the application
152 void Application::Lower()
154 // Lower the application without quitting it.
158 void Application::Quit()
160 // Actually quit the application.
161 AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ) );
164 void Application::QuitFromMainLoop()
169 // This will trigger OnTerminate(), below, after the main loop has completed.
172 void Application::DoInit()
180 // Check if user requires no vsyncing and set 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 );
197 if( ! mStylesheet.empty() )
199 Dali::StyleMonitor::Get().SetTheme( mStylesheet );
202 mAdaptor->NotifySceneCreated();
205 void Application::DoTerminate()
209 // Ensure that the render-thread is not using the surface(window) after we delete it
216 void Application::DoPause()
221 void Application::DoResume()
226 void Application::DoLanguageChange()
228 mAdaptor->NotifyLanguageChanged();
231 void Application::OnInit()
233 mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
237 // Wire up the LifecycleController
238 Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
240 InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
241 TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
242 PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
243 ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
244 ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
245 ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
246 LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );
248 Dali::Application application(this);
249 mInitSignal.Emit( application );
252 void Application::OnTerminate()
254 // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
255 // delete the window as ecore_x has been destroyed by AppCore
257 Dali::Application application(this);
258 mTerminateSignal.Emit( application );
263 void Application::OnPause()
265 // A DALi app should handle Pause/Resume events.
266 // DALi just delivers the framework Pause event to the application, but not actually pause DALi core.
267 // Pausing DALi core only occurs on the Window Hidden framework event
268 Dali::Application application(this);
269 mPauseSignal.Emit( application );
272 void Application::OnResume()
274 // Emit the signal first so the application can queue any messages before we do an update/render
275 // This ensures we do not just redraw the last frame before pausing if that's not required
276 Dali::Application application(this);
277 mResumeSignal.Emit( application );
279 // DALi just delivers the framework Resume event to the application.
280 // Resuming DALi core only occurs on the Window Show framework event
283 void Application::OnReset()
286 * usually, reset callback was called when a caller request to launch this application via aul.
287 * because Application class already handled initialization in OnInit(), OnReset do nothing.
289 Dali::Application application(this);
290 mResetSignal.Emit( application );
293 void Application::OnAppControl(void *data)
295 Dali::Application application(this);
296 mAppControlSignal.Emit( application , data );
299 void Application::OnLanguageChanged()
302 Dali::Application application(this);
303 mLanguageChangedSignal.Emit( application );
306 void Application::OnRegionChanged()
308 Dali::Application application(this);
309 mRegionChangedSignal.Emit( application );
312 void Application::OnBatteryLow()
314 Dali::Application application(this);
315 mBatteryLowSignal.Emit( application );
318 void Application::OnMemoryLow()
320 Dali::Application application(this);
321 mMemoryLowSignal.Emit( application );
324 void Application::OnResize(Dali::Adaptor& adaptor)
326 Dali::Application application(this);
327 mResizeSignal.Emit( application );
330 bool Application::AddIdle( CallbackBase* callback )
332 return mAdaptor->AddIdle( callback );
335 Dali::Adaptor& Application::GetAdaptor()
340 Dali::Window Application::GetWindow()
347 void Application::SetViewMode( ViewMode viewMode )
349 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
352 ViewMode Application::GetViewMode() const
354 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
357 void Application::SetStereoBase( float stereoBase )
359 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
362 float Application::GetStereoBase() const
364 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
368 void Application::ReplaceWindow(PositionSize windowPosition, const std::string& name)
370 Dali::Window newWindow = Dali::Window::New( windowPosition, name, mWindowMode == Dali::Application::TRANSPARENT );
371 Window& windowImpl = GetImplementation(newWindow);
372 windowImpl.SetAdaptor(*mAdaptor);
373 newWindow.ShowIndicator(Dali::Window::INVISIBLE);
374 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
376 Any nativeWindow = newWindow.GetNativeHandle();
377 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SurfaceSizeChanged( windowPosition );
378 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(nativeWindow, *renderSurface);
382 std::string Application::GetResourcePath()
384 return Internal::Adaptor::Framework::GetResourcePath();
387 } // namespace Adaptor
389 } // namespace Internal