From 5f198584e206cb8ab85d0474ce19d0faabce9468 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 11 Aug 2020 15:34:48 +0200 Subject: Define inverted QRects consistently Changes the definition of invalid QRects to be more consistent. This simplifies the logic, and makes it possible for us to fix normalized() so dimensions don't change. The actual API is not changed except for inverted rects. Only one use-case for the old normalized() function existed, and has been reimplemented as QRect::span(). Fixes: QTBUG-22934 Change-Id: I29dad2952dc6c8e84a6d931898dc7e43d66780f3 Reviewed-by: hjk Reviewed-by: Lars Knoll --- src/gui/painting/qpaintengine_raster.cpp | 38 +++----------------------------- 1 file changed, 3 insertions(+), 35 deletions(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index f34b4bb9a2..781888dd5b 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -271,35 +271,6 @@ static void qt_debug_path(const QPainterPath &path) } #endif -// QRect::normalized() will change the width/height of the rectangle due to -// its incusive-integer definition of left/right vs width. This is not -// something we want to change in QRect as that would potentially introduce -// regressions all over the place, so we implement a straightforward -// normalized here. QRectF already does this, so QRectF::normalized() is ok to -// use. -static QRect qrect_normalized(const QRect &rect) -{ - int x, y, w, h; - if (Q_UNLIKELY(rect.width() < 0)) { - x = rect.x() + rect.width(); - w = -rect.width(); - } else { - x = rect.x(); - w = rect.width(); - } - - if (Q_UNLIKELY(rect.height() < 0)) { - y = rect.y() + rect.height(); - h = -rect.height(); - } else { - y = rect.y(); - h = rect.height(); - } - - return QRect(x, y, w, h); -} - - QRasterPaintEnginePrivate::QRasterPaintEnginePrivate() : QPaintEngineExPrivate(), cachedLines(0) @@ -1320,9 +1291,7 @@ void QRasterPaintEngine::clip(const QRect &rect, Qt::ClipOperation op) bool QRasterPaintEngine::setClipRectInDeviceCoords(const QRect &r, Qt::ClipOperation op) { Q_D(QRasterPaintEngine); - // normalize before using the & operator which uses QRect::normalize() - // internally which will give us the wrong values. - QRect clipRect = qrect_normalized(r) & d->deviceRect; + QRect clipRect = r & d->deviceRect; QRasterPaintEngineState *s = state(); if (op == Qt::ReplaceClip || s->clip == nullptr) { @@ -1557,7 +1526,7 @@ void QRasterPaintEngine::drawRects(const QRect *rects, int rectCount) int offset_x = int(s->matrix.dx()); int offset_y = int(s->matrix.dy()); while (r < lastRect) { - QRect rect = qrect_normalized(*r); + QRect rect = r->normalized(); QRect rr = rect.translated(offset_x, offset_y); fillRect_normalized(rr, &s->brushData, d); ++r; @@ -3006,8 +2975,8 @@ bool QRasterPaintEnginePrivate::isUnclipped(const QRect &rect, Q_Q(const QRasterPaintEngine); const QRasterPaintEngineState *s = q->state(); const QClipData *cl = clip(); + QRect r = rect.normalized(); if (!cl) { - QRect r = qrect_normalized(rect); // inline contains() for performance (we know the rects are normalized) const QRect &r1 = deviceRect; return (r.left() >= r1.left() && r.right() <= r1.right() @@ -3022,7 +2991,6 @@ bool QRasterPaintEnginePrivate::isUnclipped(const QRect &rect, if (s->flags.antialiased) ++penWidth; - QRect r = qrect_normalized(rect); if (penWidth > 0) { r.setX(r.x() - penWidth); r.setY(r.y() - penWidth); -- cgit v1.2.3