diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-07-02 00:50:03 (GMT) |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-07-02 00:50:03 (GMT) |
commit | 6c9647f6673fd5738001c5bbe416b116442fbc41 (patch) | |
tree | 9ad13baed686c6db46b793ab91e2634bfdad7bf2 | |
parent | 0b5c4c4352d0419113cf152b7ae5bbee5a45fd5c (diff) | |
download | Qt-6c9647f6673fd5738001c5bbe416b116442fbc41.zip Qt-6c9647f6673fd5738001c5bbe416b116442fbc41.tar.gz Qt-6c9647f6673fd5738001c5bbe416b116442fbc41.tar.bz2 |
OpenVG: short-cut clipping for QPainterPath's that are just rects
If the QPainterPath contains a structure that looks like a simple
rectangle, then use the faster clip(QRect) function instead of a
full VGPath-based render call.
Task-number: QT-64
Reviewed-by: trustme
-rw-r--r-- | src/openvg/qpaintengine_vg.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/openvg/qpaintengine_vg.cpp b/src/openvg/qpaintengine_vg.cpp index 48953ac..7a962e4 100644 --- a/src/openvg/qpaintengine_vg.cpp +++ b/src/openvg/qpaintengine_vg.cpp @@ -1802,11 +1802,61 @@ void QVGPaintEngine::clip(const QRegion ®ion, Qt::ClipOperation op) } } +#if !defined(QVG_NO_RENDER_TO_MASK) + +// Copied from qpathclipper.cpp. +static bool qt_vg_pathToRect(const QPainterPath &path, QRectF *rect) +{ + if (path.elementCount() != 5) + return false; + + const bool mightBeRect = path.elementAt(0).isMoveTo() + && path.elementAt(1).isLineTo() + && path.elementAt(2).isLineTo() + && path.elementAt(3).isLineTo() + && path.elementAt(4).isLineTo(); + + if (!mightBeRect) + return false; + + const qreal x1 = path.elementAt(0).x; + const qreal y1 = path.elementAt(0).y; + + const qreal x2 = path.elementAt(1).x; + const qreal y2 = path.elementAt(2).y; + + if (path.elementAt(1).y != y1) + return false; + + if (path.elementAt(2).x != x2) + return false; + + if (path.elementAt(3).x != x1 || path.elementAt(3).y != y2) + return false; + + if (path.elementAt(4).x != x1 || path.elementAt(4).y != y1) + return false; + + if (rect) + *rect = QRectF(QPointF(x1, y1), QPointF(x2, y2)); + + return true; +} + +#endif + void QVGPaintEngine::clip(const QPainterPath &path, Qt::ClipOperation op) { #if !defined(QVG_NO_RENDER_TO_MASK) Q_D(QVGPaintEngine); + // If the path is a simple rectangle, then use clip(QRect) instead. + QRectF simpleRect; + if (qt_vg_pathToRect(path, &simpleRect)) { + clip(simpleRect.toRect(), op); + return; + } + d->dirty |= QPaintEngine::DirtyClipRegion; if (op == Qt::NoClip) { |