Revert "[Tizen] Revert "Support multiple window rendering""
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / adaptor-impl.cpp
index 149064e..e8683a5 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
@@ -30,6 +30,7 @@
 #include <dali/integration-api/profiling.h>
 #include <dali/integration-api/input-options.h>
 #include <dali/integration-api/events/touch-event-integ.h>
+#include <dali/integration-api/processor-interface.h>
 
 // INTERNAL INCLUDES
 #include <dali/public-api/dali-adaptor-common.h>
@@ -37,8 +38,8 @@
 #include <dali/internal/system/common/performance-interface-factory.h>
 #include <dali/internal/adaptor/common/lifecycle-observer.h>
 
-#include <dali/internal/graphics/gles20/egl-graphics-factory.h>
-#include <dali/internal/graphics/gles20/egl-graphics.h> // Temporary until Core is abstracted
+#include <dali/internal/graphics/gles/egl-graphics-factory.h>
+#include <dali/internal/graphics/gles/egl-graphics.h> // Temporary until Core is abstracted
 
 #include <dali/devel-api/text-abstraction/font-client.h>
 
@@ -47,9 +48,9 @@
 #include <dali/internal/accessibility/common/accessibility-adaptor-impl.h>
 #include <dali/internal/input/common/gesture-manager.h>
 #include <dali/internal/window-system/common/event-handler.h>
-#include <dali/internal/graphics/gles20/gl-proxy-implementation.h>
-#include <dali/internal/graphics/gles20/gl-implementation.h>
-#include <dali/internal/graphics/gles20/egl-sync-implementation.h>
+#include <dali/internal/graphics/gles/gl-proxy-implementation.h>
+#include <dali/internal/graphics/gles/gl-implementation.h>
+#include <dali/internal/graphics/gles/egl-sync-implementation.h>
 #include <dali/internal/graphics/common/egl-image-extensions.h>
 #include <dali/internal/clipboard/common/clipboard-impl.h>
 #include <dali/internal/graphics/common/vsync-monitor.h>
 #include <dali/internal/window-system/common/window-render-surface.h>
 
 #include <dali/internal/system/common/logging.h>
-#include <dali/devel-api/adaptor-framework/image-loading.h>
 
 #include <dali/internal/system/common/locale-utils.h>
 #include <dali/internal/imaging/common/image-loader-plugin-proxy.h>
+#include <dali/internal/imaging/common/image-loader.h>
 
 
 using Dali::TextAbstraction::FontClient;
@@ -82,7 +83,7 @@ thread_local Adaptor* gThreadLocalAdaptor = NULL; // raw thread specific pointer
 } // unnamed namespace
 
 
