#include <errno.h>
#include <dali/integration-api/platform-abstraction.h>
#include <unistd.h>
+#include "dali/public-api/common/dali-common.h"
// INTERNAL INCLUDES
#include <dali/integration-api/adaptor-framework/trigger-event-factory.h>
// EVENT THREAD
///////////////////////////////////////////////////////////////////////////////////////////////////
-CombinedUpdateRenderController::CombinedUpdateRenderController( AdaptorInternalServices& adaptorInterfaces, const EnvironmentOptions& environmentOptions )
+CombinedUpdateRenderController::CombinedUpdateRenderController( AdaptorInternalServices& adaptorInterfaces, const EnvironmentOptions& environmentOptions, ThreadMode threadMode )
: mFpsTracker( environmentOptions ),
mUpdateStatusLogger( environmentOptions ),
- mEventThreadSemaphore(),
- mGraphicsInitializeSemaphore(),
+ mEventThreadSemaphore(0),
+ mSurfaceSemaphore(0),
mUpdateRenderThreadWaitCondition(),
mAdaptorInterfaces( adaptorInterfaces ),
mPerformanceInterface( adaptorInterfaces.GetPerformanceInterface() ),
mDefaultHalfFrameNanoseconds( 0u ),
mUpdateRequestCount( 0u ),
mRunning( FALSE ),
+ mThreadMode( threadMode ),
mUpdateRenderRunCount( 0 ),
mDestroyUpdateRenderThread( FALSE ),
mUpdateRenderThreadCanSleep( FALSE ),
}
mSleepTrigger = TriggerEventFactory::CreateTriggerEvent( MakeCallback( this, &CombinedUpdateRenderController::ProcessSleepRequest ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER );
-
- // 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()
DALI_ASSERT_ALWAYS( ! mUpdateRenderThread );
// Create Update/Render Thread
+ ConditionalWait::ScopedLock lock(mGraphicsInitializeWait);
mUpdateRenderThread = new pthread_t();
int error = pthread_create( mUpdateRenderThread, NULL, InternalUpdateRenderThreadEntryFunc, this );
DALI_ASSERT_ALWAYS( !error && "Return code from pthread_create() when creating UpdateRenderThread" );
// Wait until all threads created in Initialise are up and running
for( unsigned int i = 0; i < CREATED_THREAD_COUNT; ++i )
{
- sem_wait( &mEventThreadSemaphore );
- }
-
- Dali::RenderSurfaceInterface* currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface();
- if( currentSurface )
- {
- currentSurface->StartRender();
+ mEventThreadSemaphore.Acquire();
}
mRunning = TRUE;
RunUpdateRenderThread( CONTINUOUS, AnimationProgression::NONE, UpdateMode::NORMAL );
+ Dali::RenderSurfaceInterface* currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface();
+ if( currentSurface )
+ {
+ currentSurface->StartRender();
+ }
+
DALI_LOG_RELEASE_INFO( "CombinedUpdateRenderController::Start\n" );
}
++mUpdateRequestCount;
}
- if( IsUpdateRenderThreadPaused() )
+ if( IsUpdateRenderThreadPaused() || updateMode == UpdateMode::FORCE_RENDER )
{
LOG_EVENT_TRACE;
}
// Wait until the surface has been replaced
- sem_wait( &mEventThreadSemaphore );
+ mSurfaceSemaphore.Acquire();
LOG_EVENT( "Surface replaced, event-thread continuing" );
}
}
// Wait until the surface has been deleted
- sem_wait( &mEventThreadSemaphore );
+ mSurfaceSemaphore.Acquire();
LOG_EVENT( "Surface deleted, event-thread continuing" );
}
void CombinedUpdateRenderController::WaitForGraphicsInitialization()
{
+ ConditionalWait::ScopedLock lk(mGraphicsInitializeWait);
LOG_EVENT_TRACE;
if( mUpdateRenderThread )
LOG_EVENT( "Waiting for graphics initialisation, event-thread blocked" );
// Wait until the graphics has been initialised
- sem_wait( &mGraphicsInitializeSemaphore );
+ mGraphicsInitializeWait.Wait(lk);
LOG_EVENT( "graphics initialised, event-thread continuing" );
}
void CombinedUpdateRenderController::RunUpdateRenderThread( int numberOfCycles, AnimationProgression animationProgression, UpdateMode updateMode )
{
ConditionalWait::ScopedLock lock( mUpdateRenderThreadWaitCondition );
- mUpdateRenderRunCount = numberOfCycles;
+
+ switch( mThreadMode )
+ {
+ case ThreadMode::NORMAL:
+ {
+ mUpdateRenderRunCount = numberOfCycles;
+ mUseElapsedTimeAfterWait = ( animationProgression == AnimationProgression::USE_ELAPSED_TIME );
+ break;
+ }
+ case ThreadMode::RUN_IF_REQUESTED:
+ {
+ if( updateMode != UpdateMode::FORCE_RENDER )
+ {
+ // Render only if the update mode is FORCE_RENDER which means the application requests it.
+ // We don't want to awake the update thread.
+ return;
+ }
+
+ mUpdateRenderRunCount++; // Increase the update request count
+ mUseElapsedTimeAfterWait = TRUE; // The elapsed time should be used. We want animations to proceed.
+ break;
+ }
+ }
+
mUpdateRenderThreadCanSleep = FALSE;
- mUseElapsedTimeAfterWait = ( animationProgression == AnimationProgression::USE_ELAPSED_TIME );
mUploadWithoutRendering = ( updateMode == UpdateMode::SKIP_RENDER );
LOG_COUNTER_EVENT( "mUpdateRenderRunCount: %d, mUseElapsedTimeAfterWait: %d", mUpdateRenderRunCount, mUseElapsedTimeAfterWait );
mUpdateRenderThreadWaitCondition.Notify( lock );
bool CombinedUpdateRenderController::IsUpdateRenderThreadPaused()
{
ConditionalWait::ScopedLock lock( mUpdateRenderThreadWaitCondition );
+
+ if( mThreadMode == ThreadMode::RUN_IF_REQUESTED )
+ {
+ return !mRunning || mUpdateRenderThreadCanSleep;
+ }
+
return ( mUpdateRenderRunCount != CONTINUOUS ) || // Report paused if NOT continuously running
mUpdateRenderThreadCanSleep; // Report paused if sleeping
}
}
}
- eglGraphics->GetGlesInterface().ContextCreated();
+ GlImplementation& gles = eglGraphics->GetGlesInterface();
+ gles.ContextCreated();
+ eglGraphics->SetGlesVersion( gles.GetGlesVersion() );
// Tell core it has a context
mCore.ContextCreated();
uint64_t currentFrameStartTime = 0;
TimeService::GetNanoseconds( currentFrameStartTime );
- const uint64_t timeSinceLastFrame = currentFrameStartTime - lastFrameTime;
+ uint64_t timeSinceLastFrame = currentFrameStartTime - lastFrameTime;
// Optional FPS Tracking when continuously rendering
if( useElapsedTime && mFpsTracker.Enabled() )
float frameDelta = 0.0f;
if( useElapsedTime )
{
+ if( mThreadMode == ThreadMode::RUN_IF_REQUESTED )
+ {
+ extraFramesDropped = 0;
+ while( timeSinceLastFrame >= mDefaultFrameDurationNanoseconds )
+ {
+ timeSinceLastFrame -= mDefaultFrameDurationNanoseconds;
+ extraFramesDropped++;
+ }
+ }
+
// If using the elapsed time, then calculate frameDelta as a multiple of mDefaultFrameDelta
noOfFramesSinceLastUpdate += extraFramesDropped;
if ( scene && windowSurface )
{
+ Integration::RenderStatus windowRenderStatus;
+
windowSurface->InitializeGraphics();
+ // clear previous frame damaged render items rects, buffer history is tracked on surface level
+ mDamagedRects.clear();
+
+ // Collect damage rects
+ mCore.PreRender( scene, mDamagedRects );
+
// Render off-screen frame buffers first if any
- mCore.RenderScene( scene, true );
+ mCore.RenderScene( windowRenderStatus, scene, true );
+
+ Rect<int> clippingRect; // Empty for fbo rendering
- // Switch to the EGL context of the surface
- windowSurface->PreRender( surfaceResized ); // Switch GL context
+ // Switch to the EGL context of the surface, merge damaged areas for previous frames
+ windowSurface->PreRender( surfaceResized, mDamagedRects, clippingRect ); // Switch GL context
+
+ if (clippingRect.IsEmpty())
+ {
+ mDamagedRects.clear();
+ }
// Render the surface
- mCore.RenderScene( scene, false );
+ mCore.RenderScene( windowRenderStatus, scene, false, clippingRect );
- windowSurface->PostRender( false, false, surfaceResized ); // Swap Buffer
+ if( windowRenderStatus.NeedsPostRender() )
+ {
+ windowSurface->PostRender( false, false, surfaceResized, mDamagedRects ); // Swap Buffer with damage
+ }
}
}
}
}
}
- // Inform core of context destruction & shutdown EGL
+ // Inform core of context destruction
mCore.ContextDestroyed();
- currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface();
- if( currentSurface )
+
+ WindowContainer windows;
+ mAdaptorInterfaces.GetWindowContainerInterface( windows );
+
+ // Destroy surfaces
+ for( auto&& window : windows )
{
- currentSurface->DestroySurface();
- currentSurface = nullptr;
+ Dali::RenderSurfaceInterface* surface = window->GetSurface();
+ surface->DestroySurface();
}
+ // Shutdown EGL
+ eglInterface->TerminateGles();
+
LOG_UPDATE_RENDER( "THREAD DESTROYED" );
// Uninstall the logging function
void CombinedUpdateRenderController::SurfaceReplaced()
{
// Just increment the semaphore
- sem_post( &mEventThreadSemaphore );
+ mSurfaceSemaphore.Release(1);
}
Dali::RenderSurfaceInterface* CombinedUpdateRenderController::ShouldSurfaceBeDeleted()
void CombinedUpdateRenderController::SurfaceDeleted()
{
// Just increment the semaphore
- sem_post( &mEventThreadSemaphore );
+ mSurfaceSemaphore.Release(1);
}
bool CombinedUpdateRenderController::ShouldSurfaceBeResized()
void CombinedUpdateRenderController::NotifyThreadInitialised()
{
// Just increment the semaphore
- sem_post( &mEventThreadSemaphore );
+ mEventThreadSemaphore.Release(1);
}
void CombinedUpdateRenderController::NotifyGraphicsInitialised()
{
- sem_post( &mGraphicsInitializeSemaphore );
+ mGraphicsInitializeWait.Notify();
}
void CombinedUpdateRenderController::AddPerformanceMarker( PerformanceInterface::MarkerType type )