From 73119e27b31e7d5b48e1cd3fcbe2f6edf049da5d Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Fri, 15 Oct 2021 12:14:28 +0200 Subject: Handle DPR in QPainter's drawing methods taking a brush parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The emulation paint engine is required not only for non-LogicalMode gradient brushes, but also for texture (pixmap/image) brushes with DPR != 1. fillRect(), strokePath() etc. would check for the former case, but not the latter. Fix by factoring out a common checking function. Pick-to: 6.2 5.15 Fixes: QTBUG-89101 Change-Id: I3cddf8a86a321de97b12c85a187069e77d2acea6 Reviewed-by: Morten Johan Sørvig --- src/gui/painting/qpainter.cpp | 66 ++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 35 deletions(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 83fc66c50d..e5caf0813b 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -180,6 +180,23 @@ static bool qt_painter_thread_test(int devType, int engineType, const char *what } #endif +static bool needsEmulation(const QBrush &brush) +{ + bool res = false; + + const QGradient *bg = brush.gradient(); + if (bg) { + res = (bg->coordinateMode() > QGradient::LogicalMode); + } else if (brush.style() == Qt::TexturePattern) { + if (qHasPixmapTexture(brush)) + res = !qFuzzyCompare(brush.texture().devicePixelRatio(), qreal(1.0)); + else + res = !qFuzzyCompare(brush.textureImage().devicePixelRatio(), qreal(1.0)); + } + + return res; +} + void QPainterPrivate::checkEmulation() { Q_ASSERT(extended); @@ -187,21 +204,12 @@ void QPainterPrivate::checkEmulation() if (state->bgMode == Qt::OpaqueMode) doEmulation = true; - const QGradient *bg = state->brush.gradient(); - if (bg && bg->coordinateMode() > QGradient::LogicalMode) + if (needsEmulation(state->brush)) doEmulation = true; - const QGradient *pg = qpen_brush(state->pen).gradient(); - if (pg && pg->coordinateMode() > QGradient::LogicalMode) + if (needsEmulation(qpen_brush(state->pen))) doEmulation = true; - if (state->brush.style() == Qt::TexturePattern) { - if (qHasPixmapTexture(state->brush)) - doEmulation |= !qFuzzyCompare(state->brush.texture().devicePixelRatio(), qreal(1.0)); - else - doEmulation |= !qFuzzyCompare(state->brush.textureImage().devicePixelRatio(), qreal(1.0)); - } - if (doEmulation && extended->flags() & QPaintEngineEx::DoNotEmulate) return; @@ -3083,12 +3091,9 @@ void QPainter::strokePath(const QPainterPath &path, const QPen &pen) if (path.isEmpty()) return; - if (d->extended) { - const QGradient *g = qpen_brush(pen).gradient(); - if (!g || g->coordinateMode() == QGradient::LogicalMode) { - d->extended->stroke(qtVectorPathForPath(path), pen); - return; - } + if (d->extended && !needsEmulation(pen.brush())) { + d->extended->stroke(qtVectorPathForPath(path), pen); + return; } QBrush oldBrush = d->state->brush; @@ -3126,12 +3131,9 @@ void QPainter::fillPath(const QPainterPath &path, const QBrush &brush) if (path.isEmpty()) return; - if (d->extended) { - const QGradient *g = brush.gradient(); - if (!g || g->coordinateMode() == QGradient::LogicalMode) { - d->extended->fill(qtVectorPathForPath(path), brush); - return; - } + if (d->extended && !needsEmulation(brush)) { + d->extended->fill(qtVectorPathForPath(path), brush); + return; } QBrush oldBrush = d->state->brush; @@ -6641,12 +6643,9 @@ void QPainter::fillRect(const QRectF &r, const QBrush &brush) if (!d->engine) return; - if (d->extended) { - const QGradient *g = brush.gradient(); - if (!g || g->coordinateMode() == QGradient::LogicalMode) { - d->extended->fillRect(r, brush); - return; - } + if (d->extended && !needsEmulation(brush)) { + d->extended->fillRect(r, brush); + return; } QPen oldPen = pen(); @@ -6679,12 +6678,9 @@ void QPainter::fillRect(const QRect &r, const QBrush &brush) if (!d->engine) return; - if (d->extended) { - const QGradient *g = brush.gradient(); - if (!g || g->coordinateMode() == QGradient::LogicalMode) { - d->extended->fillRect(r, brush); - return; - } + if (d->extended && !needsEmulation(brush)) { + d->extended->fillRect(r, brush); + return; } QPen oldPen = pen(); -- cgit v1.2.3