Revert "[Tizen] Revert "Support multiple window rendering""
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / ubuntu-x11 / pixmap-render-surface-ecore-x.cpp
index 4a50c5c..c8e049c 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.
 #include <dali/integration-api/thread-synchronization-interface.h>
 #include <dali/internal/system/common/trigger-event.h>
 #include <dali/internal/window-system/common/display-connection.h>
+#include <dali/internal/graphics/gles/egl-graphics.h>
+#include <dali/internal/adaptor/common/adaptor-impl.h>
+#include <dali/internal/adaptor/common/adaptor-internal-services.h>
+
 
 namespace Dali
 {
@@ -52,18 +56,19 @@ static const int INITIAL_PRODUCE_BUFFER_INDEX = 0;
 static const int INITIAL_CONSUME_BUFFER_INDEX = 1;
 }
 
-PixmapRenderSurfaceEcoreX::PixmapRenderSurfaceEcoreX(Dali::PositionSize positionSize,
-                                         Any surface,
-                                         const std::string& name,
-                                         bool isTransparent)
-: mPosition( positionSize ),
-  mTitle( name ),
+PixmapRenderSurfaceEcoreX::PixmapRenderSurfaceEcoreX( Dali::PositionSize positionSize, Any surface, bool isTransparent )
+: mGraphics( nullptr ),
+  mDisplayConnection( nullptr ),
+  mPosition( positionSize ),
   mRenderNotification( NULL ),
   mColorDepth( isTransparent ? COLOR_DEPTH_32 : COLOR_DEPTH_24 ),
   mOwnSurface( false ),
   mProduceBufferIndex( INITIAL_PRODUCE_BUFFER_INDEX ),
   mConsumeBufferIndex( INITIAL_CONSUME_BUFFER_INDEX ),
