[3.0] Modify native render surface for sync. with replace surface 15/98515/3
authortaeyoon <taeyoon0.lee@samsung.com>
Thu, 17 Nov 2016 11:46:03 +0000 (20:46 +0900)
committertaeyoon <taeyoon0.lee@samsung.com>
Wed, 23 Nov 2016 07:52:18 +0000 (16:52 +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 da9476b..a24c54c 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();
@@ -719,7 +717,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 704d414..62d21fa 100644 (file)
@@ -334,6 +334,11 @@ public:
    */
   void GetAppId( std::string& appId );
 
+  /**
+   * Informs core the surface size has changed
+   */
+  void SurfaceSizeChanged( const PositionSize& positionSize );
+
 public:  //AdaptorInternalServices
 
   /**
@@ -484,11 +489,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 23a3120..565eec2 100644 (file)
@@ -73,12 +73,18 @@ 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 Waits tbm surface after replace surface
+   * After tbm surface is acquired in PostRender, this function is finished.
+   */
+  void WaitDrawableAfterReplaceSurface();
+
 public: // from Dali::RenderSurface
 
   /**
@@ -158,6 +164,11 @@ private:
    */
   virtual void CreateNativeRenderable();
 
+  /**
+   * Release tbm surface
+   */
+  void ReleaseDrawable();
+
 private: // Data
 
   struct Impl;
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