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 <singleton-service-impl.h>
29 #include <lifecycle-controller-impl.h>
31 // CONDITIONAL INCLUDES
32 #ifdef DALI_ELDBUS_AVAILABLE
34 #endif // DALI_ELDBUS_AVAILABLE
39 namespace TizenPlatform
41 class TizenPlatformAbstraction;
55 #if defined(DEBUG_ENABLED)
58 Integration::Log::Filter* gDBusLogging = Integration::Log::Filter::New( Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DBUS" );
59 } // anonymous namespace
62 ApplicationPtr Application::New(
65 const std::string& stylesheet,
66 Dali::Application::WINDOW_MODE windowMode,
67 Framework::Type applicationType)
69 ApplicationPtr application ( new Application (argc, argv, stylesheet, windowMode, applicationType ) );
73 Application::Application( int* argc, char** argv[], const std::string& stylesheet,
74 Dali::Application::WINDOW_MODE windowMode, Framework::Type applicationType )
82 mLanguageChangedSignal(),
83 mRegionChangedSignal(),
88 mContextLossConfiguration( Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS ),
89 mCommandLineOptions( NULL ),
90 mSingletonService( SingletonService::New() ),
93 mWindowMode( windowMode ),
95 mStylesheet( stylesheet ),
96 mEnvironmentOptions(),
99 // Get mName from environment options
100 mName = mEnvironmentOptions.GetWindowName();
101 if( mName.empty() && argc && ( *argc > 0 ) )
103 // Set mName from command-line args if environment option not set
107 mCommandLineOptions = new CommandLineOptions(argc, argv);
108 mFramework = new Framework( *this, argc, argv, applicationType );
109 mUseRemoteSurface = (applicationType == Framework::WATCH);
112 Application::~Application()
114 mSingletonService.UnregisterAll();
117 delete mCommandLineOptions;
120 #ifdef DALI_ELDBUS_AVAILABLE
122 DALI_LOG_INFO( gDBusLogging, Debug::General, "Shutting down DBus\n" );
129 void Application::CreateWindow()
131 PositionSize windowPosition(0, 0, 0, 0); // this will use full screen
133 if( mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0 )
135 // Command line options override environment options and full screen
136 windowPosition = PositionSize( 0, 0, mCommandLineOptions->stageWidth, mCommandLineOptions->stageHeight );
138 else if( mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight() )
140 // Environment options override full screen functionality if command line arguments not provided
141 windowPosition = PositionSize( 0, 0, mEnvironmentOptions.GetWindowWidth(), mEnvironmentOptions.GetWindowHeight() );
144 const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName();
145 mWindow = Dali::Window::New( windowPosition, mName, windowClassName, mWindowMode == Dali::Application::TRANSPARENT );
147 // Quit the application when the window is closed
148 GetImplementation( mWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit );
151 void Application::CreateAdaptor()
153 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
155 mAdaptor = Dali::Internal::Adaptor::Adaptor::New( mWindow, mContextLossConfiguration, &mEnvironmentOptions );
157 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
159 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( mUseRemoteSurface );
162 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
164 mContextLossConfiguration = configuration;
166 // Run the application
170 void Application::Lower()
172 // Lower the application without quitting it.
176 void Application::Quit()
178 // Actually quit the application.
179 AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ) );
182 void Application::QuitFromMainLoop()
187 // This will trigger OnTerminate(), below, after the main loop has completed.
190 void Application::OnInit()
192 mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
196 #ifdef DALI_ELDBUS_AVAILABLE
197 // Initialize ElDBus.
198 DALI_LOG_INFO( gDBusLogging, Debug::General, "Starting DBus Initialization\n" );
206 // Check if user requires no vsyncing and set on X11 Adaptor
207 if (mCommandLineOptions->noVSyncOnRender)
209 mAdaptor->SetUseHardwareVSync(false);
212 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
213 if( mCommandLineOptions->viewMode != 0 )
215 ViewMode viewMode = MONO;
216 if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
218 viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
220 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
223 if( ! mStylesheet.empty() )
225 Dali::StyleMonitor::Get().SetTheme( mStylesheet );
228 // Wire up the LifecycleController
229 Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
231 InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
232 TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
233 PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
234 ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
235 ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
236 ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
237 LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );
239 Dali::Application application(this);
240 mInitSignal.Emit( application );
242 mAdaptor->NotifySceneCreated();
245 void Application::OnTerminate()
247 // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously
248 // delete the window as ecore_x has been destroyed by AppCore
250 Dali::Application application(this);
251 mTerminateSignal.Emit( application );
255 // Ensure that the render-thread is not using the surface(window) after we delete it
262 void Application::OnPause()
265 Dali::Application application(this);
266 mPauseSignal.Emit( application );
269 void Application::OnResume()
271 // Emit the signal first so the application can queue any messages before we do an update/render
272 // This ensures we do not just redraw the last frame before pausing if that's not required
273 Dali::Application application(this);
274 mResumeSignal.Emit( application );
278 void Application::OnReset()
281 * usually, reset callback was called when a caller request to launch this application via aul.
282 * because Application class already handled initialization in OnInit(), OnReset do nothing.
284 Dali::Application application(this);
285 mResetSignal.Emit( application );
288 void Application::OnAppControl(void *data)
290 Dali::Application application(this);
291 mAppControlSignal.Emit( application , data );
294 void Application::OnLanguageChanged()
296 mAdaptor->NotifyLanguageChanged();
297 Dali::Application application(this);
298 mLanguageChangedSignal.Emit( application );
301 void Application::OnRegionChanged()
303 Dali::Application application(this);
304 mRegionChangedSignal.Emit( application );
307 void Application::OnBatteryLow()
309 Dali::Application application(this);
310 mBatteryLowSignal.Emit( application );
313 void Application::OnMemoryLow()
315 Dali::Application application(this);
316 mMemoryLowSignal.Emit( application );
319 void Application::OnResize(Dali::Adaptor& adaptor)
321 Dali::Application application(this);
322 mResizeSignal.Emit( application );
325 bool Application::AddIdle( CallbackBase* callback )
327 return mAdaptor->AddIdle( callback );
330 Dali::Adaptor& Application::GetAdaptor()
335 Dali::Window Application::GetWindow()
342 void Application::SetViewMode( ViewMode viewMode )
344 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
347 ViewMode Application::GetViewMode() const
349 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
352 void Application::SetStereoBase( float stereoBase )
354 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
357 float Application::GetStereoBase() const
359 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
363 void Application::ReplaceWindow(PositionSize windowPosition, const std::string& name)
365 Dali::Window newWindow = Dali::Window::New( windowPosition, name, mWindowMode == Dali::Application::TRANSPARENT );
366 Window& windowImpl = GetImplementation(newWindow);
367 windowImpl.SetAdaptor(*mAdaptor);
368 newWindow.ShowIndicator(Dali::Window::INVISIBLE);
369 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
371 Any nativeWindow = newWindow.GetNativeHandle();
372 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SurfaceSizeChanged( windowPosition );
373 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(nativeWindow, *renderSurface);
377 } // namespace Adaptor
379 } // namespace Internal