Revert "[Tizen] Revert "Support multiple window rendering""
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / application-impl.cpp
index da1f3b6..8e90b04 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
 // INTERNAL INCLUDES
 #include <dali/devel-api/adaptor-framework/style-monitor.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/window-system/common/window-impl.h>
+#include <dali/internal/window-system/common/window-render-surface.h>
+
+#undef Status
 
 namespace Dali
 {
@@ -48,6 +51,13 @@ namespace Internal
 namespace Adaptor
 {
 
+namespace
+{
+
+const float DEFAULT_STEREO_BASE( 65.0f );
+
+} // unnamed namespace
+
 ApplicationPtr Application::gPreInitializedApplication( NULL );
 
 ApplicationPtr Application::New(
@@ -87,27 +97,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 ),
+  mCommandLineOptions( nullptr ),
   mSingletonService( SingletonService::New() ),
-  mAdaptor( NULL ),
-  mWindow(),
-  mWindowMode( windowMode ),
-  mName(),
+  mAdaptorBuilder( nullptr ),
+  mAdaptor( nullptr ),
+  mMainWindow(),
+  mMainWindowMode( windowMode ),
+  mMainWindowName(),
   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);
@@ -119,8 +132,9 @@ Application::~Application()
 {
   mSingletonService.UnregisterAll();
 
-  mWindow.Reset();
+  mMainWindow.Reset();
   delete mAdaptor;
+  delete mAdaptorBuilder;
   delete mCommandLineOptions;
   delete mFramework;
 }
@@ -144,29 +158,36 @@ void Application::CreateWindow()
   }
 
   const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName();
-  mWindow = Dali::Window::New( mWindowPositionSize, mName, windowClassName, mWindowMode == Dali::Application::TRANSPARENT );
+  mMainWindow = Dali::Window::New( mWindowPositionSize, mMainWindowName, windowClassName, mMainWindowMode == 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 ) );
+    GetImplementation( mMainWindow ).SetIndicatorVisibleMode( static_cast< Dali::Window::IndicatorVisibleMode >( indicatorVisibleMode ) );
   }
 
   // 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 = Dali::Internal::Adaptor::Adaptor::New( graphicsFactory, mMainWindow, mContextLossConfiguration, &mEnvironmentOptions );
 
   mAdaptor->ResizedSignal().Connect( mSlotDelegate, &Application::OnResize );
 
   Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( mUseRemoteSurface );
 }
 
+void Application::CreateAdaptorBuilder()
+{
+  mAdaptorBuilder = new AdaptorBuilder();
+}
+
 void Application::MainLoop(Dali::Configuration::ContextLoss configuration)
 {
   mContextLossConfiguration = configuration;
@@ -178,14 +199,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()
@@ -198,6 +219,8 @@ void Application::QuitFromMainLoop()
 
 void Application::DoInit()
 {
+  CreateAdaptorBuilder();
+
   // If an application was pre-initialized, a window was made in advance
   if( mLaunchpadState == Launchpad::NONE )
   {
@@ -215,17 +238,6 @@ void Application::DoInit()
     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 );
-  }
-
   if( ! mStylesheet.empty() )
   {
     Dali::StyleMonitor::Get().SetTheme( mStylesheet );
@@ -245,7 +257,7 @@ void Application::DoTerminate()
     mAdaptor->Stop();
   }
 
-  mWindow.Reset();
+  mMainWindow.Reset(); // This only resets (clears) the default Window
 }
 
 void Application::DoPause()
@@ -288,7 +300,7 @@ void Application::OnInit()
 
 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);
@@ -371,9 +383,9 @@ void Application::OnResize(Dali::Adaptor& adaptor)
   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
@@ -393,35 +405,34 @@ Dali::Adaptor& Application::GetAdaptor()
 
 Dali::Window Application::GetWindow()
 {
-  return mWindow;
+  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 );
+  Dali::Window newWindow = Dali::Window::New( positionSize, name, mMainWindowMode == Dali::Application::TRANSPARENT );
   Window& windowImpl = GetImplementation(newWindow);
   windowImpl.SetAdaptor(*mAdaptor);
 
@@ -431,11 +442,11 @@ void Application::ReplaceWindow( const PositionSize& positionSize, const std::st
     GetImplementation( newWindow ).SetIndicatorVisibleMode( static_cast< Dali::Window::IndicatorVisibleMode >( indicatorVisibleMode ) );
   }
 
-  Dali::RenderSurface* renderSurface = windowImpl.GetSurface();
+  Internal::Adaptor::WindowRenderSurface* renderSurface = windowImpl.GetSurface();
 
   Any nativeWindow = newWindow.GetNativeHandle();
   Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).ReplaceSurface(nativeWindow, *renderSurface);
-  mWindow = newWindow;
+  mMainWindow = newWindow;
   mWindowPositionSize = positionSize;
 }
 
@@ -444,12 +455,16 @@ 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;
 }
 
-
 ApplicationPtr Application::GetPreInitializedApplication()
 {
   return gPreInitializedApplication;