Modify native render surface for sync. with replace surface 28/102328/3
authortaeyoon <taeyoon0.lee@samsung.com>
Thu, 17 Nov 2016 11:46:03 +0000 (20:46 +0900)
committertaeyoon <taeyoon0.lee@samsung.com>
Tue, 27 Dec 2016 06:08:17 +0000 (15:08 +0900)
  Fix black scene after replace surface in NativeRenderSurface

Change-Id: Ie3e575c7d7cc1bfc88694ac104bd16e7383ea944

adaptors/common/adaptor-impl.cpp
adaptors/common/adaptor-impl.h
adaptors/common/adaptor.cpp
adaptors/integration-api/adaptor.h
adaptors/integration-api/wayland/native-render-surface.h
adaptors/tizen/native-render-surface-tizen.cpp

index ee73fd5..ab2ecac 100644 (file)
@@ -423,8 +423,6 @@ void Adaptor::ReplaceSurface( Any nativeWindow, RenderSurface& surface )
   mNativeWindow = nativeWindow;
   mSurface = &surface;
 
-  SurfaceSizeChanged(mSurface->GetPositionSize());
-
   // flush the event queue to give update and render threads chance
   // to start processing messages for new camera setup etc as soon as possible
   ProcessCoreEvents();
@@ -724,7 +722,7 @@ void Adaptor::OnDamaged( const DamageArea& area )
   RequestUpdate();
 }
 
-void Adaptor::SurfaceSizeChanged(const PositionSize& positionSize)
+void Adaptor::SurfaceSizeChanged( const PositionSize& positionSize )
 {
   // let the core know the surface size has changed
   mCore->SurfaceResized(positionSize.width, positionSize.height);
index 3688d89..479e10e 100644 (file)
@@ -345,6 +345,11 @@ public:
    */
   void GetAppId( std::string& appId );
 
+  /**
+   * Informs core the surface size has changed
+   */
+  void SurfaceSizeChanged( const PositionSize& positionSize );
+
 public:  //AdaptorInternalServices
 
   /**
@@ -495,11 +500,6 @@ private:
 private:
 
   /**
-   * Informs core the surface size has changed
-   */
-  void SurfaceSizeChanged(const PositionSize& positionSize);
-
-  /**
    * Assigns the render surface to the adaptor
    *
    */
index a2e80ad..3e96cf1 100644 (file)
@@ -184,6 +184,10 @@ void Adaptor::SetStereoBase(  float stereoBase )
   mImpl->SetStereoBase( stereoBase );
 }
 
+void Adaptor::SurfaceSizeChanged( const PositionSize& positionSize )
+{
+  mImpl->SurfaceSizeChanged( positionSize );
+}
 
 Adaptor::Adaptor()
 : mImpl( NULL )
index 7de4d65..93fbd7b 100644 (file)
@@ -337,6 +337,11 @@ public:
    */
   void SetStereoBase( float stereoBase );
 
+  /**
+   * @brief Informs core the surface size has changed
+   */
+  void SurfaceSizeChanged( const PositionSize& positionSize );
+
 public:  // Signals
 
   /**
index 44caaa2..3b0cd42 100644 (file)
@@ -73,16 +73,17 @@ public: // API
   virtual tbm_surface_h GetDrawable();
 
   /**
-   * @brief Get the surface
+   * @brief Gets the surface
    *
-   * @return tbm surface
+   * @return TBM surface
    */
   virtual Any GetSurface();
 
   /**
-   * @brief Release the surface
+   * @brief Waits until surface is replaced
+   * After tbm surface is acquired in PostRender, this function is finished.
    */
-  virtual void ReleaseSurface();
+  void WaitUntilSurfaceReplaced();
 
 public: // from Dali::RenderSurface
 
@@ -163,6 +164,11 @@ private:
    */
   virtual void CreateNativeRenderable();
 
+  /**
+   * Release tbm surface
+   */
+  void ReleaseDrawable();
+
 private: // Data
 
   struct Impl;
index c202bcc..787507f 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,12 +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 )
     {
@@ -107,8 +105,6 @@ void NativeRenderSurface::SetRenderNotification( TriggerEventInterface* renderNo
 
 tbm_surface_h NativeRenderSurface::GetDrawable()
 {
-  ConditionalWait::ScopedLock lock( mImpl->mTbmSurfaceCondition );
-
   return mImpl->mConsumeSurface;
 }
 
@@ -148,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;
@@ -191,31 +174,40 @@ void NativeRenderSurface::PostRender( EglInterface& egl, Integration::GlAbstract
     mImpl->mThreadSynchronization->PostRenderStarted();
   }
 
+  if( tbm_surface_queue_can_acquire( mImpl->mTbmQueue, 1 ) )
   {
-    ConditionalWait::ScopedLock lock( mImpl->mTbmSurfaceCondition );
-
-    if( tbm_surface_queue_can_acquire( mImpl->mTbmQueue, 1 ) )
+    if( tbm_surface_queue_acquire( mImpl->mTbmQueue, &mImpl->mConsumeSurface ) != TBM_SURFACE_QUEUE_ERROR_NONE )
     {
-      if( tbm_surface_queue_acquire( mImpl->mTbmQueue, &mImpl->mConsumeSurface ) != TBM_SURFACE_QUEUE_ERROR_NONE )
-      {
-        DALI_LOG_ERROR( "Failed aquire consume tbm_surface\n" );
-        return;
-      }
+      DALI_LOG_ERROR( "Failed to aquire a tbm_surface\n" );
+      return;
     }
   }
 
+  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 pixmap
+    // Tell the event-thread to render the tbm_surface
     mImpl->mRenderNotification->Trigger();
   }
 
   if( mImpl->mThreadSynchronization )
   {
+    // wait until the event-thread completed to use the tbm_surface
     mImpl->mThreadSynchronization->PostRenderWaitForCompletion();
   }
+
+  // release the consumed surface after post render was completed
+  ReleaseDrawable();
 }
 
 void NativeRenderSurface::StopRender()
@@ -249,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 );
 
@@ -263,20 +255,36 @@ void NativeRenderSurface::CreateNativeRenderable()
   }
 }
 
-void NativeRenderSurface::ReleaseSurface()
+void NativeRenderSurface::ReleaseLock()
 {
-  if( mImpl->mConsumeSurface )
+  if( mImpl->mThreadSynchronization )
   {
-    tbm_surface_queue_release( mImpl->mTbmQueue, mImpl->mConsumeSurface );
-    mImpl->mConsumeSurface = NULL;
+    mImpl->mThreadSynchronization->PostRenderComplete();
   }
 }
 
-void NativeRenderSurface::ReleaseLock()
+void NativeRenderSurface::WaitUntilSurfaceReplaced()
 {
-  if( mImpl->mThreadSynchronization )
+  ConditionalWait::ScopedLock lock( mImpl->mTbmSurfaceCondition );
+  while( !mImpl->mDrawableCompleted )
   {
-    mImpl->mThreadSynchronization->PostRenderComplete();
+    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;
   }
 }