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>
36 class SlpPlatformAbstraction;
52 // Defaults taken from H2 device
53 const unsigned int DEFAULT_WINDOW_WIDTH = 480;
54 const unsigned int DEFAULT_WINDOW_HEIGHT = 800;
57 ApplicationPtr Application::New(
60 const std::string& name,
61 const DeviceLayout& baseLayout,
62 Dali::Application::WINDOW_MODE windowMode)
64 ApplicationPtr application ( new Application (argc, argv, name, baseLayout, windowMode ) );
68 Application::Application( int* argc, char** argv[], const std::string& name, const DeviceLayout& baseLayout, Dali::Application::WINDOW_MODE windowMode)
75 mLanguageChangedSignal(),
78 mCommandLineOptions( NULL ),
79 mSingletonService( SingletonService::New() ),
82 mWindowMode( windowMode ),
84 mInitialized( false ),
85 mBaseLayout( baseLayout ),
88 mCommandLineOptions = new CommandLineOptions(argc, argv);
90 mFramework = new Framework(*this, argc, argv, name);
93 Application::~Application()
95 mSingletonService.UnregisterAll();
98 delete mCommandLineOptions;
103 void Application::CreateWindow()
106 PositionSize windowPosition(0, 0, DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
108 PositionSize windowPosition(0, 0, 0, 0); // this will use full screen
110 if (mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0)
112 // let the command line options over ride
113 windowPosition = PositionSize(0,0,mCommandLineOptions->stageWidth,mCommandLineOptions->stageHeight);
116 mWindow = Dali::Window::New( windowPosition, mName, mWindowMode == Dali::Application::TRANSPARENT );
119 void Application::CreateAdaptor()
121 DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" );
123 mAdaptor = &Dali::Adaptor::New( mWindow, mBaseLayout, mContextLossConfiguration );
125 mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
128 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
130 mContextLossConfiguration = configuration;
132 // Run the application
136 void Application::Lower()
138 // Lower the application without quitting it.
142 void Application::Quit()
144 // Actually quit the application.
145 AddIdle(boost::bind(&Application::QuitFromMainLoop, this));
148 void Application::QuitFromMainLoop()
152 Dali::Application application(this);
153 mTerminateSignal.Emit( application );
156 // This will trigger OnTerminate(), below, after the main loop has completed.
157 mInitialized = false;
160 void Application::OnInit()
162 mFramework->AddAbortCallback(boost::bind(&Application::QuitFromMainLoop, this));
170 // Check if user requires no vsyncing and set on X11 Adaptor
171 if (mCommandLineOptions->noVSyncOnRender)
173 mAdaptor->SetUseHardwareVSync(false);
176 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
177 if( mCommandLineOptions->viewMode != 0 )
179 ViewMode viewMode = MONO;
180 if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
182 viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
184 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
189 // Wire up the LifecycleController
190 Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
192 InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
193 TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
194 PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
195 ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
196 ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
197 ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
198 LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );
200 Dali::Application application(this);
201 mInitSignal.Emit( application );
203 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetCore().SceneCreated();
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 mPauseSignal.Emit( application );
222 void Application::OnResume()
225 Dali::Application application(this);
226 mResumeSignal.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 mResetSignal.Emit( application );
241 void Application::OnLanguageChanged()
243 mAdaptor->NotifyLanguageChanged();
246 void Application::OnResize(Dali::Adaptor& adaptor)
248 Dali::Application application(this);
249 mResizeSignal.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 const std::string& Application::GetTheme()
269 return Dali::StyleMonitor::Get().GetTheme();
272 void Application::SetTheme(const std::string& themeFilePath)
274 return Dali::StyleMonitor::Get().SetTheme(themeFilePath);
279 void Application::SetViewMode( ViewMode viewMode )
281 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
284 ViewMode Application::GetViewMode() const
286 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
289 void Application::SetStereoBase( float stereoBase )
291 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
294 float Application::GetStereoBase() const
296 return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
300 void Application::ReplaceWindow(PositionSize windowPosition, const std::string& name)
302 Dali::Window newWindow = Dali::Window::New( windowPosition, name, mWindowMode == Dali::Application::TRANSPARENT );
303 Window& windowImpl = GetImplementation(newWindow);
304 windowImpl.SetAdaptor(*mAdaptor);
305 newWindow.ShowIndicator(Dali::Window::INVISIBLE);
306 Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
307 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(*renderSurface);
311 } // namespace Adaptor
313 } // namespace Internal