-Dali::Adaptor* Adaptor::New( Any nativeWindow, RenderSurface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
+Dali::Adaptor* Adaptor::New( Any nativeWindow, Dali::RenderSurfaceInterface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
 {
   Dali::Adaptor* adaptor = new Dali::Adaptor;
   Adaptor* impl = new Adaptor( nativeWindow, *adaptor, surface, environmentOptions );
@@ -107,7 +108,7 @@ Dali::Adaptor* Adaptor::New( Dali::Window window, Dali::Configuration::ContextLo
   return adaptor;
 }
 
-Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Any nativeWindow, RenderSurface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
+Dali::Adaptor* Adaptor::New( GraphicsFactory& graphicsFactory, Any nativeWindow, Dali::RenderSurfaceInterface *surface, Dali::Configuration::ContextLoss configuration, EnvironmentOptions* environmentOptions )
 {
   Dali::Adaptor* adaptor = new Dali::Adaptor; // Public adaptor
   Adaptor* impl = new Adaptor( nativeWindow, *adaptor, surface, environmentOptions ); // Impl adaptor
@@ -160,8 +161,13 @@ void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration:
   mCallbackManager = CallbackManager::New();
 
   WindowPane defaultWindow = mWindowFrame.front();
+
+  DALI_ASSERT_DEBUG( defaultWindow.surface && "Surface not initialized" );
+
   PositionSize size = defaultWindow.surface->GetPositionSize();
 
+  defaultWindow.surface->SetAdaptor(*this);
+
   mGestureManager = new GestureManager(*this, Vector2(size.width, size.height), mCallbackManager, *mEnvironmentOptions);
 
   mGraphics = &( graphicsFactory.Create() );
@@ -169,6 +175,9 @@ void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration:
 
   auto eglGraphics = static_cast<EglGraphics *>( mGraphics ); // This interface is temporary until Core has been updated to match
 
+  // This will only be created once
+  eglGraphics->Create();
+
   GlImplementation& mGLES = eglGraphics->GetGlesInterface();
   EglSyncImplementation& eglSyncImpl = eglGraphics->GetSyncImplementation();
 
@@ -192,14 +201,7 @@ void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration:
 
   mVSyncMonitor = new VSyncMonitor;
 
-  if( defaultWindow.surface )
-  {
-    mDisplayConnection = Dali::DisplayConnection::New( *mGraphics, defaultWindow.surface->GetSurfaceType() );
-  }
-  else
-  {
-    mDisplayConnection = Dali::DisplayConnection::New( *mGraphics );
-  }
+  mDisplayConnection = Dali::DisplayConnection::New( *mGraphics, defaultWindow.surface->GetSurfaceType() );
 
   mThreadController = new ThreadController( *this, *mEnvironmentOptions );
 
@@ -272,10 +274,8 @@ void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration:
   // Set max texture size
   if( mEnvironmentOptions->GetMaxTextureSize() > 0 )
   {
-    Dali::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
+    Dali::TizenPlatform::ImageLoader::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
   }
-
-  SetupSystemInformation();
 }
 
 Adaptor::~Adaptor()
@@ -324,6 +324,10 @@ void Adaptor::Start()
     return;
   }
 
+  mCore->Initialize();
+
+  SetupSystemInformation();
+
   // Start the callback manager
   mCallbackManager->Start();
 
@@ -343,17 +347,12 @@ void Adaptor::Start()
 
   defaultWindow.surface->GetDpi( dpiHor, dpiVer );
 
-  // tell core about the DPI value
-  mCore->SetDpi(dpiHor, dpiVer);
-
   // set the DPI value for font rendering
   FontClient fontClient = FontClient::Get();
   fontClient.SetDpi( dpiHor, dpiVer );
 
   // Tell the core the size of the surface just before we start the render-thread
-  PositionSize size = defaultWindow.surface->GetPositionSize();
-
-  mCore->SurfaceResized( size.width, size.height );
+  mCore->SurfaceResized( defaultWindow.surface );
 
   // Initialize the thread controller
   mThreadController->Initialize();
@@ -392,6 +391,12 @@ void Adaptor::Pause()
 
     // Ensure any messages queued during pause callbacks are processed by doing another update.
     RequestUpdateOnce();
+
+    DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Paused\n" );
+  }
+  else
+  {
+    DALI_LOG_RELEASE_INFO( "Adaptor::Pause: Not paused [%d]\n", mState );
   }
 }
 
@@ -420,6 +425,12 @@ void Adaptor::Resume()
 
     // Do at end to ensure our first update/render after resumption includes the processed messages as well
     mThreadController->Resume();
+
+    DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Resumed\n");
+  }
+  else
+  {
+    DALI_LOG_RELEASE_INFO( "Adaptor::Resume: Not resumed [%d]\n", mState );
   }
 }
 
@@ -460,6 +471,8 @@ void Adaptor::Stop()
     mCallbackManager->Stop();
 
     mState = STOPPED;
+
+    DALI_LOG_RELEASE_INFO( "Adaptor::Stop\n" );
   }
 }
 
@@ -491,22 +504,19 @@ void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
   mEventHandler->FeedKeyEvent( keyEvent );
 }
 
-void Adaptor::ReplaceSurface( Any nativeWindow, RenderSurface& newSurface )
+void Adaptor::ReplaceSurface( Any nativeWindow, Dali::RenderSurfaceInterface& newSurface )
 {
-  PositionSize positionSize = newSurface.GetPositionSize();
-
   // Let the core know the surface size has changed
-  mCore->SurfaceResized( positionSize.width, positionSize.height );
+  mCore->SurfaceResized( &newSurface );
 
   mResizedSignal.Emit( mAdaptor );
 
   WindowPane newDefaultWindow;
   newDefaultWindow.nativeWindow = nativeWindow;
   newDefaultWindow.surface = &newSurface;
+  newDefaultWindow.surface->SetAdaptor(*this);
 
-  // Must delete the old Window first before replacing it with the new one
   WindowPane oldDefaultWindow = mWindowFrame.front();
-  oldDefaultWindow.surface->DestroySurface();
 
   // Update WindowFrame
   std::vector<WindowPane>::iterator iter = mWindowFrame.begin();
@@ -518,9 +528,13 @@ void Adaptor::ReplaceSurface( Any nativeWindow, RenderSurface& newSurface )
 
   // This method blocks until the render thread has completed the replace.
   mThreadController->ReplaceSurface( newDefaultWindow.surface );
+
+  // Must delete the old Window only after the render thread has completed the replace
+  oldDefaultWindow.surface->DestroySurface();
+  oldDefaultWindow.surface = nullptr;
 }
 
