From 472216da2d3e88472df3594cbc9eccc6d6b1b44b Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 13 Apr 2015 15:52:51 +0200 Subject: [PATCH] Defer Q(OpenGL|Raster)Window updates when non-exposed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is similar to how widgets work. On platforms like OS X this becomes essential since in non-exposed state SwapBuffers does not block so continuing to update continuously leads to undesirable effects. Task-number: QTBUG-45524 Change-Id: I80f4c00b218561b9e62c3cad1e66f61f4debd4af Reviewed-by: Jørgen Lind --- src/gui/kernel/qpaintdevicewindow.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/gui/kernel/qpaintdevicewindow.cpp b/src/gui/kernel/qpaintdevicewindow.cpp index b32ab3b34d..ff661d017d 100644 --- a/src/gui/kernel/qpaintdevicewindow.cpp +++ b/src/gui/kernel/qpaintdevicewindow.cpp @@ -60,6 +60,9 @@ QT_BEGIN_NAMESPACE \note Subsequent calls to this function before the next paint event will get ignored. + + \note For non-exposed windows the update is deferred until the + window becomes exposed again. */ void QPaintDeviceWindow::update() { @@ -70,26 +73,34 @@ void QPaintDeviceWindow::update() Marks the \a rect of the window as dirty and schedules a repaint. \note Subsequent calls to this function before the next paint - event will get ignored. + event will get ignored, but \a rect is added to the region to update. + + \note For non-exposed windows the update is deferred until the + window becomes exposed again. */ void QPaintDeviceWindow::update(const QRect &rect) { Q_D(QPaintDeviceWindow); d->dirtyRegion += rect; - requestUpdate(); + if (isExposed()) + requestUpdate(); } /*! Marks the \a region of the window as dirty and schedules a repaint. \note Subsequent calls to this function before the next paint - event will get ignored. + event will get ignored, but \a region is added to the region to update. + + \note For non-exposed windows the update is deferred until the + window becomes exposed again. */ void QPaintDeviceWindow::update(const QRegion ®ion) { Q_D(QPaintDeviceWindow); d->dirtyRegion += region; - requestUpdate(); + if (isExposed()) + requestUpdate(); } /*! @@ -168,6 +179,9 @@ void QPaintDeviceWindow::exposeEvent(QExposeEvent *exposeEvent) // sometimes relative to the parent, depending on the platform plugin. // We require local coords here. d->doFlush(QRect(QPoint(0, 0), size())); + } else if (!d->dirtyRegion.isEmpty()) { + // Updates while non-exposed were ignored. Schedule an update now. + requestUpdate(); } }