From 5138fada0b9ce3968b23ec11df5f0d4e67544c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 18 Jul 2017 16:52:08 +0200 Subject: Fix QHighDpi::fromNativeLocalExposedRegion rounding errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calling bottom/right/bottomRight on a QRect is discouraged, as it does not give the true bottom-right corner of the rectangle, instead giving a point one unit to the left and top of the true bottom right. Dividing this point by a scale factor of e.g. 2, and then using qCeil on the bottom right x and y coordinates would result in a pointRegion that was 1x1 * scaleFactor larger than it should, manifesting as rendering issues at later stages. We can get away from the whole problem by initially converting the QRect to a QRectF, and basing the pointRegion's rect on the scaled size instead of bottom-right coordinates. Change-Id: I4d4895660655cfa8749c93c7d2573ae79cd7898b Reviewed-by: Simon Hausmann Reviewed-by: Morten Johan Sørvig Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qhighdpiscaling_p.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h index 32c8f07dc0..0a060a2d2c 100644 --- a/src/gui/kernel/qhighdpiscaling_p.h +++ b/src/gui/kernel/qhighdpiscaling_p.h @@ -398,11 +398,11 @@ inline QRegion fromNativeLocalExposedRegion(const QRegion &pixelRegion, const QW const qreal scaleFactor = QHighDpiScaling::factor(window); QRegion pointRegion; - for (const QRect &rect : pixelRegion) { - const QPointF topLeftP = QPointF(rect.topLeft()) / scaleFactor; - const QPointF bottomRightP = QPointF(rect.bottomRight()) / scaleFactor; + for (const QRectF &rect : pixelRegion) { + const QPointF topLeftP = rect.topLeft() / scaleFactor; + const QSizeF sizeP = rect.size() / scaleFactor; pointRegion += QRect(QPoint(qFloor(topLeftP.x()), qFloor(topLeftP.y())), - QPoint(qCeil(bottomRightP.x()), qCeil(bottomRightP.y()))); + QSize(qCeil(sizeP.width()), qCeil(sizeP.height()))); } return pointRegion; } -- cgit v1.2.3