Revert "Remove EGL surface in the update thread"
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-render-surface.cpp
index 18ae128..e1a344f 100644 (file)
@@ -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.
 #include <dali/integration-api/debug.h>
 
 // INTERNAL INCLUDES
-#include <dali/integration-api/trigger-event-factory-interface.h>
-#include <dali/integration-api/thread-synchronization-interface.h>
-#include <dali/internal/graphics/gles/egl-implementation.h>
+#include <dali/integration-api/adaptor-framework/thread-synchronization-interface.h>
+#include <dali/integration-api/adaptor-framework/trigger-event-factory.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/window-system/common/window-base.h>
 #include <dali/internal/window-system/common/window-factory.h>
 #include <dali/internal/window-system/common/window-system.h>
-#include <dali/internal/graphics/gles/egl-graphics.h>
-
+#include <dali/internal/system/common/environment-variables.h>
 
 namespace Dali
 {
@@ -71,7 +71,9 @@ WindowRenderSurface::WindowRenderSurface( Dali::PositionSize positionSize, Any s
   mRotationSupported( false ),
   mRotationFinished( true ),
   mScreenRotationFinished( true ),
-  mResizeFinished( true )
+  mResizeFinished( true ),
+  mDpiHorizontal( 0 ),
+  mDpiVertical( 0 )
 {
   DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "Creating Window\n" );
   Initialize( surface );
@@ -83,6 +85,11 @@ WindowRenderSurface::~WindowRenderSurface()
   {
     delete mRotationTrigger;
   }
+
+  if ( mEGLSurface )
+  {
+    DestroySurface();
+  }
 }
 
 void WindowRenderSurface::Initialize( Any surface )
@@ -93,7 +100,6 @@ void WindowRenderSurface::Initialize( Any surface )
     // Default window size == screen size
     mPositionSize.x = 0;
     mPositionSize.y = 0;
-
     WindowSystem::GetScreenSize( mPositionSize.width, mPositionSize.height );
   }
 
@@ -147,8 +153,7 @@ void WindowRenderSurface::RequestRotation( int angle, int width, int height )
 
   if( !mRotationTrigger )
   {
-    TriggerEventFactoryInterface& triggerFactory = Internal::Adaptor::Adaptor::GetImplementation( Adaptor::Get() ).GetTriggerEventFactoryInterface();
-    mRotationTrigger = triggerFactory.CreateTriggerEvent( MakeCallback( this, &WindowRenderSurface::ProcessRotationRequest ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER );
+    mRotationTrigger = TriggerEventFactory::CreateTriggerEvent( MakeCallback( this, &WindowRenderSurface::ProcessRotationRequest ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER );
   }
 
   mPositionSize.width = width;
@@ -179,14 +184,30 @@ PositionSize WindowRenderSurface::GetPositionSize() const
 
 void WindowRenderSurface::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
 {
-  mWindowBase->GetDpi( dpiHorizontal, dpiVertical );
+  if( mDpiHorizontal == 0 || mDpiVertical == 0 )
+  {
+    const char* environmentDpiHorizontal = std::getenv( DALI_ENV_DPI_HORIZONTAL );
+    mDpiHorizontal = environmentDpiHorizontal ? std::atoi( environmentDpiHorizontal ) : 0;
+
+    const char* environmentDpiVertical = std::getenv( DALI_ENV_DPI_VERTICAL );
+    mDpiVertical = environmentDpiVertical ? std::atoi( environmentDpiVertical ) : 0;
+
+    if( mDpiHorizontal == 0 || mDpiVertical == 0 )
+    {
+      mWindowBase->GetDpi( mDpiHorizontal, mDpiVertical );
+    }
+  }
+
+  dpiHorizontal = mDpiHorizontal;
+  dpiVertical = mDpiVertical;
 }
 
 void WindowRenderSurface::InitializeGraphics()
 {
-
   mGraphics = &mAdaptor->GetGraphicsInterface();
 
+  DALI_ASSERT_ALWAYS( mGraphics && "Graphics interface is not created" );
+
   auto eglGraphics = static_cast<EglGraphics *>(mGraphics);
   mEGL = &eglGraphics->GetEglInterface();
 
@@ -229,7 +250,8 @@ void WindowRenderSurface::CreateSurface()
   // Check rotation capability
   mRotationSupported = mWindowBase->IsEglWindowRotationSupported();
 
-  DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::CreateSurface: w = %d h = %d angle = %d screen rotation = %d\n", mPositionSize.width, mPositionSize.height, mRotationAngle, mScreenRotationAngle );
+  DALI_LOG_RELEASE_INFO("WindowRenderSurface::CreateSurface: WinId (%d), w = %d h = %d angle = %d screen rotation = %d\n",
+      mWindowBase->GetNativeWindowId(), mPositionSize.width, mPositionSize.height, mRotationAngle, mScreenRotationAngle );
 }
 
 void WindowRenderSurface::DestroySurface()
@@ -237,11 +259,15 @@ void WindowRenderSurface::DestroySurface()
   DALI_LOG_TRACE_METHOD( gWindowRenderSurfaceLogFilter );
 
   auto eglGraphics = static_cast<EglGraphics *>(mGraphics);
+  if( eglGraphics )
+  {
+    DALI_LOG_RELEASE_INFO("WindowRenderSurface::DestroySurface: WinId (%d)\n", mWindowBase->GetNativeWindowId() );
 
-  Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
-  eglImpl.DestroySurface( mEGLSurface );
+    Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
+    eglImpl.DestroySurface( mEGLSurface );
 
-  mWindowBase->DestroyEglWindow();
+    mWindowBase->DestroyEglWindow();
+  }
 }
 
 bool WindowRenderSurface::ReplaceGraphicsSurface()
@@ -391,7 +417,13 @@ void WindowRenderSurface::PostRender( bool renderToFbo, bool replacingSurface, b
       {
         if( !mRotationFinished )
         {
-          DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::PostRender: Trigger rotation event\n" );
+          if( mThreadSynchronization )
+          {
+            // Enable PostRender flag
+            mThreadSynchronization->PostRenderStarted();
+          }
+
+          DALI_LOG_RELEASE_INFO("WindowRenderSurface::PostRender: Trigger rotation event\n" );
 
           mRotationTrigger->Trigger();
 
@@ -411,12 +443,6 @@ void WindowRenderSurface::PostRender( bool renderToFbo, bool replacingSurface, b
     {
       mRenderNotification->Trigger();
     }
-
-    if ( eglImpl.IsSurfacelessContextSupported() )
-    {
-      // Switch to the shared context after rendering this surface
-      eglImpl.MakeContextCurrent( EGL_NO_SURFACE, eglImpl.GetContext() );
-    }
   }
 }
 
@@ -436,9 +462,9 @@ void WindowRenderSurface::ReleaseLock()
   // Nothing to do.
 }
 
-Integration::RenderSurface::Type WindowRenderSurface::GetSurfaceType()
+Dali::RenderSurfaceInterface::Type WindowRenderSurface::GetSurfaceType()
 {
-  return RenderSurface::WINDOW_RENDER_SURFACE;
+  return Dali::RenderSurfaceInterface::WINDOW_RENDER_SURFACE;
 }
 
 void WindowRenderSurface::MakeContextCurrent()