[3.0] Modify native render surface for sync. with replace surface
[platform/core/uifw/dali-adaptor.git] / adaptors / tizen / native-render-surface-tizen.cpp
index ecca85d..a43aa12 100644 (file)
@@ -26,6 +26,7 @@
 #include <Ecore_Wayland.h>
 #include <tbm_bufmgr.h>
 #include <tbm_surface_queue.h>
+#include <tbm_surface_internal.h>
 
 // INTERNAL INCLUDES
 #include <trigger-event.h>
@@ -49,6 +50,7 @@ struct NativeRenderSurface::Impl
     mColorDepth( isTransparent ? COLOR_DEPTH_32 : COLOR_DEPTH_24 ),
     mTbmFormat( isTransparent ? TBM_FORMAT_ARGB8888 : TBM_FORMAT_RGB888 ),
     mOwnSurface( false ),
+    mDrawableCompleted( false ),
     mConsumeSurface( NULL ),
     mThreadSynchronization( NULL )
   {
@@ -60,6 +62,7 @@ struct NativeRenderSurface::Impl
   ColorDepth mColorDepth;
   tbm_format mTbmFormat;
   bool mOwnSurface;
+  bool mDrawableCompleted;
 
   tbm_surface_queue_h mTbmQueue;
   tbm_surface_h mConsumeSurface;
@@ -82,11 +85,7 @@ NativeRenderSurface::~NativeRenderSurface()
   // release the surface if we own one
   if( mImpl->mOwnSurface )
   {
-    if( mImpl->mConsumeSurface )
-    {
-      tbm_surface_queue_release( mImpl->mTbmQueue, mImpl->mConsumeSurface );
-      mImpl->mConsumeSurface = NULL;
-    }
+    ReleaseDrawable();
 
     if( mImpl->mTbmQueue )
     {
@@ -106,8 +105,6 @@ void NativeRenderSurface::SetRenderNotification( TriggerEventInterface* renderNo
 
 tbm_surface_h NativeRenderSurface::GetDrawable()
 {
-  ConditionalWait::ScopedLock lock( mImpl->mTbmSurfaceCondition );
-
   return mImpl->mConsumeSurface;
 }
 
@@ -147,19 +144,6 @@ bool NativeRenderSurface::ReplaceEGLSurface( EglInterface& egl )
 {
   DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
 
-  if( mImpl->mConsumeSurface )
-  {
-    tbm_surface_queue_release( mImpl->mTbmQueue, mImpl->mConsumeSurface );
-    mImpl->mConsumeSurface = NULL;
-  }
-
-  if( mImpl->mTbmQueue )
-  {
-    tbm_surface_queue_destroy( mImpl->mTbmQueue );
-  }
-
-  CreateNativeRenderable();
-
   if( !mImpl->mTbmQueue )
   {
     return false;
@@ -199,8 +183,17 @@ void NativeRenderSurface::PostRender( EglInterface& egl, Integration::GlAbstract
     }
   }
 
+  tbm_surface_internal_ref( mImpl->mConsumeSurface );
+
+  if( replacingSurface )
+  {
+    ConditionalWait::ScopedLock lock( mImpl->mTbmSurfaceCondition );
+    mImpl->mDrawableCompleted = true;
+    mImpl->mTbmSurfaceCondition.Notify( lock );
+  }
+
  // create damage for client applications which wish to know the update timing
-  if( mImpl->mRenderNotification )
+  if( !replacingSurface && mImpl->mRenderNotification )
   {
     // use notification trigger
     // Tell the event-thread to render the tbm_surface
@@ -214,11 +207,7 @@ void NativeRenderSurface::PostRender( EglInterface& egl, Integration::GlAbstract
   }
 
   // release the consumed surface after post render was completed
-  if( mImpl->mConsumeSurface )
-  {
-    tbm_surface_queue_release( mImpl->mTbmQueue, mImpl->mConsumeSurface );
-    mImpl->mConsumeSurface = NULL;
-  }
+  ReleaseDrawable();
 }
 
 void NativeRenderSurface::StopRender()
@@ -252,7 +241,7 @@ RenderSurface::Type NativeRenderSurface::GetSurfaceType()
 void NativeRenderSurface::CreateNativeRenderable()
 {
   // check we're creating one with a valid size
-  DALI_ASSERT_ALWAYS( mImpl->mPosition.width > 0 && mImpl->mPosition.height > 0 && "Pixmap size is invalid" );
+  DALI_ASSERT_ALWAYS( mImpl->mPosition.width > 0 && mImpl->mPosition.height > 0 && "tbm_surface size is invalid" );
 
   mImpl->mTbmQueue = tbm_surface_queue_create( 3, mImpl->mPosition.width, mImpl->mPosition.height, mImpl->mTbmFormat, TBM_BO_DEFAULT );
 
@@ -274,4 +263,29 @@ void NativeRenderSurface::ReleaseLock()
   }
 }
 
+void NativeRenderSurface::WaitDrawableAfterReplaceSurface()
+{
+  ConditionalWait::ScopedLock lock( mImpl->mTbmSurfaceCondition );
+  while( !mImpl->mDrawableCompleted )
+  {
+    mImpl->mTbmSurfaceCondition.Wait( lock );
+  }
+
+  mImpl->mDrawableCompleted = false;
+}
+
+void NativeRenderSurface::ReleaseDrawable()
+{
+  if( mImpl->mConsumeSurface )
+  {
+    tbm_surface_internal_unref( mImpl->mConsumeSurface );
+
+    if( tbm_surface_internal_is_valid( mImpl->mConsumeSurface ) )
+    {
+      tbm_surface_queue_release( mImpl->mTbmQueue, mImpl->mConsumeSurface );
+    }
+    mImpl->mConsumeSurface = NULL;
+  }
+}
+
 } // namespace Dali