Fixed prevent defect
[platform/core/uifw/dali-adaptor.git] / adaptors / x11 / pixmap-render-surface-x.cpp
index f950648..816d2d5 100644 (file)
 #include <dali/integration-api/debug.h>
 
 // INTERNAL INCLUDES
+
 #include <ecore-x-types.h>
 #include <trigger-event.h>
+#include <gl/egl-implementation.h>
+#include <base/display-connection.h>
 
 namespace Dali
 {
 
-namespace Internal
-{
-
-namespace Adaptor
-{
-
 #if defined(DEBUG_ENABLED)
 extern Debug::Filter* gRenderSurfaceLogFilter;
 #endif
@@ -49,12 +46,13 @@ extern Debug::Filter* gRenderSurfaceLogFilter;
 namespace ECore
 {
 
-PixmapRenderSurface::PixmapRenderSurface( Dali::PositionSize positionSize,
-                              Any surface,
-                              Any display,
-                              const std::string& name,
-                              bool isTransparent)
-: RenderSurface( Dali::RenderSurface::PIXMAP, positionSize, surface, display, name, isTransparent )
+PixmapRenderSurface::PixmapRenderSurface(Dali::PositionSize positionSize,
+                                         Any surface,
+                                         const std::string& name,
+                                         bool isTransparent)
+: EcoreXRenderSurface( positionSize, surface, name, isTransparent ),
+  mSyncMode(SYNC_MODE_NONE),
+  mSyncReceived(false)
 {
   Init( surface );
 }
@@ -72,12 +70,7 @@ PixmapRenderSurface::~PixmapRenderSurface()
 
 Ecore_X_Drawable PixmapRenderSurface::GetDrawable()
 {
-  return (Ecore_X_Drawable)mX11Pixmap;
-}
-
-Dali::RenderSurface::SurfaceType PixmapRenderSurface::GetType()
-{
-  return Dali::RenderSurface::PIXMAP;
+  return (Ecore_X_Drawable) mX11Pixmap;
 }
 
 Any PixmapRenderSurface::GetSurface()
@@ -85,48 +78,51 @@ Any PixmapRenderSurface::GetSurface()
   return Any( mX11Pixmap );
 }
 
-void PixmapRenderSurface::InitializeEgl( EglInterface& eglIf )
+void PixmapRenderSurface::InitializeEgl( EglInterface& egl )
 {
   DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
 
-  EglImplementation& eglImpl = static_cast<EglImplementation&>( eglIf );
-  eglImpl.InitializeGles( reinterpret_cast< EGLNativeDisplayType >( mMainDisplay ) );
+  Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
 
   eglImpl.ChooseConfig(false, mColorDepth);
 }
 
-void PixmapRenderSurface::CreateEglSurface( EglInterface& eglIf )
+void PixmapRenderSurface::CreateEglSurface( EglInterface& egl )
 {
   DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
 
-  EglImplementation& eglImpl = static_cast<EglImplementation&>( eglIf );
+  Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
 
   // create the EGL surface
   // 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>( mX11Pixmap );
+  XPixmap pixmap = static_cast<XPixmap>( mX11Pixmap );
   eglImpl.CreateSurfacePixmap( (EGLNativePixmapType)pixmap, mColorDepth ); // reinterpret_cast does not compile
 }
 
-void PixmapRenderSurface::DestroyEglSurface( EglInterface& eglIf )
+void PixmapRenderSurface::DestroyEglSurface( EglInterface& egl )
 {
   DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
 
-  EglImplementation& eglImpl = static_cast<EglImplementation&>( eglIf );
+  Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
   eglImpl.DestroySurface();
 }
 
-bool PixmapRenderSurface::ReplaceEGLSurface( EglInterface& eglIf )
+bool PixmapRenderSurface::ReplaceEGLSurface( EglInterface& egl )
 {
   DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
 
-  EglImplementation& eglImpl = static_cast<EglImplementation&>( eglIf );
-  eglImpl.InitializeGles( reinterpret_cast< EGLNativeDisplayType >( mMainDisplay ) );
-
   // a new surface for the new pixmap
   // 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>( mX11Pixmap );
-  return eglImpl.ReplaceSurfacePixmap( (EGLNativePixmapType)pixmap, // reinterpret_cast does not compile
-                                       reinterpret_cast< EGLNativeDisplayType >( mMainDisplay ) );
+  XPixmap pixmap = static_cast<XPixmap>( mX11Pixmap );
+  Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
+
+  return eglImpl.ReplaceSurfacePixmap( (EGLNativePixmapType)pixmap ); // reinterpret_cast does not compile
+
+}
+
+void PixmapRenderSurface::StartRender()
+{
+  mSyncMode = SYNC_MODE_WAIT;
 }
 
 bool PixmapRenderSurface::PreRender( EglInterface&, Integration::GlAbstraction& )
@@ -135,7 +131,7 @@ bool PixmapRenderSurface::PreRender( EglInterface&, Integration::GlAbstraction&
   return true;
 }
 
-void PixmapRenderSurface::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, unsigned int timeDelta, SyncMode syncMode )
+void PixmapRenderSurface::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, unsigned int deltaTime, bool replacingSurface )
 {
   // flush gl instruction queue
   glAbstraction.Flush();
@@ -149,8 +145,7 @@ void PixmapRenderSurface::PostRender( EglInterface& egl, Integration::GlAbstract
   }
   else
   {
-    // as a fallback, send damage event. This is needed until livebox is fixed to
-    // stop using damage events for render
+    // as a fallback, send damage event.
     Ecore_X_Drawable drawable = GetDrawable();
 
     if( drawable )
@@ -163,18 +158,25 @@ void PixmapRenderSurface::PostRender( EglInterface& egl, Integration::GlAbstract
       rect.width = mPosition.width;
       rect.height = mPosition.height;
 
+      XDisplay* display = AnyCast<XDisplay*>(displayConnection->GetDisplay());
+
       // make a fixes region as updated area
-      region = XFixesCreateRegion( mMainDisplay, &rect, 1 );
+      region = XFixesCreateRegion( display, &rect, 1 );
       // add damage event to updated drawable
-      XDamageAdd( mMainDisplay, (Drawable)drawable, region );
-      XFixesDestroyRegion( mMainDisplay, region );
+      XDamageAdd( display, (Drawable)drawable, region );
+      XFixesDestroyRegion( display, region );
 
-      XFlush( mMainDisplay );
+      XFlush( display );
     }
   }
 
-  // Do render synchronisation
-  DoRenderSync( timeDelta, syncMode );
+  AcquireLock( replacingSurface ? SYNC_MODE_NONE : SYNC_MODE_WAIT );
+}
+
+void PixmapRenderSurface::StopRender()
+{
+  SetSyncMode(SYNC_MODE_NONE);
+  ReleaseLock();
 }
 
 void PixmapRenderSurface::CreateXRenderable()
@@ -192,6 +194,9 @@ void PixmapRenderSurface::CreateXRenderable()
   gc = ecore_x_gc_new( mX11Pixmap,
                        ECORE_X_GC_VALUE_MASK_FOREGROUND,
                        &foreground );
+
+  DALI_ASSERT_ALWAYS( gc && "CreateXRenderable(): failed to get gc" );
+
   ecore_x_drawable_rectangle_fill( mX11Pixmap, gc, 0, 0, mPosition.width, mPosition.height );
 
   DALI_ASSERT_ALWAYS( mX11Pixmap && "Failed to create X pixmap" );
@@ -207,7 +212,26 @@ void PixmapRenderSurface::UseExistingRenderable( unsigned int surfaceId )
   mX11Pixmap = static_cast< Ecore_X_Pixmap >( surfaceId );
 }
 
-void PixmapRenderSurface::RenderSync()
+void PixmapRenderSurface::SetSyncMode( SyncMode syncMode )
+{
+  mSyncMode = syncMode;
+}
+
+void PixmapRenderSurface::AcquireLock( SyncMode syncMode )
+{
+  boost::unique_lock< boost::mutex > lock( mSyncMutex );
+
+  // wait for sync
+  if( syncMode != SYNC_MODE_NONE &&
+      mSyncMode != SYNC_MODE_NONE &&
+      !mSyncReceived )
+  {
+    mSyncNotify.wait( lock );
+  }
+  mSyncReceived = false;
+}
+
+void PixmapRenderSurface::ReleaseLock()
 {
   {
     boost::unique_lock< boost::mutex > lock( mSyncMutex );
@@ -220,8 +244,4 @@ void PixmapRenderSurface::RenderSync()
 
 } // namespace ECore
 
-} // namespace Adaptor
-
-} // namespace Internal
-
 } // namespace Dali