From 2f697c09900c0c5a104eac496c41b17ba94225dc Mon Sep 17 00:00:00 2001 From: taeyoon Date: Thu, 17 Nov 2016 20:46:03 +0900 Subject: [PATCH] Modify native render surface for sync. with replace surface Fix black scene after replace surface in NativeRenderSurface Change-Id: Ie3e575c7d7cc1bfc88694ac104bd16e7383ea944 --- adaptors/common/adaptor-impl.cpp | 4 +- adaptors/common/adaptor-impl.h | 10 +-- adaptors/common/adaptor.cpp | 4 + adaptors/integration-api/adaptor.h | 5 ++ .../wayland/native-render-surface.h | 14 +++- adaptors/tizen/native-render-surface-tizen.cpp | 86 ++++++++++++---------- 6 files changed, 72 insertions(+), 51 deletions(-) diff --git a/adaptors/common/adaptor-impl.cpp b/adaptors/common/adaptor-impl.cpp index ee73fd5..ab2ecac 100644 --- a/adaptors/common/adaptor-impl.cpp +++ b/adaptors/common/adaptor-impl.cpp @@ -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); diff --git a/adaptors/common/adaptor-impl.h b/adaptors/common/adaptor-impl.h index 3688d89..479e10e 100644 --- a/adaptors/common/adaptor-impl.h +++ b/adaptors/common/adaptor-impl.h @@ -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 * */ diff --git a/adaptors/common/adaptor.cpp b/adaptors/common/adaptor.cpp index a2e80ad..3e96cf1 100644 --- a/adaptors/common/adaptor.cpp +++ b/adaptors/common/adaptor.cpp @@ -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 ) diff --git a/adaptors/integration-api/adaptor.h b/adaptors/integration-api/adaptor.h index 7de4d65..93fbd7b 100644 --- a/adaptors/integration-api/adaptor.h +++ b/adaptors/integration-api/adaptor.h @@ -337,6 +337,11 @@ public: */ void SetStereoBase( float stereoBase ); + /** + * @brief Informs core the surface size has changed + */ + void SurfaceSizeChanged( const PositionSize& positionSize ); + public: // Signals /** diff --git a/adaptors/integration-api/wayland/native-render-surface.h b/adaptors/integration-api/wayland/native-render-surface.h index 44caaa2..3b0cd42 100644 --- a/adaptors/integration-api/wayland/native-render-surface.h +++ b/adaptors/integration-api/wayland/native-render-surface.h @@ -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; diff --git a/adaptors/tizen/native-render-surface-tizen.cpp b/adaptors/tizen/native-render-surface-tizen.cpp index c202bcc..787507f 100644 --- a/adaptors/tizen/native-render-surface-tizen.cpp +++ b/adaptors/tizen/native-render-surface-tizen.cpp @@ -26,6 +26,7 @@ #include #include #include +#include // INTERNAL INCLUDES #include @@ -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; } } -- 2.7.4