-RenderSurface& Adaptor::GetSurface() const
+Dali::RenderSurfaceInterface& Adaptor::GetSurface() const
 {
   WindowPane defaultWindow = mWindowFrame.front();
   return *(defaultWindow.surface);
@@ -568,19 +582,21 @@ void Adaptor::SetPreRenderCallback( CallbackBase* callback )
 
 bool Adaptor::AddWindow( Dali::Window* childWindow, const std::string& childWindowName, const std::string& childWindowClassName, const bool& childWindowMode )
 {
+  Window& windowImpl = Dali::GetImplementation( *childWindow );
+  windowImpl.SetAdaptor( Get() );
+
   // This is any Window that is not the main (default) one
   WindowPane additionalWindow;
   additionalWindow.instance = childWindow;
   additionalWindow.window_name = childWindowName;
   additionalWindow.class_name = childWindowClassName;
   additionalWindow.window_mode = childWindowMode;
+  additionalWindow.surface = windowImpl.GetSurface();
+  additionalWindow.id = windowImpl.GetId();
 
   // Add the new Window to the Frame - the order is not important
   mWindowFrame.push_back( additionalWindow );
 
-  Window& windowImpl = Dali::GetImplementation( *childWindow );
-  windowImpl.SetAdaptor( Get() );
-
   return true;
 }
 
@@ -612,6 +628,20 @@ bool Adaptor::RemoveWindow( std::string childWindowName )
   return false;
 }
 
+bool Adaptor::RemoveWindow( Window* childWindow )
+{
+  for ( WindowFrames::iterator iter = mWindowFrame.begin(); iter != mWindowFrame.end(); ++iter )
+  {
+    if( iter->id == childWindow->GetId() )
+    {
+      mWindowFrame.erase( iter );
+      return true;
+    }
+  }
+
+  return false;
+}
+
 Dali::Adaptor& Adaptor::Get()
 {
   DALI_ASSERT_ALWAYS( IsAvailable() && "Adaptor not instantiated" );
@@ -675,7 +705,7 @@ SocketFactoryInterface& Adaptor::GetSocketFactoryInterface()
   return mSocketFactory;
 }
 
-RenderSurface* Adaptor::GetRenderSurfaceInterface()
+Dali::RenderSurfaceInterface* Adaptor::GetRenderSurfaceInterface()
 {
   if( !mWindowFrame.empty())
   {
@@ -875,6 +905,10 @@ void Adaptor::OnWindowShown()
     // Force a render task
     RequestUpdateOnce();
   }
+  else
+  {
+    DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowShown: Not shown [%d]\n", mState );
+  }
 }
 
 void Adaptor::OnWindowHidden()
@@ -886,6 +920,10 @@ void Adaptor::OnWindowHidden()
     // Adaptor cannot be resumed until the window is shown
     mState = PAUSED_WHILE_HIDDEN;
   }
+  else
+  {
+    DALI_LOG_RELEASE_INFO( "Adaptor::OnWindowHidden: Not hidden [%d]\n", mState );
+  }
 }
 
 // Dali::Internal::Adaptor::Adaptor::OnDamaged
@@ -895,15 +933,15 @@ void Adaptor::OnDamaged( const DamageArea& area )
   RequestUpdate( false );
 }
 
