/*
- * 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.
#include <dali/internal/adaptor/common/application-impl.h>
// EXTERNAL INCLUDES
+#include <dali/public-api/object/object-registry.h>
#include <dali/integration-api/debug.h>
+#include <dali/devel-api/common/singleton-service.h>
// INTERNAL INCLUDES
#include <dali/devel-api/adaptor-framework/style-monitor.h>
-#include <dali/internal/system/common/command-line-options.h>
+#include <dali/devel-api/text-abstraction/font-client.h>
+#include <dali/devel-api/adaptor-framework/accessibility-impl.h>
#include <dali/internal/adaptor/common/adaptor-impl.h>
+#include <dali/internal/system/common/command-line-options.h>
#include <dali/internal/adaptor/common/framework.h>
-#include <dali/internal/system/common/singleton-service-impl.h>
#include <dali/internal/adaptor/common/lifecycle-controller-impl.h>
+#include <dali/internal/window-system/common/window-impl.h>
#include <dali/internal/window-system/common/window-render-surface.h>
+#include <dali/internal/window-system/common/render-surface-factory.h>
+
+// To disable a macro with the same name from one of OpenGL headers
+#undef Status
namespace Dali
{
{
if( !gPreInitializedApplication )
{
- gPreInitializedApplication = new Application ( argc, argv, "", Dali::Application::OPAQUE, PositionSize(), Framework::NORMAL );
+ Dali::TextAbstraction::FontClientPreInitialize();
+ gPreInitializedApplication = new Application ( argc, argv, "", Dali::Application::OPAQUE, PositionSize(), Framework::NORMAL );
gPreInitializedApplication->CreateWindow(); // Only create window
-
gPreInitializedApplication->mLaunchpadState = Launchpad::PRE_INITIALIZED;
}
}
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(),
+ mEventLoop( nullptr ),
+ mFramework( nullptr ),
+ mCommandLineOptions( nullptr ),
+ mAdaptorBuilder( nullptr ),
+ mAdaptor( nullptr ),
+ mMainWindow(),
+ mMainWindowMode( windowMode ),
+ mMainWindowName(),
mStylesheet( stylesheet ),
mEnvironmentOptions(),
mWindowPositionSize( positionSize ),
mSlotDelegate( this )
{
// 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);
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;
}
}
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" );
- mAdaptor = Dali::Internal::Adaptor::Adaptor::New( mWindow, mContextLossConfiguration, &mEnvironmentOptions );
+ auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
- mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
+ Integration::SceneHolder sceneHolder = Integration::SceneHolder( &Dali::GetImplementation( mMainWindow ) );
- Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( mUseRemoteSurface );
+ mAdaptor = Adaptor::New( graphicsFactory, sceneHolder, &mEnvironmentOptions );
+
+ Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( mUseRemoteSurface );
}
-void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
+void Application::CreateAdaptorBuilder()
{
- mContextLossConfiguration = configuration;
+ mAdaptorBuilder = new AdaptorBuilder();
+}
+void Application::MainLoop()
+{
// Run the application
mFramework->Run();
}
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()
{
+ Accessibility::Bridge::GetCurrentBridge()->Terminate();
+
mAdaptor->Stop();
mFramework->Quit();
// 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 )
{
// 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<ViewMode>( mCommandLineOptions->viewMode );
- }
- Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
- }
+ Accessibility::Accessible::SetObjectRegistry(mAdaptor->GetObjectRegistry());
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();
PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
- ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );
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()
void Application::OnLanguageChanged()
{
- DoLanguageChange();
+ mAdaptor->NotifyLanguageChanged();
Dali::Application application(this);
mLanguageChangedSignal.Emit( application );
}
void Application::OnBatteryLow( Dali::DeviceStatus::Battery::Status status )
{
Dali::Application application(this);
- mBatteryLowSignal.Emit( application );
-
mLowBatterySignal.Emit( status );
}
void Application::OnMemoryLow( Dali::DeviceStatus::Memory::Status status )
{
Dali::Application application(this);
- mMemoryLowSignal.Emit( application );
-
mLowMemorySignal.Emit( status );
}
-void Application::OnResize(Dali::Adaptor& adaptor)
+
+void Application::OnSurfaceCreated( Any newSurface )
{
- Dali::Application application(this);
- mResizeSignal.Emit( application );
+ 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() );
+ }
}
-bool Application::AddIdle( CallbackBase* callback )
+void Application::OnSurfaceDestroyed( Any surface )
{
- return mAdaptor->AddIdle( callback );
+}
+
+bool Application::AddIdle( CallbackBase* callback, bool hasReturnValue )
+{
+ return mAdaptor->AddIdle( callback, hasReturnValue );
}
std::string Application::GetRegion() const
return mFramework->GetLanguage();
}
-Dali::Adaptor& Application::GetAdaptor()
+Dali::ObjectRegistry Application::GetObjectRegistry() const
{
- return *mAdaptor;
+ Dali::ObjectRegistry objectRegistry;
+ if( mAdaptor )
+ {
+ objectRegistry = mAdaptor->GetObjectRegistry();
+ }
+ return objectRegistry;
}
-Dali::Window Application::GetWindow()
+Dali::Adaptor& Application::GetAdaptor()
{
- return mWindow;
+ return *mAdaptor;
}
-// Stereoscopy
-
-void Application::SetViewMode( ViewMode viewMode )
+Dali::Window Application::GetWindow()
{
- Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
+ return mMainWindow;
}
-ViewMode Application::GetViewMode() const
+std::string Application::GetResourcePath()
{
- return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetViewMode();
+ return Internal::Adaptor::Framework::GetResourcePath();
}
-void Application::SetStereoBase( float stereoBase )
+std::string Application::GetDataPath()
{
- Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( stereoBase );
+ return Internal::Adaptor::Framework::GetDataPath();
}
-float Application::GetStereoBase() const
+void Application::SetStyleSheet( const std::string& stylesheet )
{
- return Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).GetStereoBase();
+ mStylesheet = stylesheet;
}
-
-void Application::ReplaceWindow( const PositionSize& positionSize, const std::string& name )
+void Application::SetCommandLineOptions( int* argc, char **argv[] )
{
- Dali::Window newWindow = Dali::Window::New( positionSize, name, mWindowMode == Dali::Application::TRANSPARENT );
- Window& windowImpl = GetImplementation(newWindow);
- windowImpl.SetAdaptor(*mAdaptor);
-
- 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;
-}
+ delete mCommandLineOptions;
-std::string Application::GetResourcePath()
-{
- return Internal::Adaptor::Framework::GetResourcePath();
-}
+ mCommandLineOptions = new CommandLineOptions( argc, argv );
-void Application::SetStyleSheet( const std::string& stylesheet )
-{
- mStylesheet = stylesheet;
+ mFramework->SetCommandLineOptions( argc, argv );
}
-
ApplicationPtr Application::GetPreInitializedApplication()
{
return gPreInitializedApplication;