X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fadaptor%2Fcommon%2Fcombined-update-render-controller.cpp;h=80bc0a3de178576cc9df959914d9340601d6876a;hb=aecc2d4c642e0cdf360e56accd3e5b96622a707f;hp=aae33400eeb40a1ab7c3d459fb3a9f58cce360a2;hpb=70c70ce03f9d763c3897046ad00ac6dc3b84d95e;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/dali/internal/adaptor/common/combined-update-render-controller.cpp b/dali/internal/adaptor/common/combined-update-render-controller.cpp index aae3340..80bc0a3 100644 --- a/dali/internal/adaptor/common/combined-update-render-controller.cpp +++ b/dali/internal/adaptor/common/combined-update-render-controller.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,17 +21,19 @@ // EXTERNAL INCLUDES #include #include +#include // INTERNAL INCLUDES -#include -#include -#include -#include -#include +#include #include +#include +#include #include #include #include +#include +#include +#include namespace Dali { @@ -91,6 +93,7 @@ CombinedUpdateRenderController::CombinedUpdateRenderController( AdaptorInternalS : mFpsTracker( environmentOptions ), mUpdateStatusLogger( environmentOptions ), mEventThreadSemaphore(), + mGraphicsInitializeSemaphore(), mUpdateRenderThreadWaitCondition(), mAdaptorInterfaces( adaptorInterfaces ), mPerformanceInterface( adaptorInterfaces.GetPerformanceInterface() ), @@ -112,10 +115,12 @@ CombinedUpdateRenderController::CombinedUpdateRenderController( AdaptorInternalS mPendingRequestUpdate( FALSE ), mUseElapsedTimeAfterWait( FALSE ), mNewSurface( NULL ), - mDeletedSurface( nullptr ), mPostRendering( FALSE ), mSurfaceResized( FALSE ), - mForceClear( FALSE ) + mForceClear( FALSE ), + mUploadWithoutRendering( FALSE ), + mFirstFrameAfterResume( FALSE ), + mIsRenderingWindows( false ) { LOG_EVENT_TRACE; @@ -129,10 +134,11 @@ CombinedUpdateRenderController::CombinedUpdateRenderController( AdaptorInternalS currentSurface->SetThreadSynchronization( *this ); } - TriggerEventFactoryInterface& triggerFactory = mAdaptorInterfaces.GetTriggerEventFactoryInterface(); - mSleepTrigger = triggerFactory.CreateTriggerEvent( MakeCallback( this, &CombinedUpdateRenderController::ProcessSleepRequest ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER ); + mSleepTrigger = TriggerEventFactory::CreateTriggerEvent( MakeCallback( this, &CombinedUpdateRenderController::ProcessSleepRequest ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER ); - sem_init( &mEventThreadSemaphore, 0, 0 ); // Initialize to 0 so that it just waits if sem_post has not been called + // Initialize to 0 so that it just waits if sem_post has not been called + sem_init( &mEventThreadSemaphore, 0, 0 ); + sem_init( &mGraphicsInitializeSemaphore, 0, 0 ); } CombinedUpdateRenderController::~CombinedUpdateRenderController() @@ -173,7 +179,7 @@ void CombinedUpdateRenderController::Start() sem_wait( &mEventThreadSemaphore ); } - Integration::RenderSurface* currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface(); + Dali::RenderSurfaceInterface* currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface(); if( currentSurface ) { currentSurface->StartRender(); @@ -183,7 +189,7 @@ void CombinedUpdateRenderController::Start() LOG_EVENT( "Startup Complete, starting Update/Render Thread" ); - RunUpdateRenderThread( CONTINUOUS, false /* No animation progression */ ); + RunUpdateRenderThread( CONTINUOUS, AnimationProgression::NONE, UpdateMode::NORMAL ); DALI_LOG_RELEASE_INFO( "CombinedUpdateRenderController::Start\n" ); } @@ -209,12 +215,13 @@ void CombinedUpdateRenderController::Resume() { LOG_EVENT( "Resuming" ); - RunUpdateRenderThread( CONTINUOUS, true /* Animation progression required while we were paused */ ); + RunUpdateRenderThread( CONTINUOUS, AnimationProgression::USE_ELAPSED_TIME, UpdateMode::NORMAL ); AddPerformanceMarker( PerformanceInterface::RESUME ); mRunning = TRUE; mForceClear = TRUE; + mFirstFrameAfterResume = TRUE; DALI_LOG_RELEASE_INFO( "CombinedUpdateRenderController::Resume\n" ); } @@ -229,7 +236,7 @@ void CombinedUpdateRenderController::Stop() LOG_EVENT_TRACE; // Stop Rendering and the Update/Render Thread - Integration::RenderSurface* currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface(); + Dali::RenderSurfaceInterface* currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface(); if( currentSurface ) { currentSurface->StopRender(); @@ -267,14 +274,14 @@ void CombinedUpdateRenderController::RequestUpdate() { LOG_EVENT( "Processing" ); - RunUpdateRenderThread( CONTINUOUS, false /* No animation progression */ ); + RunUpdateRenderThread( CONTINUOUS, AnimationProgression::NONE, UpdateMode::NORMAL ); } ConditionalWait::ScopedLock updateLock( mUpdateRenderThreadWaitCondition ); mPendingRequestUpdate = TRUE; } -void CombinedUpdateRenderController::RequestUpdateOnce() +void CombinedUpdateRenderController::RequestUpdateOnce( UpdateMode updateMode ) { // Increment the update-request count to the maximum if( mUpdateRequestCount < MAXIMUM_UPDATE_REQUESTS ) @@ -287,7 +294,7 @@ void CombinedUpdateRenderController::RequestUpdateOnce() LOG_EVENT_TRACE; // Run Update/Render once - RunUpdateRenderThread( ONCE, false /* No animation progression */ ); + RunUpdateRenderThread( ONCE, AnimationProgression::NONE, updateMode ); } } @@ -317,26 +324,18 @@ void CombinedUpdateRenderController::ReplaceSurface( Dali::RenderSurfaceInterfac } } -void CombinedUpdateRenderController::DeleteSurface( Dali::RenderSurfaceInterface* surface ) +void CombinedUpdateRenderController::WaitForGraphicsInitialization() { LOG_EVENT_TRACE; if( mUpdateRenderThread ) { - LOG_EVENT( "Starting to delete the surface, event-thread blocked" ); - - // Start replacing the surface. - { - ConditionalWait::ScopedLock lock( mUpdateRenderThreadWaitCondition ); - mPostRendering = FALSE; // Clear the post-rendering flag as Update/Render thread will delete the surface now - mDeletedSurface = surface; - mUpdateRenderThreadWaitCondition.Notify( lock ); - } + LOG_EVENT( "Waiting for graphics initialisation, event-thread blocked" ); - // Wait until the surface has been deleted - sem_wait( &mEventThreadSemaphore ); + // Wait until the graphics has been initialised + sem_wait( &mGraphicsInitializeSemaphore ); - LOG_EVENT( "Surface deleted, event-thread continuing" ); + LOG_EVENT( "graphics initialised, event-thread continuing" ); } } @@ -378,16 +377,28 @@ void CombinedUpdateRenderController::SetPreRenderCallback( CallbackBase* callbac mPreRenderCallback = callback; } +void CombinedUpdateRenderController::AddSurface( Dali::RenderSurfaceInterface* surface ) +{ + LOG_EVENT_TRACE; + LOG_EVENT( "Surface is added" ); + if( mUpdateRenderThread ) + { + // Set the ThreadSyncronizationInterface on the added surface + surface->SetThreadSynchronization( *this ); + } +} + /////////////////////////////////////////////////////////////////////////////////////////////////// // EVENT THREAD /////////////////////////////////////////////////////////////////////////////////////////////////// -void CombinedUpdateRenderController::RunUpdateRenderThread( int numberOfCycles, bool useElapsedTime ) +void CombinedUpdateRenderController::RunUpdateRenderThread( int numberOfCycles, AnimationProgression animationProgression, UpdateMode updateMode ) { ConditionalWait::ScopedLock lock( mUpdateRenderThreadWaitCondition ); mUpdateRenderRunCount = numberOfCycles; mUpdateRenderThreadCanSleep = FALSE; - mUseElapsedTimeAfterWait = useElapsedTime; + mUseElapsedTimeAfterWait = ( animationProgression == AnimationProgression::USE_ELAPSED_TIME ); + mUploadWithoutRendering = ( updateMode == UpdateMode::SKIP_RENDER ); LOG_COUNTER_EVENT( "mUpdateRenderRunCount: %d, mUseElapsedTimeAfterWait: %d", mUpdateRenderRunCount, mUseElapsedTimeAfterWait ); mUpdateRenderThreadWaitCondition.Notify( lock ); } @@ -453,6 +464,9 @@ void CombinedUpdateRenderController::UpdateRenderThread() Dali::DisplayConnection& displayConnection = mAdaptorInterfaces.GetDisplayConnectionInterface(); displayConnection.Initialize(); + // EGL has been initialised at this point + NotifyGraphicsInitialised(); + RenderSurfaceInterface* currentSurface = nullptr; GraphicsInterface& graphics = mAdaptorInterfaces.GetGraphicsInterface(); @@ -493,6 +507,8 @@ void CombinedUpdateRenderController::UpdateRenderThread() } } + eglGraphics->GetGlesInterface().ContextCreated(); + // Tell core it has a context mCore.ContextCreated(); @@ -538,19 +554,21 @@ void CombinedUpdateRenderController::UpdateRenderThread() // REPLACE SURFACE ////////////////////////////// - Integration::RenderSurface* newSurface = ShouldSurfaceBeReplaced(); + Dali::RenderSurfaceInterface* newSurface = ShouldSurfaceBeReplaced(); if( DALI_UNLIKELY( newSurface ) ) { LOG_UPDATE_RENDER_TRACE_FMT( "Replacing Surface" ); - // This is designed for replacing pixmap surfaces, but should work for window as well // we need to delete the surface and renderable (pixmap / window) // Then create a new pixmap/window and new surface // If the new surface has a different display connection, then the context will be lost - mAdaptorInterfaces.GetDisplayConnectionInterface().Initialize(); newSurface->InitializeGraphics(); - newSurface->ReplaceGraphicsSurface(); + newSurface->MakeContextCurrent(); + // TODO: ReplaceGraphicsSurface doesn't work, InitializeGraphics() + // already creates new surface window, the surface and the context. + // We probably don't need ReplaceGraphicsSurface at all. + // newSurface->ReplaceGraphicsSurface(); SurfaceReplaced(); } @@ -596,6 +614,7 @@ void CombinedUpdateRenderController::UpdateRenderThread() } // Check resize + bool surfaceResized = false; bool shouldSurfaceBeResized = ShouldSurfaceBeResized(); if( DALI_UNLIKELY( shouldSurfaceBeResized ) ) { @@ -603,6 +622,7 @@ void CombinedUpdateRenderController::UpdateRenderThread() { LOG_UPDATE_RENDER_TRACE_FMT( "Resizing Surface" ); SurfaceResized(); + surfaceResized = true; } } @@ -631,25 +651,59 @@ void CombinedUpdateRenderController::UpdateRenderThread() eglImpl.MakeContextCurrent( EGL_NO_SURFACE, eglImpl.GetContext() ); } + if( mFirstFrameAfterResume ) + { + // mFirstFrameAfterResume is set to true when the thread is resumed + // Let eglImplementation know the first frame after thread initialized or resumed. + eglImpl.SetFirstFrameAfterResume(); + mFirstFrameAfterResume = FALSE; + } + Integration::RenderStatus renderStatus; AddPerformanceMarker( PerformanceInterface::RENDER_START ); - mCore.Render( renderStatus, mForceClear ); - ////////////////////////////// - // DELETE SURFACE - ////////////////////////////// + mIsRenderingWindows = true; + + // Upload shared resources + mCore.PreRender( renderStatus, mForceClear, mUploadWithoutRendering ); - Integration::RenderSurface* deletedSurface = ShouldSurfaceBeDeleted(); - if( DALI_UNLIKELY( deletedSurface ) ) + if ( !mUploadWithoutRendering ) { - LOG_UPDATE_RENDER_TRACE_FMT( "Deleting Surface" ); + // Go through each window + WindowContainer windows; + mAdaptorInterfaces.GetWindowContainerInterface( windows ); + + for( auto&& window : windows ) + { + if ( window && !window->IsBeingDeleted() ) + { + Dali::Integration::Scene scene = window->GetScene(); + Dali::RenderSurfaceInterface* windowSurface = window->GetSurface(); + + if ( scene && windowSurface ) + { + windowSurface->InitializeGraphics(); + + // Render off-screen frame buffers first if any + mCore.RenderScene( scene, true ); + + // Switch to the EGL context of the surface + windowSurface->PreRender( surfaceResized ); // Switch GL context - mCore.SurfaceDeleted( deletedSurface ); + // Render the surface + mCore.RenderScene( scene, false ); - SurfaceDeleted(); + windowSurface->PostRender( false, false, surfaceResized ); // Swap Buffer + } + } + } } + mCore.PostRender( mUploadWithoutRendering ); + + mIsRenderingWindows = false; + AddPerformanceMarker( PerformanceInterface::RENDER_END ); mForceClear = false; @@ -734,14 +788,12 @@ bool CombinedUpdateRenderController::UpdateRenderReady( bool& useElapsedTime, bo ( mUpdateRenderThreadCanSleep && ! updateRequired && ! mPendingRequestUpdate ) ) && // Ensure we wait if we're supposed to be sleeping AND do not require another update ! mDestroyUpdateRenderThread && // Ensure we don't wait if the update-render-thread is supposed to be destroyed ! mNewSurface && // Ensure we don't wait if we need to replace the surface - ! mDeletedSurface && // Ensure we don't wait if we need to delete the surface ! mSurfaceResized ) // Ensure we don't wait if we need to resize the surface { LOG_UPDATE_RENDER( "WAIT: mUpdateRenderRunCount: %d", mUpdateRenderRunCount ); LOG_UPDATE_RENDER( " mUpdateRenderThreadCanSleep: %d, updateRequired: %d, mPendingRequestUpdate: %d", mUpdateRenderThreadCanSleep, updateRequired, mPendingRequestUpdate ); LOG_UPDATE_RENDER( " mDestroyUpdateRenderThread: %d", mDestroyUpdateRenderThread ); LOG_UPDATE_RENDER( " mNewSurface: %d", mNewSurface ); - LOG_UPDATE_RENDER( " mDeletedSurface: %d", mDeletedSurface ); LOG_UPDATE_RENDER( " mSurfaceResized: %d", mSurfaceResized ); // Reset the time when the thread is waiting, so the sleep-until time for @@ -761,7 +813,6 @@ bool CombinedUpdateRenderController::UpdateRenderReady( bool& useElapsedTime, bo LOG_COUNTER_UPDATE_RENDER( "mUpdateRenderThreadCanSleep: %d, updateRequired: %d, mPendingRequestUpdate: %d", mUpdateRenderThreadCanSleep, updateRequired, mPendingRequestUpdate ); LOG_COUNTER_UPDATE_RENDER( "mDestroyUpdateRenderThread: %d", mDestroyUpdateRenderThread ); LOG_COUNTER_UPDATE_RENDER( "mNewSurface: %d", mNewSurface ); - LOG_COUNTER_UPDATE_RENDER( "mDeletedSurface: %d", mDeletedSurface ); LOG_COUNTER_UPDATE_RENDER( "mSurfaceResized: %d", mSurfaceResized ); mUseElapsedTimeAfterWait = FALSE; @@ -779,11 +830,11 @@ bool CombinedUpdateRenderController::UpdateRenderReady( bool& useElapsedTime, bo return ! mDestroyUpdateRenderThread; } -Integration::RenderSurface* CombinedUpdateRenderController::ShouldSurfaceBeReplaced() +Dali::RenderSurfaceInterface* CombinedUpdateRenderController::ShouldSurfaceBeReplaced() { ConditionalWait::ScopedLock lock( mUpdateRenderThreadWaitCondition ); - Integration::RenderSurface* newSurface = mNewSurface; + Dali::RenderSurfaceInterface* newSurface = mNewSurface; mNewSurface = NULL; return newSurface; @@ -795,22 +846,6 @@ void CombinedUpdateRenderController::SurfaceReplaced() sem_post( &mEventThreadSemaphore ); } -Integration::RenderSurface* CombinedUpdateRenderController::ShouldSurfaceBeDeleted() -{ - ConditionalWait::ScopedLock lock( mUpdateRenderThreadWaitCondition ); - - Integration::RenderSurface* deletedSurface = mDeletedSurface; - mDeletedSurface = NULL; - - return deletedSurface; -} - -void CombinedUpdateRenderController::SurfaceDeleted() -{ - // Just increment the semaphore - sem_post( &mEventThreadSemaphore ); -} - bool CombinedUpdateRenderController::ShouldSurfaceBeResized() { ConditionalWait::ScopedLock lock( mUpdateRenderThreadWaitCondition ); @@ -833,6 +868,11 @@ void CombinedUpdateRenderController::NotifyThreadInitialised() sem_post( &mEventThreadSemaphore ); } +void CombinedUpdateRenderController::NotifyGraphicsInitialised() +{ + sem_post( &mGraphicsInitializeSemaphore ); +} + void CombinedUpdateRenderController::AddPerformanceMarker( PerformanceInterface::MarkerType type ) { if( mPerformanceInterface ) @@ -867,8 +907,6 @@ void CombinedUpdateRenderController::PostRenderWaitForCompletion() ConditionalWait::ScopedLock lock( mUpdateRenderThreadWaitCondition ); while( mPostRendering && ! mNewSurface && // We should NOT wait if we're replacing the surface - ! mDeletedSurface && // We should NOT wait if we're deleting the surface - ! mSurfaceResized && // We should NOT wait if we're resizing the surface ! mDestroyUpdateRenderThread ) { mUpdateRenderThreadWaitCondition.Wait( lock );