Revert "Add OffscreenApplication"
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / native-render-surface-ecore-wl.cpp
index 66364cc..7ade18f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 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 <tbm_surface_internal.h>
 
 // INTERNAL INCLUDES
+#include <dali/integration-api/adaptor-framework/thread-synchronization-interface.h>
+#include <dali/internal/adaptor/common/adaptor-impl.h>
+#include <dali/internal/adaptor/common/adaptor-internal-services.h>
+#include <dali/internal/graphics/gles/egl-graphics.h>
+#include <dali/internal/graphics/gles/egl-implementation.h>
 #include <dali/internal/system/common/trigger-event.h>
-#include <dali/internal/graphics/gles20/egl-implementation.h>
-#include <dali/internal/graphics/gles20/egl-graphics.h>
 #include <dali/internal/window-system/common/display-connection.h>
 #include <dali/internal/window-system/common/window-system.h>
-#include <dali/integration-api/thread-synchronization-interface.h>
 
 namespace Dali
 {
@@ -51,9 +53,13 @@ Debug::Filter* gNativeSurfaceLogFilter = Debug::Filter::New(Debug::Verbose, fals
 
 } // unnamed namespace
 
-NativeRenderSurfaceEcoreWl::NativeRenderSurfaceEcoreWl( Dali::PositionSize positionSize, bool isTransparent )
-: mPosition( positionSize ),
+NativeRenderSurfaceEcoreWl::NativeRenderSurfaceEcoreWl( SurfaceSize surfaceSize, Any surface, bool isTransparent )
+: mSurfaceSize( surfaceSize ),
   mRenderNotification( NULL ),
+  mGraphics( NULL ),
+  mEGL( nullptr ),
+  mEGLSurface( nullptr ),
+  mEGLContext( nullptr ),
   mColorDepth( isTransparent ? COLOR_DEPTH_32 : COLOR_DEPTH_24 ),
   mTbmFormat( isTransparent ? TBM_FORMAT_ARGB8888 : TBM_FORMAT_RGB888 ),
   mOwnSurface( false ),
@@ -64,12 +70,25 @@ NativeRenderSurfaceEcoreWl::NativeRenderSurfaceEcoreWl( Dali::PositionSize posit
 {
   Dali::Internal::Adaptor::WindowSystem::Initialize();
 
-  CreateNativeRenderable();
-  setenv( "EGL_PLATFORM", "tbm", 1 );
+  if( surface.Empty() )
+  {
+    CreateNativeRenderable();
+  }
+  else
+  {
+    // check we have a valid type
+    DALI_ASSERT_ALWAYS( ( surface.GetType() == typeid (tbm_surface_queue_h) ) && "Surface type is invalid" );
+    mTbmQueue = AnyCast< tbm_surface_queue_h >( surface );
+  }
 }
 
 NativeRenderSurfaceEcoreWl::~NativeRenderSurfaceEcoreWl()
 {
+  if ( mEGLSurface )
+  {
+    DestroySurface();
+  }
+
   // release the surface if we own one
   if( mOwnSurface )
   {
@@ -109,7 +128,7 @@ void NativeRenderSurfaceEcoreWl::WaitUntilSurfaceReplaced()
 
 PositionSize NativeRenderSurfaceEcoreWl::GetPositionSize() const
 {
-  return mPosition;
+  return PositionSize( 0, 0, static_cast<int>( mSurfaceSize.GetWidth() ), static_cast<int>( mSurfaceSize.GetHeight() ) );
 }
 
 void NativeRenderSurfaceEcoreWl::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
@@ -131,31 +150,24 @@ void NativeRenderSurfaceEcoreWl::GetDpi( unsigned int& dpiHorizontal, unsigned i
   dpiVertical   = int( yres + 0.5f );
 }
 
-void NativeRenderSurfaceEcoreWl::InitializeGraphics( Internal::Adaptor::GraphicsInterface& graphics, DisplayConnection& displayConnection )
+void NativeRenderSurfaceEcoreWl::InitializeGraphics()
 {
   DALI_LOG_TRACE_METHOD( gNativeSurfaceLogFilter );
-  unsetenv( "EGL_PLATFORM" );
-
-  mGraphics = &graphics;
 
+  mGraphics = &mAdaptor->GetGraphicsInterface();
   auto eglGraphics = static_cast<Internal::Adaptor::EglGraphics *>(mGraphics);
 
-  EglInterface* mEGL = eglGraphics->Create();
-
-  // Initialize EGL & OpenGL
-  displayConnection.Initialize();
-
-  Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>(*mEGL);
-  eglImpl.ChooseConfig(true, mColorDepth);
+  mEGL = &eglGraphics->GetEglInterface();
 
-  // Create the OpenGL context
-  mEGL->CreateContext();
-
-  // Create the OpenGL surface
-  CreateSurface();
+  if ( mEGLContext == NULL )
+  {
+    // Create the OpenGL context for this window
+    Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>(*mEGL);
+    eglImpl.CreateWindowContext( mEGLContext );
 
-  // Make it current
-  mEGL->MakeContextCurrent();
+    // Create the OpenGL surface
+    CreateSurface();
+  }
 }
 
 void NativeRenderSurfaceEcoreWl::CreateSurface()
@@ -165,7 +177,7 @@ void NativeRenderSurfaceEcoreWl::CreateSurface()
   auto eglGraphics = static_cast<Internal::Adaptor::EglGraphics *>(mGraphics);
   Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
 
-  eglImpl.CreateSurfaceWindow( reinterpret_cast< EGLNativeWindowType >( mTbmQueue ), mColorDepth );
+  mEGLSurface = eglImpl.CreateSurfaceWindow( reinterpret_cast< EGLNativeWindowType >( mTbmQueue ), mColorDepth );
 }
 
 void NativeRenderSurfaceEcoreWl::DestroySurface()
@@ -175,7 +187,7 @@ void NativeRenderSurfaceEcoreWl::DestroySurface()
   auto eglGraphics = static_cast<Internal::Adaptor::EglGraphics *>(mGraphics);
   Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
 
-  eglImpl.DestroySurface();
+  eglImpl.DestroySurface( mEGLSurface );
 }
 
 bool NativeRenderSurfaceEcoreWl::ReplaceGraphicsSurface()
@@ -190,33 +202,53 @@ bool NativeRenderSurfaceEcoreWl::ReplaceGraphicsSurface()
   auto eglGraphics = static_cast<Internal::Adaptor::EglGraphics *>(mGraphics);
   Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
 
-  return eglImpl.ReplaceSurfaceWindow( reinterpret_cast< EGLNativeWindowType >( mTbmQueue ) );
+  return eglImpl.ReplaceSurfaceWindow( reinterpret_cast< EGLNativeWindowType >( mTbmQueue ), mEGLSurface, mEGLContext );
 }
 
 void NativeRenderSurfaceEcoreWl::MoveResize( Dali::PositionSize positionSize )
 {
-}
+  tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
 
-void NativeRenderSurfaceEcoreWl::SetViewMode( ViewMode viewMode )
-{
+  error = tbm_surface_queue_reset( mTbmQueue, positionSize.width, positionSize.height, mTbmFormat );
+
+  if( error != TBM_SURFACE_QUEUE_ERROR_NONE )
+  {
+    DALI_LOG_ERROR( "Failed to resize tbm_surface_queue" );
+  }
+
+  mSurfaceSize.SetWidth( static_cast<uint16_t>( positionSize.width ) );
+  mSurfaceSize.SetHeight( static_cast<uint16_t>( positionSize.height ) );
 }
 
 void NativeRenderSurfaceEcoreWl::StartRender()
 {
 }
 
-bool NativeRenderSurfaceEcoreWl::PreRender( bool )
+bool NativeRenderSurfaceEcoreWl::PreRender( bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect )
 {
-  // nothing to do for pixmaps
+  auto eglGraphics = static_cast<Internal::Adaptor::EglGraphics*>(mGraphics);
+  if (eglGraphics)
+  {
+    Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
+    if (resizingSurface)
+    {
+      eglImpl.SetFullSwapNextFrame();
+    }
+
+    eglImpl.SetDamage(mEGLSurface, damagedRects, clippingRect);
+  }
+
   return true;
 }
 
-void NativeRenderSurfaceEcoreWl::PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface )
+void NativeRenderSurfaceEcoreWl::PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface, const std::vector<Rect<int>>& damagedRects )
 {
   auto eglGraphics = static_cast<Internal::Adaptor::EglGraphics *>(mGraphics);
-  Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
-
-  eglImpl.SwapBuffers();
+  if (eglGraphics)
+  {
+    Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
+    eglImpl.SwapBuffers( mEGLSurface, damagedRects );
+  }
 
   if( mThreadSynchronization )
   {
@@ -269,9 +301,27 @@ void NativeRenderSurfaceEcoreWl::SetThreadSynchronization( ThreadSynchronization
   mThreadSynchronization = &threadSynchronization;
 }
 
-RenderSurface::Type NativeRenderSurfaceEcoreWl::GetSurfaceType()
+Dali::RenderSurfaceInterface::Type NativeRenderSurfaceEcoreWl::GetSurfaceType()
 {
-  return RenderSurface::NATIVE_RENDER_SURFACE;
+  return Dali::RenderSurfaceInterface::NATIVE_RENDER_SURFACE;
+}
+
+void NativeRenderSurfaceEcoreWl::MakeContextCurrent()
+{
+  if ( mEGL != nullptr )
+  {
+    mEGL->MakeContextCurrent( mEGLSurface, mEGLContext );
+  }
+}
+
+Integration::DepthBufferAvailable NativeRenderSurfaceEcoreWl::GetDepthBufferRequired()
+{
+  return mGraphics ? mGraphics->GetDepthBufferRequired() : Integration::DepthBufferAvailable::FALSE;
+}
+
+Integration::StencilBufferAvailable NativeRenderSurfaceEcoreWl::GetStencilBufferRequired()
+{
+  return mGraphics ? mGraphics->GetStencilBufferRequired() : Integration::StencilBufferAvailable::FALSE;
 }
 
 void NativeRenderSurfaceEcoreWl::ReleaseLock()
@@ -284,10 +334,13 @@ void NativeRenderSurfaceEcoreWl::ReleaseLock()
 
 void NativeRenderSurfaceEcoreWl::CreateNativeRenderable()
 {
+  int width = static_cast<int>( mSurfaceSize.GetWidth() );
+  int height = static_cast<int>( mSurfaceSize.GetHeight() );
+
   // check we're creating one with a valid size
-  DALI_ASSERT_ALWAYS( mPosition.width > 0 && mPosition.height > 0 && "tbm_surface size is invalid" );
+  DALI_ASSERT_ALWAYS( width > 0 && height > 0 && "tbm_surface size is invalid" );
 
-  mTbmQueue = tbm_surface_queue_create( 3, mPosition.width, mPosition.height, mTbmFormat, TBM_BO_DEFAULT );
+  mTbmQueue = tbm_surface_queue_create( 3, width, height, mTbmFormat, TBM_BO_DEFAULT );
 
   if( mTbmQueue )
   {