diff options
author | Samuel Rødal <samuel.rodal@nokia.com> | 2011-02-03 16:06:15 (GMT) |
---|---|---|
committer | Samuel Rødal <samuel.rodal@nokia.com> | 2011-02-03 17:01:58 (GMT) |
commit | 30dee4f433d2426ce2dc0bccda8e62683380a1c4 (patch) | |
tree | b19ee21df2a11dd6463ac93393eec359fa5eae32 /src/gui | |
parent | 68f78ba6be29b839433d924b5dc348d6d94b3d43 (diff) | |
download | Qt-30dee4f433d2426ce2dc0bccda8e62683380a1c4.zip Qt-30dee4f433d2426ce2dc0bccda8e62683380a1c4.tar.gz Qt-30dee4f433d2426ce2dc0bccda8e62683380a1c4.tar.bz2 |
Improve performance of partial updates in raster window surface on X11.
An XSync is needed to prevent the raster engine from writing to the
shared memory raster backbuffer at the same time the X server reads from
it. However, instead of doing the sync right after telling X to blit, we
can do it right before we start writing to it with raster. At this point
there will on average be less processing heavy X commands in the command
queue, and we thus spend less time blocking the GUI thread.
Measured frame rate improvement of 20 - 60 % in an update stress testing
the performance of partial updates.
Idea-from: Olivier Goffart
Reviewed-by: Bjørn Erik Nilsen
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/painting/qwindowsurface_raster.cpp | 29 | ||||
-rw-r--r-- | src/gui/painting/qwindowsurface_raster_p.h | 3 |
2 files changed, 30 insertions, 2 deletions
diff --git a/src/gui/painting/qwindowsurface_raster.cpp b/src/gui/painting/qwindowsurface_raster.cpp index 843c9ff..419518ac 100644 --- a/src/gui/painting/qwindowsurface_raster.cpp +++ b/src/gui/painting/qwindowsurface_raster.cpp @@ -78,6 +78,9 @@ public: #ifdef Q_WS_X11 GC gc; +#ifndef QT_NO_MITSHM + uint needsSync : 1; +#endif #ifndef QT_NO_XRENDER uint translucentBackground : 1; #endif @@ -94,6 +97,9 @@ QRasterWindowSurface::QRasterWindowSurface(QWidget *window, bool setDefaultSurfa d_ptr->translucentBackground = X11->use_xrender && window->x11Info().depth() == 32; #endif +#ifndef QT_NO_MITHSM + d_ptr->needsSync = false; +#endif #endif d_ptr->image = 0; d_ptr->inSetGeometry = false; @@ -116,8 +122,23 @@ QPaintDevice *QRasterWindowSurface::paintDevice() return &d_ptr->image->image; } +#if defined(Q_WS_X11) && !defined(QT_NO_MITSHM) +void QRasterWindowSurface::syncX() +{ + // delay writing to the backbuffer until we know for sure X is done reading from it + if (d_ptr->needsSync) { + XSync(X11->display, false); + d_ptr->needsSync = false; + } +} +#endif + void QRasterWindowSurface::beginPaint(const QRegion &rgn) { +#if defined(Q_WS_X11) && !defined(QT_NO_MITSHM) + syncX(); +#endif + #if (defined(Q_WS_X11) && !defined(QT_NO_XRENDER)) || (defined(Q_WS_WIN) && !defined(Q_WS_WINCE)) if (!qt_widget_private(window())->isOpaque && window()->testAttribute(Qt::WA_TranslucentBackground)) { #if defined(Q_WS_WIN) && !defined(Q_WS_WINCE) @@ -217,13 +238,13 @@ void QRasterWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoi if (d_ptr->image->xshmpm) { XCopyArea(X11->display, d_ptr->image->xshmpm, widget->handle(), d_ptr->gc, br.x(), br.y(), br.width(), br.height(), wbr.x(), wbr.y()); - XSync(X11->display, False); + d_ptr->needsSync = true; } else if (d_ptr->image->xshmimg) { const QImage &src = d->image->image; br = br.intersected(src.rect()); XShmPutImage(X11->display, widget->handle(), d_ptr->gc, d_ptr->image->xshmimg, br.x(), br.y(), wbr.x(), wbr.y(), br.width(), br.height(), False); - XSync(X11->display, False); + d_ptr->needsSync = true; } else #endif { @@ -392,6 +413,10 @@ bool QRasterWindowSurface::scroll(const QRegion &area, int dx, int dy) if (!d->image || d->image->image.isNull()) return false; +#if defined(Q_WS_X11) && !defined(QT_NO_MITSHM) + syncX(); +#endif + const QVector<QRect> rects = area.rects(); for (int i = 0; i < rects.size(); ++i) qt_scrollRectInImage(d->image->image, rects.at(i), QPoint(dx, dy)); diff --git a/src/gui/painting/qwindowsurface_raster_p.h b/src/gui/painting/qwindowsurface_raster_p.h index b6e61e1..903810b 100644 --- a/src/gui/painting/qwindowsurface_raster_p.h +++ b/src/gui/painting/qwindowsurface_raster_p.h @@ -107,6 +107,9 @@ public: bool scroll(const QRegion &area, int dx, int dy); private: +#if defined(Q_WS_X11) && !defined(QT_NO_MITSHM) + void syncX(); +#endif void prepareBuffer(QImage::Format format, QWidget *widget); Q_DECLARE_PRIVATE(QRasterWindowSurface) QScopedPointer<QRasterWindowSurfacePrivate> d_ptr; |