X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fadaptor%2Fcommon%2Fapplication-impl.cpp;h=17d0282fa1bc5f272cf1e153443330b51e3f18ce;hb=6e77f2f2c059b23e19ee8387397192431a88232a;hp=e5a4f45c4783cc3d93036aa04a150c519b30f7a4;hpb=4d3f072f2b4191440ef5b6396a0e033098a87067;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/dali/internal/adaptor/common/application-impl.cpp b/dali/internal/adaptor/common/application-impl.cpp old mode 100644 new mode 100755 index e5a4f45..17d0282 --- a/dali/internal/adaptor/common/application-impl.cpp +++ b/dali/internal/adaptor/common/application-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -20,15 +20,21 @@ // EXTERNAL INCLUDES #include +#include // INTERNAL INCLUDES #include -#include +#include #include +#include #include -#include #include +#include #include +#include + +// To disable a macro with the same name from one of OpenGL headers +#undef Status namespace Dali { @@ -49,6 +55,13 @@ namespace Internal namespace Adaptor { +namespace +{ + +const float DEFAULT_STEREO_BASE( 65.0f ); + +} // unnamed namespace + ApplicationPtr Application::gPreInitializedApplication( NULL ); ApplicationPtr Application::New( @@ -68,9 +81,7 @@ void Application::PreInitialize( int* argc, char** argv[] ) if( !gPreInitializedApplication ) { gPreInitializedApplication = new Application ( argc, argv, "", Dali::Application::OPAQUE, PositionSize(), Framework::NORMAL ); - gPreInitializedApplication->CreateWindow(); // Only create window - gPreInitializedApplication->mLaunchpadState = Launchpad::PRE_INITIALIZED; } } @@ -88,27 +99,30 @@ Application::Application( int* argc, char** argv[], const std::string& styleshee mRegionChangedSignal(), mBatteryLowSignal(), mMemoryLowSignal(), - mEventLoop( NULL ), - mFramework( NULL ), + mEventLoop( nullptr ), + mFramework( nullptr ), mContextLossConfiguration( Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS ), - mCommandLineOptions( NULL ), - mSingletonService( SingletonService::New() ), - mAdaptor( NULL ), - mWindow(), - mWindowMode( windowMode ), - mName(), + mCommandLineOptions( nullptr ), + mAdaptorBuilder( nullptr ), + mAdaptor( nullptr ), + mMainWindow(), + mMainWindowMode( windowMode ), + mMainWindowName(), + mMainWindowReplaced( false ), mStylesheet( stylesheet ), mEnvironmentOptions(), mWindowPositionSize( positionSize ), mLaunchpadState( Launchpad::NONE ), - mSlotDelegate( this ) + mSlotDelegate( this ), + mViewMode( MONO ), + mStereoBase( DEFAULT_STEREO_BASE ) { // Get mName from environment options - mName = mEnvironmentOptions.GetWindowName(); - if( mName.empty() && argc && ( *argc > 0 ) ) + mMainWindowName = mEnvironmentOptions.GetWindowName(); + if( mMainWindowName.empty() && argc && ( *argc > 0 ) ) { // Set mName from command-line args if environment option not set - mName = (*argv)[0]; + mMainWindowName = (*argv)[0]; } mCommandLineOptions = new CommandLineOptions(argc, argv); @@ -118,10 +132,16 @@ Application::Application( int* argc, char** argv[], const std::string& styleshee Application::~Application() { - mSingletonService.UnregisterAll(); + SingletonService service = SingletonService::Get(); + // Note this can be false i.e. if Application has never created a Core instance + if( service ) + { + service.UnregisterAll(); + } - mWindow.Reset(); + mMainWindow.Reset(); delete mAdaptor; + delete mAdaptorBuilder; delete mCommandLineOptions; delete mFramework; } @@ -145,27 +165,32 @@ void Application::CreateWindow() } const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName(); - mWindow = Dali::Window::New( mWindowPositionSize, mName, windowClassName, mWindowMode == Dali::Application::TRANSPARENT ); - int indicatorVisibleMode = mEnvironmentOptions.GetIndicatorVisibleMode(); - if( indicatorVisibleMode >= Dali::Window::INVISIBLE && indicatorVisibleMode <= Dali::Window::AUTO ) - { - GetImplementation( mWindow ).SetIndicatorVisibleMode( static_cast< Dali::Window::IndicatorVisibleMode >( indicatorVisibleMode ) ); - } + Internal::Adaptor::Window* window = Internal::Adaptor::Window::New(mWindowPositionSize, mMainWindowName, windowClassName, mMainWindowMode == Dali::Application::TRANSPARENT); + mMainWindow = Dali::Window( window ); // Quit the application when the window is closed - GetImplementation( mWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit ); + GetImplementation( mMainWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit ); } void Application::CreateAdaptor() { - DALI_ASSERT_ALWAYS( mWindow && "Window required to create adaptor" ); + DALI_ASSERT_ALWAYS( mMainWindow && "Window required to create adaptor" ); + + auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory(); + + Integration::SceneHolder sceneHolder = Integration::SceneHolder( &Dali::GetImplementation( mMainWindow ) ); - mAdaptor = Dali::Internal::Adaptor::Adaptor::New( mWindow, mContextLossConfiguration, &mEnvironmentOptions ); + mAdaptor = Adaptor::New( graphicsFactory, sceneHolder, mContextLossConfiguration, &mEnvironmentOptions ); mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize ); - Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( mUseRemoteSurface ); + Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( mUseRemoteSurface ); +} + +void Application::CreateAdaptorBuilder() +{ + mAdaptorBuilder = new AdaptorBuilder(); } void Application::MainLoop(Dali::Configuration::ContextLoss configuration) @@ -179,14 +204,14 @@ void Application::MainLoop(Dali::Configuration::ContextLoss configuration) void Application::Lower() { // Lower the application without quitting it. - mWindow.Lower(); + mMainWindow.Lower(); } void Application::Quit() { // Actually quit the application. // Force a call to Quit even if adaptor is not running. - Internal::Adaptor::Adaptor::GetImplementation(*mAdaptor).AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ), true ); + Internal::Adaptor::Adaptor::GetImplementation(*mAdaptor).AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ), false, true ); } void Application::QuitFromMainLoop() @@ -197,8 +222,11 @@ void Application::QuitFromMainLoop() // This will trigger OnTerminate(), below, after the main loop has completed. } -void Application::DoInit() +void Application::OnInit() { + mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) ); + + CreateAdaptorBuilder(); // If an application was pre-initialized, a window was made in advance if( mLaunchpadState == Launchpad::NONE ) { @@ -210,65 +238,10 @@ void Application::DoInit() // Run the adaptor mAdaptor->Start(); - // Check if user requires no vsyncing and set Adaptor - if (mCommandLineOptions->noVSyncOnRender) - { - mAdaptor->SetUseHardwareVSync(false); - } - - Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase ); - if( mCommandLineOptions->viewMode != 0 ) - { - ViewMode viewMode = MONO; - if( mCommandLineOptions->viewMode <= STEREO_INTERLACED ) - { - viewMode = static_cast( mCommandLineOptions->viewMode ); - } - Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode ); - } - if( ! mStylesheet.empty() ) { Dali::StyleMonitor::Get().SetTheme( mStylesheet ); } -} - -void Application::DoStart() -{ - 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(); @@ -284,18 +257,24 @@ void Application::OnInit() Dali::Application application(this); mInitSignal.Emit( application ); - DoStart(); + mAdaptor->NotifySceneCreated(); } void Application::OnTerminate() { - // we've been told to quit by AppCore, ecore_x_destroy has been called, need to quit synchronously + // 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 Dali::Application application(this); mTerminateSignal.Emit( application ); - DoTerminate(); + if( mAdaptor ) + { + // Ensure that the render-thread is not using the surface(window) after we delete it + mAdaptor->Stop(); + } + + mMainWindow.Reset(); // This only resets (clears) the default Window } void Application::OnPause() @@ -340,7 +319,7 @@ void Application::OnAppControl(void *data) void Application::OnLanguageChanged() { - DoLanguageChange(); + mAdaptor->NotifyLanguageChanged(); Dali::Application application(this); mLanguageChangedSignal.Emit( application ); } @@ -366,15 +345,34 @@ void Application::OnMemoryLow( Dali::DeviceStatus::Memory::Status status ) mLowMemorySignal.Emit( status ); } + +void Application::OnSurfaceCreated( Any newSurface ) +{ + void* newWindow = AnyCast< void* >( newSurface ); + void* oldWindow = AnyCast< void* >( mMainWindow.GetNativeHandle() ); + if( oldWindow != newWindow ) + { + auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory(); + std::unique_ptr< WindowRenderSurface > newSurfacePtr + = renderSurfaceFactory->CreateWindowRenderSurface( PositionSize(), newSurface, true ); + + mAdaptor->ReplaceSurface( mMainWindow, *newSurfacePtr.release() ); + } +} + +void Application::OnSurfaceDestroyed( Any surface ) +{ +} + void Application::OnResize(Dali::Adaptor& adaptor) { Dali::Application application(this); mResizeSignal.Emit( application ); } -bool Application::AddIdle( CallbackBase* callback ) +bool Application::AddIdle( CallbackBase* callback, bool hasReturnValue ) { - return mAdaptor->AddIdle( callback ); + return mAdaptor->AddIdle( callback, hasReturnValue ); } std::string Application::GetRegion() const @@ -394,50 +392,47 @@ Dali::Adaptor& Application::GetAdaptor() Dali::Window Application::GetWindow() { - return mWindow; + // Changed to return a different window handle after ReplaceWindow is called + // just for backward compatibility to make the test case pass + if ( mMainWindowReplaced ) + { + Internal::Adaptor::Window* window = Internal::Adaptor::Window::New(PositionSize(), "ReplacedWindow", "", false); + return Dali::Window( window ); + } + else + { + return mMainWindow; + } } // Stereoscopy void Application::SetViewMode( ViewMode viewMode ) { - Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode ); + mViewMode = viewMode; } ViewMode Application::GetViewMode() const { - return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode(); + return mViewMode; } void Application::SetStereoBase( float stereoBase ) { - Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase ); + mStereoBase = stereoBase; } float Application::GetStereoBase() const { - return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase(); + return mStereoBase; } - void Application::ReplaceWindow( const PositionSize& positionSize, const std::string& name ) { - Dali::Window newWindow = Dali::Window::New( positionSize, name, mWindowMode == Dali::Application::TRANSPARENT ); - Window& windowImpl = GetImplementation(newWindow); - windowImpl.SetAdaptor(*mAdaptor); + // This API is kept just for backward compatibility to make the test case pass. - int indicatorVisibleMode = mEnvironmentOptions.GetIndicatorVisibleMode(); - if( indicatorVisibleMode >= Dali::Window::INVISIBLE && indicatorVisibleMode <= Dali::Window::AUTO ) - { - GetImplementation( newWindow ).SetIndicatorVisibleMode( static_cast< Dali::Window::IndicatorVisibleMode >( indicatorVisibleMode ) ); - } - - Dali::RenderSurface* renderSurface = windowImpl.GetSurface(); - - Any nativeWindow = newWindow.GetNativeHandle(); - Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(nativeWindow, *renderSurface); - mWindow = newWindow; - mWindowPositionSize = positionSize; + mMainWindowReplaced = true; + OnResize( *mAdaptor ); } std::string Application::GetResourcePath() @@ -445,11 +440,24 @@ std::string Application::GetResourcePath() return Internal::Adaptor::Framework::GetResourcePath(); } +std::string Application::GetDataPath() +{ + return Internal::Adaptor::Framework::GetDataPath(); +} + void Application::SetStyleSheet( const std::string& stylesheet ) { mStylesheet = stylesheet; } +void Application::SetCommandLineOptions( int* argc, char **argv[] ) +{ + delete mCommandLineOptions; + + mCommandLineOptions = new CommandLineOptions( argc, argv ); + + mFramework->SetCommandLineOptions( argc, argv ); +} ApplicationPtr Application::GetPreInitializedApplication() {