/*
- * 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.
// EXTERNAL INCLUDES
#include <errno.h>
#include <dali/integration-api/platform-abstraction.h>
+#include <unistd.h>
// INTERNAL INCLUDES
-#include <dali/integration-api/trigger-event-factory.h>
-#include <dali/internal/adaptor/common/combined-update-render-controller-debug.h>
-#include <dali/internal/system/common/environment-options.h>
-#include <dali/internal/system/common/time-service.h>
-#include <dali/internal/adaptor/common/adaptor-internal-services.h>
+#include <dali/integration-api/adaptor-framework/trigger-event-factory.h>
#include <dali/devel-api/adaptor-framework/thread-settings.h>
+#include <dali/internal/adaptor/common/adaptor-internal-services.h>
+#include <dali/internal/adaptor/common/combined-update-render-controller-debug.h>
#include <dali/internal/graphics/gles/egl-graphics.h>
#include <dali/internal/graphics/gles/egl-implementation.h>
#include <dali/internal/graphics/common/graphics-interface.h>
+#include <dali/internal/system/common/environment-options.h>
+#include <dali/internal/system/common/time-service.h>
+#include <dali/internal/window-system/common/window-impl.h>
namespace Dali
{
: mFpsTracker( environmentOptions ),
mUpdateStatusLogger( environmentOptions ),
mEventThreadSemaphore(),
+ mGraphicsInitializeSemaphore(),
mUpdateRenderThreadWaitCondition(),
mAdaptorInterfaces( adaptorInterfaces ),
mPerformanceInterface( adaptorInterfaces.GetPerformanceInterface() ),
mNewSurface( NULL ),
mPostRendering( FALSE ),
mSurfaceResized( FALSE ),
- mForceClear( FALSE )
+ mForceClear( FALSE ),
+ mUploadWithoutRendering( FALSE ),
+ mFirstFrameAfterResume( FALSE ),
+ mIsRenderingWindows( false )
{
LOG_EVENT_TRACE;
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()
sem_wait( &mEventThreadSemaphore );
}
- Integration::RenderSurface* currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface();
+ Dali::RenderSurfaceInterface* currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface();
if( currentSurface )
{
currentSurface->StartRender();
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" );
}
{
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" );
}
LOG_EVENT_TRACE;
// Stop Rendering and the Update/Render Thread
- Integration::RenderSurface* currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface();
+ Dali::RenderSurfaceInterface* currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface();
if( currentSurface )
{
currentSurface->StopRender();
{
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 )
LOG_EVENT_TRACE;
// Run Update/Render once
- RunUpdateRenderThread( ONCE, false /* No animation progression */ );
+ RunUpdateRenderThread( ONCE, AnimationProgression::NONE, updateMode );
}
}
{
LOG_EVENT_TRACE;
- // Set the ThreadSyncronizationInterface on the new surface
- newSurface->SetThreadSynchronization( *this );
+ if( mUpdateRenderThread )
+ {
+ // Set the ThreadSyncronizationInterface on the new surface
+ newSurface->SetThreadSynchronization( *this );
- LOG_EVENT( "Starting to replace the surface, event-thread blocked" );
+ LOG_EVENT( "Starting to replace 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 replace the surface now
- mNewSurface = newSurface;
- mUpdateRenderThreadWaitCondition.Notify( lock );
+ // Start replacing the surface.
+ {
+ ConditionalWait::ScopedLock lock( mUpdateRenderThreadWaitCondition );
+ mPostRendering = FALSE; // Clear the post-rendering flag as Update/Render thread will replace the surface now
+ mNewSurface = newSurface;
+ mUpdateRenderThreadWaitCondition.Notify( lock );
+ }
+
+ // Wait until the surface has been replaced
+ sem_wait( &mEventThreadSemaphore );
+
+ LOG_EVENT( "Surface replaced, event-thread continuing" );
}
+}
- // Wait until the surface has been replaced
- sem_wait( &mEventThreadSemaphore );
+void CombinedUpdateRenderController::WaitForGraphicsInitialization()
+{
+ LOG_EVENT_TRACE;
- LOG_EVENT( "Surface replaced, event-thread continuing" );
+ if( mUpdateRenderThread )
+ {
+ LOG_EVENT( "Waiting for graphics initialisation, event-thread blocked" );
+
+ // Wait until the graphics has been initialised
+ sem_wait( &mGraphicsInitializeSemaphore );
+
+ LOG_EVENT( "graphics initialised, event-thread continuing" );
+ }
}
void CombinedUpdateRenderController::ResizeSurface()
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 );
}
Dali::DisplayConnection& displayConnection = mAdaptorInterfaces.GetDisplayConnectionInterface();
displayConnection.Initialize();
+ // EGL has been initialised at this point
+ NotifyGraphicsInitialised();
+
RenderSurfaceInterface* currentSurface = nullptr;
GraphicsInterface& graphics = mAdaptorInterfaces.GetGraphicsInterface();
}
}
+ eglGraphics->GetGlesInterface().ContextCreated();
+
// Tell core it has a context
mCore.ContextCreated();
// 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();
}
}
// Check resize
+ bool surfaceResized = false;
bool shouldSurfaceBeResized = ShouldSurfaceBeResized();
if( DALI_UNLIKELY( shouldSurfaceBeResized ) )
{
{
LOG_UPDATE_RENDER_TRACE_FMT( "Resizing Surface" );
SurfaceResized();
+ surfaceResized = true;
}
}
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 );
+
+ mIsRenderingWindows = true;
+
+ // Upload shared resources
+ mCore.PreRender( renderStatus, mForceClear, mUploadWithoutRendering );
+
+ if ( !mUploadWithoutRendering )
+ {
+ // 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
+
+ // Render the surface
+ mCore.RenderScene( scene, false );
+
+ windowSurface->PostRender( false, false, surfaceResized ); // Swap Buffer
+ }
+ }
+ }
+ }
+
+ mCore.PostRender( mUploadWithoutRendering );
+
+ mIsRenderingWindows = false;
+
AddPerformanceMarker( PerformanceInterface::RENDER_END );
mForceClear = false;
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;
sem_post( &mEventThreadSemaphore );
}
+void CombinedUpdateRenderController::NotifyGraphicsInitialised()
+{
+ sem_post( &mGraphicsInitializeSemaphore );
+}
+
void CombinedUpdateRenderController::AddPerformanceMarker( PerformanceInterface::MarkerType type )
{
if( mPerformanceInterface )
ConditionalWait::ScopedLock lock( mUpdateRenderThreadWaitCondition );
while( mPostRendering &&
! mNewSurface && // We should NOT wait if we're replacing the surface
- ! mSurfaceResized && // We should NOT wait if we're resizing the surface
! mDestroyUpdateRenderThread )
{
mUpdateRenderThreadWaitCondition.Wait( lock );