-void Adaptor::SurfaceResizePrepare( SurfaceSize surfaceSize )
+void Adaptor::SurfaceResizePrepare( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
 {
   // Let the core know the surface size has changed
-  mCore->SurfaceResized( surfaceSize.GetWidth(), surfaceSize.GetHeight() );
+  mCore->SurfaceResized( surface );
 
   mResizedSignal.Emit( mAdaptor );
 }
 
-void Adaptor::SurfaceResizeComplete( SurfaceSize surfaceSize )
+void Adaptor::SurfaceResizeComplete( Dali::RenderSurfaceInterface* surface, SurfaceSize surfaceSize )
 {
   // Flush the event queue to give the update-render thread chance
   // to start processing messages for new camera setup etc as soon as possible
@@ -916,6 +954,10 @@ void Adaptor::NotifySceneCreated()
 {
   GetCore().SceneCreated();
 
+  // Flush the event queue to give the update-render thread chance
+  // to start processing messages for new camera setup etc as soon as possible
+  ProcessCoreEvents();
+
   // Start thread controller after the scene has been created
   mThreadController->Start();
 
@@ -923,6 +965,8 @@ void Adaptor::NotifySceneCreated()
   SurfaceInitialized();
 
   mState = RUNNING;
+
+  DALI_LOG_RELEASE_INFO( "Adaptor::NotifySceneCreated\n" );
 }
 
 void Adaptor::NotifyLanguageChanged()
@@ -940,6 +984,16 @@ const LogFactoryInterface& Adaptor::GetLogFactory()
   return *mEnvironmentOptions;
 }
 
+void Adaptor::RegisterProcessor( Integration::Processor& processor )
+{
+  GetCore().RegisterProcessor(processor);
+}
+
+void Adaptor::UnregisterProcessor( Integration::Processor& processor )
+{
+  GetCore().UnregisterProcessor(processor);
+}
+
 void Adaptor::RequestUpdateOnce()
 {
   if( mThreadController )
@@ -948,12 +1002,6 @@ void Adaptor::RequestUpdateOnce()
   }
 }
 
-void Adaptor::IndicatorSizeChanged(int height)
-{
-  // Let the core know the indicator height is changed
-  mCore->SetTopMargin(height);
-}
-
 bool Adaptor::ProcessCoreEventsFromIdle()
 {
   ProcessCoreEvents();
@@ -964,7 +1012,7 @@ bool Adaptor::ProcessCoreEventsFromIdle()
   return false;
 }
 
-Adaptor::Adaptor(Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surface, EnvironmentOptions* environmentOptions)
+Adaptor::Adaptor(Any nativeWindow, Dali::Adaptor& adaptor, Dali::RenderSurfaceInterface* surface, EnvironmentOptions* environmentOptions)
 : mResizedSignal(),
   mLanguageChangedSignal(),
   mAdaptor( adaptor ),
@@ -972,7 +1020,9 @@ Adaptor::Adaptor(Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surfac
   mCore( nullptr ),
   mThreadController( nullptr ),
   mVSyncMonitor( nullptr ),
+  mGraphics( nullptr ),
   mDisplayConnection( nullptr ),
+  mWindowFrame(),
   mPlatformAbstraction( nullptr ),
   mEventHandler( nullptr ),
   mCallbackManager( nullptr ),
@@ -1000,6 +1050,7 @@ Adaptor::Adaptor(Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surfac
   WindowPane defaultWindow;
   defaultWindow.nativeWindow = nativeWindow;
   defaultWindow.surface = surface;
+  defaultWindow.id = 0;
 
   std::vector<WindowPane>::iterator iter = mWindowFrame.begin();
   iter = mWindowFrame.insert( iter, defaultWindow );
@@ -1007,31 +1058,6 @@ Adaptor::Adaptor(Any nativeWindow, Dali::Adaptor& adaptor, RenderSurface* surfac
   gThreadLocalAdaptor = this;
 }
 
-// Stereoscopy
-
-void Adaptor::SetViewMode( ViewMode viewMode )
-{
-  WindowPane defaultWindow = mWindowFrame.front();
-  defaultWindow.surface->SetViewMode( viewMode );
-
-  mCore->SetViewMode( viewMode );
-}
-
-ViewMode Adaptor::GetViewMode() const
-{
-  return mCore->GetViewMode();
-}
-
-void Adaptor::SetStereoBase( float stereoBase )
-{
-  mCore->SetStereoBase( stereoBase );
-}
-
-float Adaptor::GetStereoBase() const
-{
-  return mCore->GetStereoBase();
-}
-
 void Adaptor::SetRootLayoutDirection( std::string locale )
 {
   Dali::Stage stage = Dali::Stage::GetCurrent();