|
|
131b74 |
From 081d835c040a90f8ee76807354355062ac521dfb Mon Sep 17 00:00:00 2001
|
|
|
131b74 |
From: Eirik Aavitsland <eirik.aavitsland@qt.io>
|
|
|
131b74 |
Date: Tue, 13 Apr 2021 14:23:45 +0200
|
|
|
131b74 |
Subject: [PATCH] Avoid processing-intensive painting of high number of tiny
|
|
|
131b74 |
dashes
|
|
|
131b74 |
|
|
|
131b74 |
When stroking a dashed path, an unnecessary amount of processing would
|
|
|
131b74 |
be spent if there is a huge number of dashes visible, e.g. because of
|
|
|
131b74 |
scaling. Since the dashes are too small to be indivdually visible
|
|
|
131b74 |
anyway, just replace with a semi-transparent solid line for such
|
|
|
131b74 |
cases.
|
|
|
131b74 |
|
|
|
131b74 |
Pick-to: 6.1 6.0 5.15
|
|
|
131b74 |
Change-Id: I9e9f7861257ad5bce46a0cf113d1a9d7824911e6
|
|
|
131b74 |
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
|
|
|
131b74 |
(cherry picked from commit f4d791b330d02777fcaf02938732892eb3167e9b)
|
|
|
131b74 |
|
|
|
131b74 |
* asturmlechner 2021-08-21:
|
|
|
131b74 |
Conflict from preceding 94dd2ceb in dev branch:
|
|
|
131b74 |
src/gui/painting/qpaintengineex.cpp
|
|
|
131b74 |
Resolved via:
|
|
|
131b74 |
|
|
|
131b74 |
if (pen.style() > Qt::SolidLine) {
|
|
|
131b74 |
QRectF cpRect = path.controlPointRect();
|
|
|
131b74 |
const QTransform &xf = state()->matrix;
|
|
|
131b74 |
- if (pen.isCosmetic()) {
|
|
|
131b74 |
+ if (qt_pen_is_cosmetic(pen, state()->renderHints)){
|
|
|
131b74 |
clipRect = d->exDeviceRect;
|
|
|
131b74 |
cpRect.translate(xf.dx(), xf.dy());
|
|
|
131b74 |
} else {
|
|
|
131b74 |
|
|
|
131b74 |
FTBFS from preceding 471e4fcb in dev branch changing QVector to QList:
|
|
|
131b74 |
Resolved via:
|
|
|
131b74 |
|
|
|
131b74 |
QRectF extentRect = cpRect.adjusted(-pw, -pw, pw, pw) & clipRect;
|
|
|
131b74 |
qreal extent = qMax(extentRect.width(), extentRect.height());
|
|
|
131b74 |
qreal patternLength = 0;
|
|
|
131b74 |
- const QList<qreal> pattern = pen.dashPattern();
|
|
|
131b74 |
+ const QVector<qreal> pattern = pen.dashPattern();
|
|
|
131b74 |
const int patternSize = qMin(pattern.size(), 32);
|
|
|
131b74 |
for (int i = 0; i < patternSize; i++)
|
|
|
131b74 |
patternLength += qMax(pattern.at(i), qreal(0));
|
|
|
131b74 |
---
|
|
|
131b74 |
src/gui/painting/qpaintengineex.cpp | 44 +++++++++++++++----
|
|
|
131b74 |
.../other/lancelot/scripts/tinydashes.qps | 34 ++++++++++++++
|
|
|
131b74 |
2 files changed, 69 insertions(+), 9 deletions(-)
|
|
|
131b74 |
create mode 100644 tests/auto/other/lancelot/scripts/tinydashes.qps
|
|
|
131b74 |
|
|
|
131b74 |
diff --git a/src/gui/painting/qpaintengineex.cpp b/src/gui/painting/qpaintengineex.cpp
|
|
|
131b74 |
index 5d8f89eadd..55fdb0c2a0 100644
|
|
|
131b74 |
--- a/src/gui/painting/qpaintengineex.cpp
|
|
|
131b74 |
+++ b/src/gui/painting/qpaintengineex.cpp
|
|
|
131b74 |
@@ -385,7 +385,7 @@ QPainterState *QPaintEngineEx::createState(QPainterState *orig) const
|
|
|
131b74 |
|
|
|
131b74 |
Q_GUI_EXPORT extern bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp
|
|
|
131b74 |
|
|
|
131b74 |
-void QPaintEngineEx::stroke(const QVectorPath &path, const QPen &pen)
|
|
|
131b74 |
+void QPaintEngineEx::stroke(const QVectorPath &path, const QPen &inPen)
|
|
|
131b74 |
{
|
|
|
131b74 |
#ifdef QT_DEBUG_DRAW
|
|
|
131b74 |
qDebug() << "QPaintEngineEx::stroke()" << pen;
|
|
|
131b74 |
@@ -403,6 +403,38 @@ void QPaintEngineEx::stroke(const QVectorPath &path, const QPen &pen)
|
|
|
131b74 |
d->stroker.setCubicToHook(qpaintengineex_cubicTo);
|
|
|
131b74 |
}
|
|
|
131b74 |
|
|
|
131b74 |
+ QRectF clipRect;
|
|
|
131b74 |
+ QPen pen = inPen;
|
|
|
131b74 |
+ if (pen.style() > Qt::SolidLine) {
|
|
|
131b74 |
+ QRectF cpRect = path.controlPointRect();
|
|
|
131b74 |
+ const QTransform &xf = state()->matrix;
|
|
|
131b74 |
+ if (qt_pen_is_cosmetic(pen, state()->renderHints)){
|
|
|
131b74 |
+ clipRect = d->exDeviceRect;
|
|
|
131b74 |
+ cpRect.translate(xf.dx(), xf.dy());
|
|
|
131b74 |
+ } else {
|
|
|
131b74 |
+ clipRect = xf.inverted().mapRect(QRectF(d->exDeviceRect));
|
|
|
131b74 |
+ }
|
|
|
131b74 |
+ // Check to avoid generating unwieldy amount of dashes that will not be visible anyway
|
|
|
131b74 |
+ QRectF extentRect = cpRect & clipRect;
|
|
|
131b74 |
+ qreal extent = qMax(extentRect.width(), extentRect.height());
|
|
|
131b74 |
+ qreal patternLength = 0;
|
|
|
131b74 |
+ const QVector<qreal> pattern = pen.dashPattern();
|
|
|
131b74 |
+ const int patternSize = qMin(pattern.size(), 32);
|
|
|
131b74 |
+ for (int i = 0; i < patternSize; i++)
|
|
|
131b74 |
+ patternLength += qMax(pattern.at(i), qreal(0));
|
|
|
131b74 |
+ if (pen.widthF())
|
|
|
131b74 |
+ patternLength *= pen.widthF();
|
|
|
131b74 |
+ if (qFuzzyIsNull(patternLength)) {
|
|
|
131b74 |
+ pen.setStyle(Qt::NoPen);
|
|
|
131b74 |
+ } else if (extent / patternLength > 10000) {
|
|
|
131b74 |
+ // approximate stream of tiny dashes with semi-transparent solid line
|
|
|
131b74 |
+ pen.setStyle(Qt::SolidLine);
|
|
|
131b74 |
+ QColor color(pen.color());
|
|
|
131b74 |
+ color.setAlpha(color.alpha() / 2);
|
|
|
131b74 |
+ pen.setColor(color);
|
|
|
131b74 |
+ }
|
|
|
131b74 |
+ }
|
|
|
131b74 |
+
|
|
|
131b74 |
if (!qpen_fast_equals(pen, d->strokerPen)) {
|
|
|
131b74 |
d->strokerPen = pen;
|
|
|
131b74 |
d->stroker.setJoinStyle(pen.joinStyle());
|
|
|
131b74 |
@@ -430,14 +462,8 @@ void QPaintEngineEx::stroke(const QVectorPath &path, const QPen &pen)
|
|
|
131b74 |
return;
|
|
|
131b74 |
}
|
|
|
131b74 |
|
|
|
131b74 |
- if (pen.style() > Qt::SolidLine) {
|
|
|
131b74 |
- if (qt_pen_is_cosmetic(pen, state()->renderHints)){
|
|
|
131b74 |
- d->activeStroker->setClipRect(d->exDeviceRect);
|
|
|
131b74 |
- } else {
|
|
|
131b74 |
- QRectF clipRect = state()->matrix.inverted().mapRect(QRectF(d->exDeviceRect));
|
|
|
131b74 |
- d->activeStroker->setClipRect(clipRect);
|
|
|
131b74 |
- }
|
|
|
131b74 |
- }
|
|
|
131b74 |
+ if (!clipRect.isNull())
|
|
|
131b74 |
+ d->activeStroker->setClipRect(clipRect);
|
|
|
131b74 |
|
|
|
131b74 |
if (d->activeStroker == &d->stroker)
|
|
|
131b74 |
d->stroker.setForceOpen(path.hasExplicitOpen());
|
|
|
131b74 |
diff --git a/tests/auto/other/lancelot/scripts/tinydashes.qps b/tests/auto/other/lancelot/scripts/tinydashes.qps
|
|
|
131b74 |
new file mode 100644
|
|
|
131b74 |
index 0000000000..d41ced7f5f
|
|
|
131b74 |
--- /dev/null
|
|
|
131b74 |
+++ b/tests/auto/other/lancelot/scripts/tinydashes.qps
|
|
|
131b74 |
@@ -0,0 +1,34 @@
|
|
|
131b74 |
+# Version: 1
|
|
|
131b74 |
+# CheckVsReference: 5%
|
|
|
131b74 |
+
|
|
|
131b74 |
+path_addEllipse mypath 20.0 20.0 200.0 200.0
|
|
|
131b74 |
+
|
|
|
131b74 |
+save
|
|
|
131b74 |
+setPen blue 20 SolidLine FlatCap
|
|
|
131b74 |
+pen_setCosmetic true
|
|
|
131b74 |
+pen_setDashPattern [ 0.0004 0.0004 ]
|
|
|
131b74 |
+setBrush yellow
|
|
|
131b74 |
+
|
|
|
131b74 |
+drawPath mypath
|
|
|
131b74 |
+translate 300 0
|
|
|
131b74 |
+setRenderHint Antialiasing true
|
|
|
131b74 |
+drawPath mypath
|
|
|
131b74 |
+restore
|
|
|
131b74 |
+
|
|
|
131b74 |
+path_addEllipse bigpath 200000.0 200000.0 2000000.0 2000000.0
|
|
|
131b74 |
+
|
|
|
131b74 |
+setPen blue 20 DotLine FlatCap
|
|
|
131b74 |
+setBrush yellow
|
|
|
131b74 |
+
|
|
|
131b74 |
+save
|
|
|
131b74 |
+translate 0 300
|
|
|
131b74 |
+scale 0.0001 0.00011
|
|
|
131b74 |
+drawPath bigpath
|
|
|
131b74 |
+restore
|
|
|
131b74 |
+
|
|
|
131b74 |
+save
|
|
|
131b74 |
+translate 300 300
|
|
|
131b74 |
+setRenderHint Antialiasing true
|
|
|
131b74 |
+scale 0.0001 0.00011
|
|
|
131b74 |
+drawPath bigpath
|
|
|
131b74 |
+restore
|
|
|
131b74 |
--
|
|
|
131b74 |
GitLab
|
|
|
131b74 |
|
|
|
131b74 |
From 6b400e3147dcfd8cc3a393ace1bd118c93762e0c Mon Sep 17 00:00:00 2001
|
|
|
131b74 |
From: Eirik Aavitsland <eirik.aavitsland@qt.io>
|
|
|
131b74 |
Date: Fri, 23 Jul 2021 15:53:56 +0200
|
|
|
131b74 |
Subject: [PATCH] Improve fix for avoiding huge number of tiny dashes
|
|
|
131b74 |
MIME-Version: 1.0
|
|
|
131b74 |
Content-Type: text/plain; charset=UTF-8
|
|
|
131b74 |
Content-Transfer-Encoding: 8bit
|
|
|
131b74 |
|
|
|
131b74 |
Some pathological cases were not caught by the previous fix.
|
|
|
131b74 |
|
|
|
131b74 |
Fixes: QTBUG-95239
|
|
|
131b74 |
Pick-to: 6.2 6.1 5.15
|
|
|
131b74 |
Change-Id: I0337ee3923ff93ccb36c4d7b810a9c0667354cc5
|
|
|
131b74 |
Reviewed-by: Robert Löhning <robert.loehning@qt.io>
|
|
|
131b74 |
---
|
|
|
131b74 |
src/gui/painting/qpaintengineex.cpp | 2 +-
|
|
|
131b74 |
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
131b74 |
|
|
|
131b74 |
diff --git a/src/gui/painting/qpaintengineex.cpp b/src/gui/painting/qpaintengineex.cpp
|
|
|
131b74 |
index 2997d533107..22e9a621c3c 100644
|
|
|
131b74 |
--- a/src/gui/painting/qpaintengineex.cpp
|
|
|
131b74 |
+++ b/src/gui/painting/qpaintengineex.cpp
|
|
|
131b74 |
@@ -426,7 +426,7 @@ void QPaintEngineEx::stroke(const QVectorPath &path, const QPen &inPen)
|
|
|
131b74 |
patternLength *= pen.widthF();
|
|
|
131b74 |
if (qFuzzyIsNull(patternLength)) {
|
|
|
131b74 |
pen.setStyle(Qt::NoPen);
|
|
|
131b74 |
- } else if (extent / patternLength > 10000) {
|
|
|
131b74 |
+ } else if (qFuzzyIsNull(extent) || extent / patternLength > 10000) {
|
|
|
131b74 |
// approximate stream of tiny dashes with semi-transparent solid line
|
|
|
131b74 |
pen.setStyle(Qt::SolidLine);
|
|
|
131b74 |
QColor color(pen.color());
|
|
|
131b74 |
|
|
|
131b74 |
From 427df34efdcb56582a9ae9f7d2d1f39eeff70328 Mon Sep 17 00:00:00 2001
|
|
|
131b74 |
From: Eirik Aavitsland <eirik.aavitsland@qt.io>
|
|
|
131b74 |
Date: Fri, 30 Jul 2021 13:03:49 +0200
|
|
|
131b74 |
Subject: [PATCH] Refix for avoiding huge number of tiny dashes
|
|
|
131b74 |
|
|
|
131b74 |
Previous fix hit too widely so some valid horizontal and vertical
|
|
|
131b74 |
lines were affected; the root problem being that such lines have an
|
|
|
131b74 |
empty control point rect (width or height is 0). Fix by caculating in
|
|
|
131b74 |
the pen width.
|
|
|
131b74 |
|
|
|
131b74 |
Pick-to: 6.2 6.1 5.15
|
|
|
131b74 |
Change-Id: I7a436e873f6d485028f6759d0e2c6456f07eebdc
|
|
|
131b74 |
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
|
|
|
131b74 |
(cherry picked from commit 84aba80944a2e1c3058d7a1372e0e66676411884)
|
|
|
131b74 |
---
|
|
|
131b74 |
src/gui/painting/qpaintengineex.cpp | 8 ++---
|
|
|
131b74 |
.../gui/painting/qpainter/tst_qpainter.cpp | 31 +++++++++++++++++++
|
|
|
131b74 |
2 files changed, 35 insertions(+), 4 deletions(-)
|
|
|
131b74 |
|
|
|
131b74 |
diff --git a/src/gui/painting/qpaintengineex.cpp b/src/gui/painting/qpaintengineex.cpp
|
|
|
131b74 |
index 19e4b23423..9fe510827a 100644
|
|
|
131b74 |
--- a/src/gui/painting/qpaintengineex.cpp
|
|
|
131b74 |
+++ b/src/gui/painting/qpaintengineex.cpp
|
|
|
131b74 |
@@ -415,18 +415,18 @@ void QPaintEngineEx::stroke(const QVectorPath &path, const QPen &inPen)
|
|
|
131b74 |
clipRect = xf.inverted().mapRect(QRectF(d->exDeviceRect));
|
|
|
131b74 |
}
|
|
|
131b74 |
// Check to avoid generating unwieldy amount of dashes that will not be visible anyway
|
|
|
131b74 |
- QRectF extentRect = cpRect & clipRect;
|
|
|
131b74 |
+ qreal pw = pen.widthF() ? pen.widthF() : 1;
|
|
|
131b74 |
+ QRectF extentRect = cpRect.adjusted(-pw, -pw, pw, pw) & clipRect;
|
|
|
131b74 |
qreal extent = qMax(extentRect.width(), extentRect.height());
|
|
|
131b74 |
qreal patternLength = 0;
|
|
|
131b74 |
const QVector<qreal> pattern = pen.dashPattern();
|
|
|
131b74 |
const int patternSize = qMin(pattern.size(), 32);
|
|
|
131b74 |
for (int i = 0; i < patternSize; i++)
|
|
|
131b74 |
patternLength += qMax(pattern.at(i), qreal(0));
|
|
|
131b74 |
- if (pen.widthF())
|
|
|
131b74 |
- patternLength *= pen.widthF();
|
|
|
131b74 |
+ patternLength *= pw;
|
|
|
131b74 |
if (qFuzzyIsNull(patternLength)) {
|
|
|
131b74 |
pen.setStyle(Qt::NoPen);
|
|
|
131b74 |
- } else if (qFuzzyIsNull(extent) || extent / patternLength > 10000) {
|
|
|
131b74 |
+ } else if (extent / patternLength > 10000) {
|
|
|
131b74 |
// approximate stream of tiny dashes with semi-transparent solid line
|
|
|
131b74 |
pen.setStyle(Qt::SolidLine);
|
|
|
131b74 |
QColor color(pen.color());
|
|
|
131b74 |
diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
|
|
|
131b74 |
index 42e98ce363..d7c3f95f1d 100644
|
|
|
131b74 |
--- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
|
|
|
131b74 |
+++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
|
|
|
131b74 |
@@ -308,6 +308,7 @@ private slots:
|
|
|
131b74 |
void fillPolygon();
|
|
|
131b74 |
|
|
|
131b74 |
void drawImageAtPointF();
|
|
|
131b74 |
+ void scaledDashes();
|
|
|
131b74 |
|
|
|
131b74 |
private:
|
|
|
131b74 |
void fillData();
|
|
|
131b74 |
@@ -5468,6 +5469,36 @@ void tst_QPainter::drawImageAtPointF()
|
|
|
131b74 |
paint.end();
|
|
|
131b74 |
}
|
|
|
131b74 |
|
|
|
131b74 |
+void tst_QPainter::scaledDashes()
|
|
|
131b74 |
+{
|
|
|
131b74 |
+ // Test that we do not hit the limit-huge-number-of-dashes path
|
|
|
131b74 |
+ QRgb fore = qRgb(0, 0, 0xff);
|
|
|
131b74 |
+ QRgb back = qRgb(0xff, 0xff, 0);
|
|
|
131b74 |
+ QImage image(5, 32, QImage::Format_RGB32);
|
|
|
131b74 |
+ image.fill(back);
|
|
|
131b74 |
+ QPainter p(&image);
|
|
|
131b74 |
+ QPen pen(QColor(fore), 3, Qt::DotLine);
|
|
|
131b74 |
+ p.setPen(pen);
|
|
|
131b74 |
+ p.scale(1, 2);
|
|
|
131b74 |
+ p.drawLine(2, 0, 2, 16);
|
|
|
131b74 |
+ p.end();
|
|
|
131b74 |
+
|
|
|
131b74 |
+ bool foreFound = false;
|
|
|
131b74 |
+ bool backFound = false;
|
|
|
131b74 |
+ int i = 0;
|
|
|
131b74 |
+ while (i < 32 && (!foreFound || !backFound)) {
|
|
|
131b74 |
+ QRgb pix = image.pixel(3, i);
|
|
|
131b74 |
+ if (pix == fore)
|
|
|
131b74 |
+ foreFound = true;
|
|
|
131b74 |
+ else if (pix == back)
|
|
|
131b74 |
+ backFound = true;
|
|
|
131b74 |
+ i++;
|
|
|
131b74 |
+ }
|
|
|
131b74 |
+
|
|
|
131b74 |
+ QVERIFY(foreFound);
|
|
|
131b74 |
+ QVERIFY(backFound);
|
|
|
131b74 |
+}
|
|
|
131b74 |
+
|
|
|
131b74 |
QTEST_MAIN(tst_QPainter)
|
|
|
131b74 |
|
|
|
131b74 |
#include "tst_qpainter.moc"
|
|
|
131b74 |
--
|
|
|
131b74 |
GitLab
|