Reduce flushes with repaint() when GL-based compositing is active

Task-number: QTBUG-49655
Change-Id: I7a5d08f681a7d87709aac745154730764040e922
Reviewed-by: Paul Olav Tvete <paul.tvete@theqtcompany.com>
bb10
Laszlo Agocs 2015-12-01 12:31:14 +01:00 committed by Simon Hausmann
parent 8f74fe1b66
commit 1b61390856
4 changed files with 27 additions and 0 deletions

View File

@ -50,6 +50,7 @@
#include <qpa/qplatformwindow.h>
#include <QtCore/private/qobject_p.h>
#include <QtCore/qelapsedtimer.h>
#include <QtGui/QIcon>
QT_BEGIN_NAMESPACE
@ -187,6 +188,7 @@ public:
#endif
bool compositing;
QElapsedTimer lastComposeTime;
};

View File

@ -301,6 +301,8 @@ void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion &regi
return;
}
QWindowPrivate::get(window)->lastComposeTime.start();
QOpenGLFunctions *funcs = context->functions();
funcs->glViewport(0, 0, window->width() * window->devicePixelRatio(), window->height() * window->devicePixelRatio());
funcs->glClearColor(0, 0, 0, translucentBackground ? 0 : 1);

View File

@ -35,6 +35,7 @@
#include <QtGui/QWindow>
#include <QtGui/QPainter>
#include <qpa/qplatformbackingstore.h>
#include <private/qwindow_p.h>
#include "qopenglcompositorbackingstore_p.h"
#include "qopenglcompositor_p.h"
@ -198,6 +199,8 @@ void QOpenGLCompositorBackingStore::composeAndFlush(QWindow *window, const QRegi
dstCtx->makeCurrent(dstWin);
QWindowPrivate::get(window)->lastComposeTime.start();
m_textures->clear();
for (int i = 0; i < textures->count(); ++i)
m_textures->appendTexture(textures->source(i), textures->textureId(i), textures->geometry(i),

View File

@ -448,6 +448,26 @@ void QWidgetBackingStore::sendUpdateRequest(QWidget *widget, UpdateTime updateTi
if (!widget)
return;
#ifndef QT_NO_OPENGL
// Having every repaint() leading to a sync/flush is bad as it causes
// compositing and waiting for vsync each and every time. Change to
// UpdateLater, except for approx. once per frame to prevent starvation in
// case the control does not get back to the event loop.
QWidget *w = widget->window();
if (updateTime == UpdateNow && w && w->windowHandle() && QWindowPrivate::get(w->windowHandle())->compositing) {
int refresh = 60;
QScreen *ws = w->windowHandle()->screen();
if (ws)
refresh = ws->refreshRate();
QWindowPrivate *wd = QWindowPrivate::get(w->windowHandle());
if (wd->lastComposeTime.isValid()) {
const qint64 elapsed = wd->lastComposeTime.elapsed();
if (elapsed <= qint64(1000.0f / refresh))
updateTime = UpdateLater;
}
}
#endif
switch (updateTime) {
case UpdateLater:
updateRequestSent = true;