/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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/devel-api/common/singleton-service.h>
#include <dali/integration-api/debug.h>
+#include <dali/public-api/object/object-registry.h>
// INTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/accessibility-impl.h>
#include <dali/devel-api/adaptor-framework/style-monitor.h>
#include <dali/devel-api/text-abstraction/font-client.h>
-#include <dali/internal/system/common/command-line-options.h>
+#include <dali/internal/adaptor/common/adaptor-impl.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/system/common/command-line-options.h>
+#include <dali/internal/window-system/common/render-surface-factory.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>
+#include <dali/internal/window-system/common/window-system.h>
// To disable a macro with the same name from one of OpenGL headers
#undef Status
namespace Dali
{
-
namespace TizenPlatform
{
class TizenPlatformAbstraction;
namespace Internal
{
-
namespace Adaptor
{
-
-namespace
-{
-
-const float DEFAULT_STEREO_BASE( 65.0f );
-
-} // unnamed namespace
-
-ApplicationPtr Application::gPreInitializedApplication( NULL );
+ApplicationPtr Application::gPreInitializedApplication(NULL);
ApplicationPtr Application::New(
- int* argc,
- char **argv[],
- const std::string& stylesheet,
+ int* argc,
+ char** argv[],
+ const std::string& stylesheet,
Dali::Application::WINDOW_MODE windowMode,
- const PositionSize& positionSize,
- Framework::Type applicationType)
+ const PositionSize& positionSize,
+ Framework::Type applicationType)
{
- ApplicationPtr application ( new Application (argc, argv, stylesheet, windowMode, positionSize, applicationType ) );
+ ApplicationPtr application(new Application(argc, argv, stylesheet, windowMode, positionSize, applicationType));
return application;
}
-void Application::PreInitialize( int* argc, char** argv[] )
+void Application::PreInitialize(int* argc, char** argv[])
{
- if( !gPreInitializedApplication )
+ if(!gPreInitializedApplication)
{
- gPreInitializedApplication = new Application ( argc, argv, "", Dali::Application::OPAQUE, PositionSize(), Framework::NORMAL );
-
- gPreInitializedApplication->CreateWindow(); // Only create window
+ Dali::TextAbstraction::FontClientPreInitialize();
+ gPreInitializedApplication = new Application(argc, argv, "", Dali::Application::OPAQUE, PositionSize(), Framework::NORMAL);
+ gPreInitializedApplication->CreateWindow(); // Only create window
gPreInitializedApplication->mLaunchpadState = Launchpad::PRE_INITIALIZED;
-
- //Make DefaultFontDescription cached
- Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
- Dali::TextAbstraction::FontDescription defaultFontDescription;
- fontClient.GetDefaultPlatformFontDescription( defaultFontDescription );
}
}
-Application::Application( int* argc, char** argv[], const std::string& stylesheet,
- Dali::Application::WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType )
+Application::Application(int* argc, char** argv[], const std::string& stylesheet, Dali::Application::WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType)
: mInitSignal(),
mTerminateSignal(),
mPauseSignal(),
mResumeSignal(),
mResetSignal(),
- mResizeSignal(),
mAppControlSignal(),
mLanguageChangedSignal(),
mRegionChangedSignal(),
- mBatteryLowSignal(),
- mMemoryLowSignal(),
- mEventLoop( nullptr ),
- mFramework( nullptr ),
- mContextLossConfiguration( Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS ),
- mCommandLineOptions( nullptr ),
- mSingletonService( SingletonService::New() ),
- mAdaptorBuilder( nullptr ),
- mAdaptor( nullptr ),
+ mEventLoop(nullptr),
+ mFramework(nullptr),
+ mCommandLineOptions(nullptr),
+ mAdaptorBuilder(nullptr),
+ mAdaptor(nullptr),
mMainWindow(),
- mMainWindowMode( windowMode ),
+ mMainWindowMode(windowMode),
mMainWindowName(),
- mMainWindowReplaced( false ),
- mStylesheet( stylesheet ),
+ mStylesheet(stylesheet),
mEnvironmentOptions(),
- mWindowPositionSize( positionSize ),
- mLaunchpadState( Launchpad::NONE ),
- mSlotDelegate( this ),
- mViewMode( MONO ),
- mStereoBase( DEFAULT_STEREO_BASE )
+ mWindowPositionSize(positionSize),
+ mLaunchpadState(Launchpad::NONE),
+ mSlotDelegate(this)
{
// Get mName from environment options
mMainWindowName = mEnvironmentOptions.GetWindowName();
- if( mMainWindowName.empty() && argc && ( *argc > 0 ) )
+ if(mMainWindowName.empty() && argc && (*argc > 0))
{
// Set mName from command-line args if environment option not set
mMainWindowName = (*argv)[0];
}
mCommandLineOptions = new CommandLineOptions(argc, argv);
- mFramework = new Framework( *this, argc, argv, applicationType );
- mUseRemoteSurface = (applicationType == Framework::WATCH);
+ mFramework = new Framework(*this, argc, argv, applicationType);
+ mUseRemoteSurface = (applicationType == Framework::WATCH);
}
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();
+ }
mMainWindow.Reset();
delete mAdaptor;
delete mFramework;
}
+void Application::StoreWindowPositionSize(PositionSize positionSize)
+{
+ mWindowPositionSize = positionSize;
+}
+
+void Application::ChangePreInitializedWindowSize()
+{
+ int screenWidth, screenHeight;
+ Dali::Internal::Adaptor::WindowSystem::GetScreenSize(screenWidth, screenHeight);
+
+ if(mWindowPositionSize != PositionSize(0, 0, 0, 0))
+ {
+ Dali::DevelWindow::SetPositionSize(mMainWindow, mWindowPositionSize);
+ }
+ else if(mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0)
+ {
+ // Command line options override environment options and full screen
+ mWindowPositionSize.width = mCommandLineOptions->stageWidth;
+ mWindowPositionSize.height = mCommandLineOptions->stageHeight;
+ mMainWindow.SetSize(Dali::Window::WindowSize(mWindowPositionSize.width, mWindowPositionSize.height));
+ }
+ else if(mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight())
+ {
+ // Environment options override full screen functionality if command line arguments not provided
+ mWindowPositionSize.width = mEnvironmentOptions.GetWindowWidth();
+ mWindowPositionSize.height = mEnvironmentOptions.GetWindowHeight();
+ mMainWindow.SetSize(Dali::Window::WindowSize(mWindowPositionSize.width, mWindowPositionSize.height));
+ }
+ else if(screenWidth != mWindowPositionSize.width || screenHeight != mWindowPositionSize.height)
+ {
+ //Some apps can receive screen size differently after launching by specifying size in manifest.
+ mWindowPositionSize.width = screenWidth;
+ mWindowPositionSize.height = screenHeight;
+ mMainWindow.SetSize(Dali::Window::WindowSize(mWindowPositionSize.width, mWindowPositionSize.height));
+ }
+}
+
void Application::CreateWindow()
{
- if( mWindowPositionSize.width == 0 && mWindowPositionSize.height == 0 )
+ if(mWindowPositionSize.width == 0 && mWindowPositionSize.height == 0)
{
- if( mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0 )
+ if(mCommandLineOptions->stageWidth > 0 && mCommandLineOptions->stageHeight > 0)
{
// Command line options override environment options and full screen
- mWindowPositionSize.width = mCommandLineOptions->stageWidth;
+ mWindowPositionSize.width = mCommandLineOptions->stageWidth;
mWindowPositionSize.height = mCommandLineOptions->stageHeight;
}
- else if( mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight() )
+ else if(mEnvironmentOptions.GetWindowWidth() && mEnvironmentOptions.GetWindowHeight())
{
// Environment options override full screen functionality if command line arguments not provided
- mWindowPositionSize.width = mEnvironmentOptions.GetWindowWidth();
+ mWindowPositionSize.width = mEnvironmentOptions.GetWindowWidth();
mWindowPositionSize.height = mEnvironmentOptions.GetWindowHeight();
}
}
const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName();
- Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( mWindowPositionSize, mMainWindowName, windowClassName, mMainWindowMode == Dali::Application::TRANSPARENT );
- mMainWindow = Dali::Window( window );
+ 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( mMainWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit );
+ GetImplementation(mMainWindow).DeleteRequestSignal().Connect(mSlotDelegate, &Application::Quit);
}
void Application::CreateAdaptor()
{
- DALI_ASSERT_ALWAYS( mMainWindow && "Window required to create adaptor" );
+ DALI_ASSERT_ALWAYS(mMainWindow && "Window required to create adaptor");
auto graphicsFactory = mAdaptorBuilder->GetGraphicsFactory();
- mAdaptor = Dali::Internal::Adaptor::Adaptor::New( graphicsFactory, mMainWindow, mContextLossConfiguration, &mEnvironmentOptions );
+ Integration::SceneHolder sceneHolder = Integration::SceneHolder(&Dali::GetImplementation(mMainWindow));
- mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
+ mAdaptor = Adaptor::New(graphicsFactory, sceneHolder, &mEnvironmentOptions);
- Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( mUseRemoteSurface );
+ Adaptor::GetImplementation(*mAdaptor).SetUseRemoteSurface(mUseRemoteSurface);
}
void Application::CreateAdaptorBuilder()
{
- mAdaptorBuilder = new AdaptorBuilder();
+ mAdaptorBuilder = new AdaptorBuilder(mEnvironmentOptions);
}
-void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
+void Application::MainLoop()
{
- mContextLossConfiguration = configuration;
-
// Run the application
mFramework->Run();
}
{
// 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 ), false, true );
+ Internal::Adaptor::Adaptor::GetImplementation(*mAdaptor).AddIdle(MakeCallback(this, &Application::QuitFromMainLoop), false, true);
}
void Application::QuitFromMainLoop()
{
+ Accessibility::Bridge::GetCurrentBridge()->Terminate();
+
mAdaptor->Stop();
mFramework->Quit();
void Application::OnInit()
{
- mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );
+ mFramework->AddAbortCallback(MakeCallback(this, &Application::QuitFromMainLoop));
CreateAdaptorBuilder();
-
// If an application was pre-initialized, a window was made in advance
- if( mLaunchpadState == Launchpad::NONE )
+ if(mLaunchpadState == Launchpad::NONE)
{
CreateWindow();
}
CreateAdaptor();
- // Run the adaptor
- mAdaptor->Start();
-
- // Check if user requires no vsyncing and set Adaptor
- if (mCommandLineOptions->noVSyncOnRender)
+ if(mLaunchpadState == Launchpad::PRE_INITIALIZED)
{
- mAdaptor->SetUseHardwareVSync(false);
+ ChangePreInitializedWindowSize();
}
- if( ! mStylesheet.empty() )
+ // Run the adaptor
+ mAdaptor->Start();
+ Accessibility::Accessible::SetObjectRegistry(mAdaptor->GetObjectRegistry());
+
+ if(!mStylesheet.empty())
{
- Dali::StyleMonitor::Get().SetTheme( mStylesheet );
+ Dali::StyleMonitor::Get().SetTheme(mStylesheet);
}
// Wire up the LifecycleController
Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
- InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
- TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
- 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 );
+ InitSignal().Connect(&GetImplementation(lifecycleController), &LifecycleController::OnInit);
+ TerminateSignal().Connect(&GetImplementation(lifecycleController), &LifecycleController::OnTerminate);
+ PauseSignal().Connect(&GetImplementation(lifecycleController), &LifecycleController::OnPause);
+ ResumeSignal().Connect(&GetImplementation(lifecycleController), &LifecycleController::OnResume);
+ ResetSignal().Connect(&GetImplementation(lifecycleController), &LifecycleController::OnReset);
+ LanguageChangedSignal().Connect(&GetImplementation(lifecycleController), &LifecycleController::OnLanguageChanged);
Dali::Application application(this);
- mInitSignal.Emit( application );
+ mInitSignal.Emit(application);
mAdaptor->NotifySceneCreated();
}
// delete the window as ecore_x has been destroyed by AppCore
Dali::Application application(this);
- mTerminateSignal.Emit( application );
+ mTerminateSignal.Emit(application);
- if( mAdaptor )
+ if(mAdaptor)
{
// Ensure that the render-thread is not using the surface(window) after we delete it
mAdaptor->Stop();
// DALi just delivers the framework Pause event to the application, but not actually pause DALi core.
// Pausing DALi core only occurs on the Window Hidden framework event
Dali::Application application(this);
- mPauseSignal.Emit( application );
+ mPauseSignal.Emit(application);
}
void Application::OnResume()
// 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 );
+ mResumeSignal.Emit(application);
// DALi just delivers the framework Resume event to the application.
// Resuming DALi core only occurs on the Window Show framework event
// Trigger processing of events queued up while paused
- CoreEventInterface& coreEventInterface = Internal::Adaptor::Adaptor::GetImplementation( GetAdaptor() );
+ CoreEventInterface& coreEventInterface = Internal::Adaptor::Adaptor::GetImplementation(GetAdaptor());
coreEventInterface.ProcessCoreEvents();
}
* because Application class already handled initialization in OnInit(), OnReset do nothing.
*/
Dali::Application application(this);
- mResetSignal.Emit( application );
+ mResetSignal.Emit(application);
}
-void Application::OnAppControl(void *data)
+void Application::OnAppControl(void* data)
{
Dali::Application application(this);
- mAppControlSignal.Emit( application , data );
+ mAppControlSignal.Emit(application, data);
}
void Application::OnLanguageChanged()
{
mAdaptor->NotifyLanguageChanged();
Dali::Application application(this);
- mLanguageChangedSignal.Emit( application );
+ mLanguageChangedSignal.Emit(application);
}
void Application::OnRegionChanged()
{
Dali::Application application(this);
- mRegionChangedSignal.Emit( application );
+ mRegionChangedSignal.Emit(application);
}
-void Application::OnBatteryLow( Dali::DeviceStatus::Battery::Status status )
+void Application::OnBatteryLow(Dali::DeviceStatus::Battery::Status status)
{
Dali::Application application(this);
- mBatteryLowSignal.Emit( application );
-
- mLowBatterySignal.Emit( status );
+ mLowBatterySignal.Emit(status);
}
-void Application::OnMemoryLow( Dali::DeviceStatus::Memory::Status status )
+void Application::OnMemoryLow(Dali::DeviceStatus::Memory::Status status)
{
Dali::Application application(this);
- mMemoryLowSignal.Emit( application );
+ 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);
- mLowMemorySignal.Emit( status );
+ mAdaptor->ReplaceSurface(mMainWindow, *newSurfacePtr.release());
+ }
}
-void Application::OnResize(Dali::Adaptor& adaptor)
+void Application::OnSurfaceDestroyed(Any surface)
{
- Dali::Application application(this);
- mResizeSignal.Emit( application );
}
-bool Application::AddIdle( CallbackBase* callback, bool hasReturnValue )
+bool Application::AddIdle(CallbackBase* callback, bool hasReturnValue)
{
- return mAdaptor->AddIdle( callback, hasReturnValue );
+ return mAdaptor->AddIdle(callback, hasReturnValue);
}
std::string Application::GetRegion() const
return mFramework->GetLanguage();
}
-Dali::Adaptor& Application::GetAdaptor()
-{
- return *mAdaptor;
-}
-
-Dali::Window Application::GetWindow()
+Dali::ObjectRegistry Application::GetObjectRegistry() const
{
- // 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
+ Dali::ObjectRegistry objectRegistry;
+ if(mAdaptor)
{
- return mMainWindow;
+ objectRegistry = mAdaptor->GetObjectRegistry();
}
+ return objectRegistry;
}
-// Stereoscopy
-
-void Application::SetViewMode( ViewMode viewMode )
-{
- mViewMode = viewMode;
-}
-
-ViewMode Application::GetViewMode() const
-{
- return mViewMode;
-}
-
-void Application::SetStereoBase( float stereoBase )
-{
- mStereoBase = stereoBase;
-}
-
-float Application::GetStereoBase() const
+Dali::Adaptor& Application::GetAdaptor()
{
- return mStereoBase;
+ return *mAdaptor;
}
-void Application::ReplaceWindow( const PositionSize& positionSize, const std::string& name )
+Dali::Window Application::GetWindow()
{
- // This API is kept just for backward compatibility to make the test case pass.
-
- mMainWindowReplaced = true;
- OnResize( *mAdaptor );
+ return mMainWindow;
}
std::string Application::GetResourcePath()
return Internal::Adaptor::Framework::GetDataPath();
}
-void Application::SetStyleSheet( const std::string& stylesheet )
+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()
{
return gPreInitializedApplication;
}
+Graphics::Controller& Application::GetController()
+{
+ auto& adaptor = Internal::Adaptor::Adaptor::GetImplementation(*mAdaptor);
+ return adaptor.GetGraphicsInterface().GetController();
+}
+
} // namespace Adaptor
} // namespace Internal