From 64fab8f7e2d225e37aa731db7501b5d5b82eab64 Mon Sep 17 00:00:00 2001 From: Joni Poikelin Date: Thu, 3 Jan 2019 11:52:15 +0200 Subject: Add faster path for scaling QRegion with multiple regions Fixes: QTBUG-72821 Change-Id: Ic4fa349087239337a77b0e280be551b46c75af71 Reviewed-by: Giuseppe D'Angelo --- tests/auto/gui/painting/qregion/tst_qregion.cpp | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'tests/auto/gui/painting') diff --git a/tests/auto/gui/painting/qregion/tst_qregion.cpp b/tests/auto/gui/painting/qregion/tst_qregion.cpp index 5256fbd1dc..24c4583819 100644 --- a/tests/auto/gui/painting/qregion/tst_qregion.cpp +++ b/tests/auto/gui/painting/qregion/tst_qregion.cpp @@ -84,6 +84,8 @@ private slots: #endif void regionFromPath(); + void scaleRegions_data(); + void scaleRegions(); #ifdef QT_BUILD_INTERNAL void regionToPath_data(); @@ -973,6 +975,59 @@ void tst_QRegion::regionFromPath() } } +void tst_QRegion::scaleRegions_data() +{ + QTest::addColumn("scale"); + QTest::addColumn>("inputRects"); + QTest::addColumn>("expectedRects"); + + QTest::newRow("1.0 single") << 1.0 + << QVector{ QRect(10, 10, 20, 20) } + << QVector{ QRect(10, 10, 20, 20) }; + QTest::newRow("1.0 multi") << 1.0 + << QVector{ QRect(10, 10, 20, 20), QRect(40, 10, 20, 20) } + << QVector{ QRect(10, 10, 20, 20), QRect(40, 10, 20, 20) }; + QTest::newRow("2.0 single") << 2.0 + << QVector{ QRect(10, 10, 20, 20) } + << QVector{ QRect(20, 20, 40, 40) }; + QTest::newRow("2.0 multi") << 2.0 + << QVector{ QRect(10, 10, 20, 20), QRect(40, 10, 20, 20) } + << QVector{ QRect(20, 20, 40, 40), QRect(80, 20, 40, 40) }; + QTest::newRow("-1.0 single") << -1.0 + << QVector{ QRect(10, 10, 20, 20) } + << QVector{ QRect(-30, -30, 20, 20) }; + QTest::newRow("-1.0 multi") << -1.0 + << QVector{ QRect(10, 10, 20, 20), QRect(40, 10, 20, 20) } + << QVector{ QRect(-60, -30, 20, 20), QRect(-30, -30, 20, 20) }; + QTest::newRow("-2.0 single") << -2.0 + << QVector{ QRect(10, 10, 20, 20) } + << QVector{ QRect(-60, -60, 40, 40) }; + QTest::newRow("-2.0 multi") << -2.0 + << QVector{ QRect(10, 10, 20, 20), QRect(40, 10, 20, 20) } + << QVector{ QRect(-120, -60, 40, 40), QRect(-60, -60, 40, 40) }; +} + +void tst_QRegion::scaleRegions() +{ + QFETCH(qreal, scale); + QFETCH(QVector, inputRects); + QFETCH(QVector, expectedRects); + + QRegion region; + region.setRects(inputRects.constData(), inputRects.size()); + + QRegion expected(expectedRects.first()); + expected.setRects(expectedRects.constData(), expectedRects.size()); + + QTransform t; + t.scale(scale, scale); + + auto result = t.map(region); + + QCOMPARE(result.rectCount(), expectedRects.size()); + QCOMPARE(result, expected); +} + Q_DECLARE_METATYPE(QPainterPath) #ifdef QT_BUILD_INTERNAL -- cgit v1.2.3