Redo timing of next painting with vsync used, try harder not to miss

every other sync just by a small time.


svn path=/trunk/KDE/kdebase/workspace/; revision=806443
This commit is contained in:
Luboš Luňák 2008-05-11 12:03:42 +00:00
parent 8eb8c8c08f
commit 9bd87cb271
2 changed files with 18 additions and 13 deletions

View file

@ -175,8 +175,7 @@ void Workspace::setupCompositing()
if( rate <= 0 )
rate = 50;
// QTimer gives us 1msec (1000Hz) at best, so we ignore anything higher;
// however, since compositing is limited to no more than once per 5msec,
// 200Hz to 1000Hz are effectively identical
// however, additional throttling makes prevents very high rates from taking place anyway
else if( rate > 1000 )
rate = 1000;
kDebug( 1212 ) << "Refresh rate " << rate << "Hz";
@ -318,15 +317,12 @@ void Workspace::performCompositing()
// clear all repaints, so that post-pass can add repaints for the next repaint
repaints_region = QRegion();
scene->paint( repaints, windows );
if( scene->waitSyncAvailable() && options->glVSync )
{ // if we're using vsync, then time the next paint pass to
// before the next available sync
int paintTime = ( lastCompositePaint.elapsed() % compositeRate ) +
( compositeRate / 2 );
if( paintTime >= compositeRate )
compositeTimer.start( paintTime );
else if( paintTime < compositeRate )
compositeTimer.start( compositeRate - paintTime );
if( scene->waitSyncAvailable())
{
// if vsync is used, schedule the next repaint slightly in advance of the next sync,
// so that there is still time for the drawing to take place
int untilNextSync = compositeRate - ( lastCompositePaint.elapsed() % compositeRate );
compositeTimer.start( qMax( 1, untilNextSync - 10 )); // 10 ms in advance - TODO maybe less?
}
lastCompositePaint.start();
#endif

View file

@ -145,7 +145,16 @@ SceneOpenGL::SceneOpenGL( Workspace* ws )
if( db )
glDrawBuffer( GL_BACK );
// Check whether certain features are supported
has_waitSync = glXGetVideoSync ? true : false;
has_waitSync = false;
if( glXGetVideoSync && glXIsDirect( display(), ctxbuffer ) && options->glVSync )
{
unsigned int sync;
if( glXGetVideoSync( &sync ) == 0 )
{
if( glXWaitVideoSync( 1, 0, &sync ) == 0 )
has_waitSync = true;
}
}
// OpenGL scene setup
glMatrixMode( GL_PROJECTION );
@ -625,7 +634,7 @@ void SceneOpenGL::paint( QRegion damage, ToplevelList toplevels )
// wait for vblank signal before painting
void SceneOpenGL::waitSync()
{ // NOTE that vsync has no effect with indirect rendering
if( waitSyncAvailable() && options->glVSync )
if( waitSyncAvailable())
{
unsigned int sync;