X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=adaptors%2Fcommon%2Fapplication-impl.cpp;h=931ba1218e14ad72d5f0ff8eb87b99806155e18d;hb=1654c8904e689b9fbdbe0bc65ac6a3d827bd6795;hp=d114b39cb9b3dea297ef491564e43cc1fb27bcc1;hpb=a859b4fec592ba891e281a74ebe53048cc90a980;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/adaptors/common/application-impl.cpp b/adaptors/common/application-impl.cpp index d114b39..931ba12 100644 --- a/adaptors/common/application-impl.cpp +++ b/adaptors/common/application-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,15 +25,16 @@ #include #include #include +#include #include #include namespace Dali { -namespace SlpPlatform +namespace TizenPlatform { -class SlpPlatformAbstraction; +class TizenPlatformAbstraction; } namespace Integration @@ -47,82 +48,97 @@ namespace Internal namespace Adaptor { -namespace -{ -// Defaults taken from H2 device -const unsigned int DEFAULT_WINDOW_WIDTH = 480; -const unsigned int DEFAULT_WINDOW_HEIGHT = 800; -} - ApplicationPtr Application::New( int* argc, char **argv[], - const std::string& name, - const DeviceLayout& baseLayout, - Dali::Application::WINDOW_MODE windowMode) + const std::string& stylesheet, + Dali::Application::WINDOW_MODE windowMode, + Framework::Type applicationType) { - ApplicationPtr application ( new Application (argc, argv, name, baseLayout, windowMode ) ); + ApplicationPtr application ( new Application (argc, argv, stylesheet, windowMode, applicationType ) ); return application; } -Application::Application( int* argc, char** argv[], const std::string& name, const DeviceLayout& baseLayout, Dali::Application::WINDOW_MODE windowMode) +Application::Application( int* argc, char** argv[], const std::string& stylesheet, + Dali::Application::WINDOW_MODE windowMode, Framework::Type applicationType ) : mInitSignal(), mTerminateSignal(), mPauseSignal(), mResumeSignal(), mResetSignal(), mResizeSignal(), + mAppControlSignal(), mLanguageChangedSignal(), + mRegionChangedSignal(), + mBatteryLowSignal(), + mMemoryLowSignal(), mEventLoop( NULL ), mFramework( NULL ), + mContextLossConfiguration( Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS ), mCommandLineOptions( NULL ), mSingletonService( SingletonService::New() ), mAdaptor( NULL ), mWindow(), mWindowMode( windowMode ), - mName( name ), - mInitialized( false ), - mBaseLayout( baseLayout ), + mName(), + mStylesheet( stylesheet ), + mEnvironmentOptions(), mSlotDelegate( this ) { - mCommandLineOptions = new CommandLineOptions(argc, argv); + // Get mName from environment options + mName = mEnvironmentOptions.GetWindowName(); + if( mName.empty() && argc && ( *argc > 0 ) ) + { + // Set mName from command-line args if environment option not set + mName = (*argv)[0]; + } - mFramework = new Framework(*this, argc, argv, name); + mCommandLineOptions = new CommandLineOptions(argc, argv); + mFramework = new Framework( *this, argc, argv, applicationType ); + mUseRemoteSurface = (applicationType == Framework::WATCH); } Application::~Application() { mSingletonService.UnregisterAll(); - delete mFramework; - delete mCommandLineOptions; - delete mAdaptor; mWindow.Reset(); + delete mAdaptor; + delete mCommandLineOptions; + delete mFramework; } void Application::CreateWindow() { -#ifndef __arm__ - PositionSize windowPosition(0, 0, DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT); -#else - PositionSize windowPosition(0, 0, 0, 0); // this will use full screen -#endif - if (mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0) + PositionSize windowPosition(0, 0, 0, 0); // this will use full screen + + if( mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0 ) + { + // Command line options override environment options and full screen + windowPosition = PositionSize( 0, 0, mCommandLineOptions->stageWidth, mCommandLineOptions->stageHeight ); + } + else if( mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight() ) { - // let the command line options over ride - windowPosition = PositionSize(0,0,mCommandLineOptions->stageWidth,mCommandLineOptions->stageHeight); + // Environment options override full screen functionality if command line arguments not provided + windowPosition = PositionSize( 0, 0, mEnvironmentOptions.GetWindowWidth(), mEnvironmentOptions.GetWindowHeight() ); } - mWindow = Dali::Window::New( windowPosition, mName, mWindowMode == Dali::Application::TRANSPARENT ); + const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName(); + mWindow = Dali::Window::New( windowPosition, mName, windowClassName, mWindowMode == Dali::Application::TRANSPARENT ); + + // Quit the application when the window is closed + GetImplementation( mWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit ); } void Application::CreateAdaptor() { DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" ); - mAdaptor = &Dali::Adaptor::New( mWindow, mBaseLayout, mContextLossConfiguration ); + mAdaptor = Dali::Internal::Adaptor::Adaptor::New( mWindow, mContextLossConfiguration, &mEnvironmentOptions ); mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize ); + + Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( mUseRemoteSurface ); } void Application::MainLoop(Dali::Configuration::ContextLoss configuration) @@ -142,32 +158,26 @@ void Application::Lower() void Application::Quit() { // Actually quit the application. - AddIdle(boost::bind(&Application::QuitFromMainLoop, this)); + AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ) ); } void Application::QuitFromMainLoop() { mAdaptor->Stop(); - Dali::Application application(this); - mTerminateSignal.Emit( application ); - mFramework->Quit(); // This will trigger OnTerminate(), below, after the main loop has completed. - mInitialized = false; } -void Application::OnInit() +void Application::DoInit() { - mFramework->AddAbortCallback(boost::bind(&Application::QuitFromMainLoop, this)); - CreateWindow(); CreateAdaptor(); // Run the adaptor mAdaptor->Start(); - // Check if user requires no vsyncing and set on X11 Adaptor + // Check if user requires no vsyncing and set Adaptor if (mCommandLineOptions->noVSyncOnRender) { mAdaptor->SetUseHardwareVSync(false); @@ -184,7 +194,45 @@ void Application::OnInit() Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode ); } - mInitialized = true; + if( ! mStylesheet.empty() ) + { + Dali::StyleMonitor::Get().SetTheme( mStylesheet ); + } + + mAdaptor->NotifySceneCreated(); +} + +void Application::DoTerminate() +{ + if( mAdaptor ) + { + // Ensure that the render-thread is not using the surface(window) after we delete it + mAdaptor->Stop(); + } + + mWindow.Reset(); +} + +void Application::DoPause() +{ + mAdaptor->Pause(); +} + +void Application::DoResume() +{ + mAdaptor->Resume(); +} + +void Application::DoLanguageChange() +{ + mAdaptor->NotifyLanguageChanged(); +} + +void Application::OnInit() +{ + mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) ); + + DoInit(); // Wire up the LifecycleController Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get(); @@ -199,8 +247,6 @@ void Application::OnInit() Dali::Application application(this); mInitSignal.Emit( application ); - - Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetCore().SceneCreated(); } void Application::OnTerminate() @@ -208,22 +254,26 @@ void Application::OnTerminate() // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously // delete the window as ecore_x has been destroyed by AppCore - mWindow.Reset(); - mInitialized = false; + Dali::Application application(this); + mTerminateSignal.Emit( application ); + + DoTerminate(); } void Application::OnPause() { - mAdaptor->Pause(); + DoPause(); Dali::Application application(this); mPauseSignal.Emit( application ); } void Application::OnResume() { - mAdaptor->Resume(); + // Emit the signal first so the application can queue any messages before we do an update/render + // This ensures we do not just redraw the last frame before pausing if that's not required Dali::Application application(this); mResumeSignal.Emit( application ); + DoResume(); } void Application::OnReset() @@ -234,44 +284,58 @@ void Application::OnReset() */ Dali::Application application(this); mResetSignal.Emit( application ); +} - mWindow.Raise(); +void Application::OnAppControl(void *data) +{ + Dali::Application application(this); + mAppControlSignal.Emit( application , data ); } void Application::OnLanguageChanged() { - mAdaptor->NotifyLanguageChanged(); + DoLanguageChange(); + Dali::Application application(this); + mLanguageChangedSignal.Emit( application ); } -void Application::OnResize(Dali::Adaptor& adaptor) +void Application::OnRegionChanged() { Dali::Application application(this); - mResizeSignal.Emit( application ); + mRegionChangedSignal.Emit( application ); } -bool Application::AddIdle(boost::function callBack) +void Application::OnBatteryLow() { - return mAdaptor->AddIdle(callBack); + Dali::Application application(this); + mBatteryLowSignal.Emit( application ); } -Dali::Adaptor& Application::GetAdaptor() +void Application::OnMemoryLow() { - return *mAdaptor; + Dali::Application application(this); + mMemoryLowSignal.Emit( application ); } -Dali::Window Application::GetWindow() +void Application::OnResize(Dali::Adaptor& adaptor) { - return mWindow; + Dali::Application application(this); + mResizeSignal.Emit( application ); } -const std::string& Application::GetTheme() +bool Application::AddIdle( CallbackBase* callback ) { - return Dali::StyleMonitor::Get().GetTheme(); + return mAdaptor->AddIdle( callback ); } -void Application::SetTheme(const std::string& themeFilePath) +Dali::Adaptor& Application::GetAdaptor() { - return Dali::StyleMonitor::Get().SetTheme(themeFilePath); + return *mAdaptor; +} + +Dali::Window Application::GetWindow() +{ + return mWindow; } // Stereoscopy @@ -304,10 +368,18 @@ void Application::ReplaceWindow(PositionSize windowPosition, const std::string& windowImpl.SetAdaptor(*mAdaptor); newWindow.ShowIndicator(Dali::Window::INVISIBLE); Dali::RenderSurface* renderSurface = windowImpl.GetSurface(); - Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(*renderSurface); + + Any nativeWindow = newWindow.GetNativeHandle(); + Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SurfaceSizeChanged( windowPosition ); + Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(nativeWindow, *renderSurface); mWindow = newWindow; } +std::string Application::GetResourcePath() +{ + return Internal::Adaptor::Framework::GetResourcePath(); +} + } // namespace Adaptor } // namespace Internal