-  mThreadSynchronization(NULL)
+  mX11Pixmaps(),
+  mEglSurfaces(),
+  mThreadSynchronization( nullptr ),
+  mPixmapCondition()
 {
   for( int i = 0; i != BUFFER_COUNT; ++i )
   {
@@ -130,20 +135,36 @@ PositionSize PixmapRenderSurfaceEcoreX::GetPositionSize() const
   return mPosition;
 }
 
-void PixmapRenderSurfaceEcoreX::InitializeEgl( EglInterface& egl )
+void PixmapRenderSurfaceEcoreX::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
 {
-  DALI_LOG_TRACE_METHOD( gPixmapRenderSurfaceLogFilter );
+  // calculate DPI
+  float xres, yres;
+
+  // 1 inch = 25.4 millimeters
+  xres = ecore_x_dpi_get();
+  yres = ecore_x_dpi_get();
+
+  dpiHorizontal = int( xres + 0.5f );  // rounding
+  dpiVertical   = int( yres + 0.5f );
+}
+
+void PixmapRenderSurfaceEcoreX::InitializeGraphics()
+{
+  mGraphics = &mAdaptor->GetGraphicsInterface();
+  mDisplayConnection = &mAdaptor->GetDisplayConnectionInterface();
 
-  Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
 
+  auto eglGraphics = static_cast<EglGraphics *>(mGraphics);
+  Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
   eglImpl.ChooseConfig(false, mColorDepth);
 }
 
-void PixmapRenderSurfaceEcoreX::CreateEglSurface( EglInterface& egl )
+void PixmapRenderSurfaceEcoreX::CreateSurface()
 {
   DALI_LOG_TRACE_METHOD( gPixmapRenderSurfaceLogFilter );
 
-  Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
+  auto eglGraphics = static_cast<EglGraphics *>(mGraphics);
+  Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
 
   for (int i = 0; i < BUFFER_COUNT; ++i)
   {
@@ -154,28 +175,32 @@ void PixmapRenderSurfaceEcoreX::CreateEglSurface( EglInterface& egl )
   }
 }
 
-void PixmapRenderSurfaceEcoreX::DestroyEglSurface( EglInterface& egl )
+void PixmapRenderSurfaceEcoreX::DestroySurface()
 {
   DALI_LOG_TRACE_METHOD( gPixmapRenderSurfaceLogFilter );
 
-  Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
+  auto eglGraphics = static_cast<EglGraphics *>(mGraphics);
+
+  Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
 
   for (int i = 0; i < BUFFER_COUNT; ++i)
   {
     // need to cast to X handle as in 64bit system ECore handle is 32 bit whereas EGLnative and XWindow are 64 bit
     XPixmap pixmap = static_cast<XPixmap>( mX11Pixmaps[i] );
     eglImpl.MakeCurrent( EGLNativePixmapType( pixmap ), mEglSurfaces[i] );
-    eglImpl.DestroySurface();
+    eglImpl.DestroySurface( mEglSurfaces[i] );
   }
 }
 
-bool PixmapRenderSurfaceEcoreX::ReplaceEGLSurface( EglInterface& egl )
+bool PixmapRenderSurfaceEcoreX::ReplaceGraphicsSurface()
 {
   DALI_LOG_TRACE_METHOD( gPixmapRenderSurfaceLogFilter );
 
   bool contextLost = false;
 
-  Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
+  auto eglGraphics = static_cast<EglGraphics *>(mGraphics);
+
+  Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
 
   for (int i = 0; i < BUFFER_COUNT; ++i)
   {
@@ -196,15 +221,18 @@ void PixmapRenderSurfaceEcoreX::StartRender()
 {
 }
 
-bool PixmapRenderSurfaceEcoreX::PreRender( EglInterface& egl, Integration::GlAbstraction&, bool )
+bool PixmapRenderSurfaceEcoreX::PreRender( bool )
 {
   // Nothing to do for pixmaps
   return true;
 }
 
-void PixmapRenderSurfaceEcoreX::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, Dali::DisplayConnection* displayConnection, bool replacingSurface, bool resizingSurface )
+void PixmapRenderSurfaceEcoreX::PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface )
 {
+  auto eglGraphics = static_cast<EglGraphics *>(mGraphics);
+
   // flush gl instruction queue
+  Integration::GlAbstraction& glAbstraction = eglGraphics->GetGlAbstraction();
   glAbstraction.Flush();
 
   if( mThreadSynchronization )
@@ -216,7 +244,7 @@ void PixmapRenderSurfaceEcoreX::PostRender( EglInterface& egl, Integration::GlAb
     ConditionalWait::ScopedLock lock( mPixmapCondition );
     mConsumeBufferIndex = __sync_fetch_and_xor( &mProduceBufferIndex, 1 ); // Swap buffer indexes.
 
-    Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
+    Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
 
     // need to cast to X handle as in 64bit system ECore handle is 32 bit whereas EGLnative and XWindow are 64 bit
     XPixmap pixmap = static_cast<XPixmap>( mX11Pixmaps[mProduceBufferIndex] );
@@ -245,7 +273,7 @@ void PixmapRenderSurfaceEcoreX::PostRender( EglInterface& egl, Integration::GlAb
       rect.width = mPosition.width;
       rect.height = mPosition.height;
 
-      XDisplay* display = AnyCast<XDisplay*>(displayConnection->GetDisplay());
+      XDisplay* display = AnyCast<XDisplay*>(mDisplayConnection->GetDisplay());
 
       // make a fixes region as updated area
       region = XFixesCreateRegion( display, &rect, 1 );
@@ -282,9 +310,13 @@ void PixmapRenderSurfaceEcoreX::ReleaseLock()
   }
 }
 
-RenderSurface::Type PixmapRenderSurfaceEcoreX::GetSurfaceType()
+Integration::RenderSurface::Type PixmapRenderSurfaceEcoreX::GetSurfaceType()
+{
+  return Integration::RenderSurface::PIXMAP_RENDER_SURFACE;
+}
+
+void PixmapRenderSurfaceEcoreX::MakeContextCurrent()
 {
-  return RenderSurface::PIXMAP_RENDER_SURFACE;
 }
 
 void PixmapRenderSurfaceEcoreX::CreateRenderable()