[Tizen] Add OffscreenApplication
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / native-render-surface-ecore-wl.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 76e0d89..15a603e
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 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.
@@ -53,8 +53,8 @@ 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 ),
@@ -70,8 +70,16 @@ 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()
@@ -120,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 )
@@ -150,7 +158,6 @@ int NativeRenderSurfaceEcoreWl::GetOrientation() const
 void NativeRenderSurfaceEcoreWl::InitializeGraphics()
 {
   DALI_LOG_TRACE_METHOD( gNativeSurfaceLogFilter );
-  unsetenv( "EGL_PLATFORM" );
 
   mGraphics = &mAdaptor->GetGraphicsInterface();
   auto eglGraphics = static_cast<Internal::Adaptor::EglGraphics *>(mGraphics);
@@ -214,77 +221,98 @@ void NativeRenderSurfaceEcoreWl::MoveResize( Dali::PositionSize positionSize )
     DALI_LOG_ERROR( "Failed to resize tbm_surface_queue" );
   }
 
-  mPosition = positionSize;
+  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
-  return true;
-}
+  MakeContextCurrent();
 
-void NativeRenderSurfaceEcoreWl::SetDamagedRect( const Dali::DamagedRect& damagedRect, Dali::DamagedRect& mergedRect )
-{
-}
+  auto eglGraphics = static_cast<Internal::Adaptor::EglGraphics*>(mGraphics);
+  if (eglGraphics)
+  {
+    Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
+    if (resizingSurface)
+    {
+      eglImpl.SetFullSwapNextFrame();
+    }
 
-int32_t NativeRenderSurfaceEcoreWl::GetBufferAge()
-{
-  return 0;
+    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);
-  if ( eglGraphics )
+  if (eglGraphics)
   {
     Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
-
-    eglImpl.SwapBuffers( mEGLSurface );
+    eglImpl.SwapBuffers( mEGLSurface, damagedRects );
   }
 
-  if( mThreadSynchronization )
+  if ( mOwnSurface )
   {
-    mThreadSynchronization->PostRenderStarted();
-  }
+    if( mThreadSynchronization )
+    {
+      mThreadSynchronization->PostRenderStarted();
+    }
 
-  if( tbm_surface_queue_can_acquire( mTbmQueue, 1 ) )
-  {
-    if( tbm_surface_queue_acquire( mTbmQueue, &mConsumeSurface ) != TBM_SURFACE_QUEUE_ERROR_NONE )
+    if( tbm_surface_queue_can_acquire( mTbmQueue, 1 ) )
     {
-      DALI_LOG_ERROR( "Failed to acquire a tbm_surface\n" );
-      return;
+      if( tbm_surface_queue_acquire( mTbmQueue, &mConsumeSurface ) != TBM_SURFACE_QUEUE_ERROR_NONE )
+      {
+        DALI_LOG_ERROR( "Failed to acquire a tbm_surface\n" );
+        return;
+      }
     }
-  }
 
-  tbm_surface_internal_ref( mConsumeSurface );
+    if ( mConsumeSurface )
+    {
+      tbm_surface_internal_ref( mConsumeSurface );
+    }
 
-  if( replacingSurface )
-  {
-    ConditionalWait::ScopedLock lock( mTbmSurfaceCondition );
-    mDrawableCompleted = true;
-    mTbmSurfaceCondition.Notify( lock );
-  }
+    if( replacingSurface )
+    {
+      ConditionalWait::ScopedLock lock( mTbmSurfaceCondition );
+      mDrawableCompleted = true;
+      mTbmSurfaceCondition.Notify( lock );
+    }
 
- // create damage for client applications which wish to know the update timing
-  if( !replacingSurface && mRenderNotification )
-  {
-    // use notification trigger
-    // Tell the event-thread to render the tbm_surface
-    mRenderNotification->Trigger();
-  }
  // create damage for client applications which wish to know the update timing
+    if( !replacingSurface && mRenderNotification )
+    {
+      // use notification trigger
+      // Tell the event-thread to render the tbm_surface
+      mRenderNotification->Trigger();
+    }
 
-  if( mThreadSynchronization )
+    if( mThreadSynchronization )
+    {
+      // wait until the event-thread completed to use the tbm_surface
+      mThreadSynchronization->PostRenderWaitForCompletion();
+    }
+
+    // release the consumed surface after post render was completed
+    ReleaseDrawable();
+  }
+  else
   {
-    // wait until the event-thread completed to use the tbm_surface
-    mThreadSynchronization->PostRenderWaitForCompletion();
+    // create damage for client applications which wish to know the update timing
+    if( !replacingSurface && mRenderNotification )
+    {
+      // use notification trigger
+      // Tell the event-thread to render the tbm_surface
+      mRenderNotification->Trigger();
+    }
   }
 
-  // release the consumed surface after post render was completed
-  ReleaseDrawable();
 }
 
 void NativeRenderSurfaceEcoreWl::StopRender()
@@ -297,9 +325,9 @@ void NativeRenderSurfaceEcoreWl::SetThreadSynchronization( ThreadSynchronization
   mThreadSynchronization = &threadSynchronization;
 }
 
-Integration::RenderSurface::Type NativeRenderSurfaceEcoreWl::GetSurfaceType()
+Dali::RenderSurfaceInterface::Type NativeRenderSurfaceEcoreWl::GetSurfaceType()
 {
-  return Integration::RenderSurface::NATIVE_RENDER_SURFACE;
+  return Dali::RenderSurfaceInterface::NATIVE_RENDER_SURFACE;
 }
 
 void NativeRenderSurfaceEcoreWl::MakeContextCurrent()
@@ -320,6 +348,11 @@ Integration::StencilBufferAvailable NativeRenderSurfaceEcoreWl::GetStencilBuffer
   return mGraphics ? mGraphics->GetStencilBufferRequired() : Integration::StencilBufferAvailable::FALSE;
 }
 
+Any NativeRenderSurfaceEcoreWl::GetNativeHandle()
+{
+  return mTbmQueue;
+}
+
 void NativeRenderSurfaceEcoreWl::ReleaseLock()
 {
   if( mThreadSynchronization )
@@ -330,10 +363,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 )
   {