diff options
Diffstat (limited to 'tests/benchmarks/gui/painting')
24 files changed, 362 insertions, 384 deletions
diff --git a/tests/benchmarks/gui/painting/CMakeLists.txt b/tests/benchmarks/gui/painting/CMakeLists.txt new file mode 100644 index 0000000000..2313688038 --- /dev/null +++ b/tests/benchmarks/gui/painting/CMakeLists.txt @@ -0,0 +1,12 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +add_subdirectory(drawtexture) +add_subdirectory(qcolor) +add_subdirectory(qregion) +add_subdirectory(qtransform) +add_subdirectory(lancebench) +if(TARGET Qt::Widgets) + add_subdirectory(qpainter) + add_subdirectory(qtbench) +endif() diff --git a/tests/benchmarks/gui/painting/drawtexture/CMakeLists.txt b/tests/benchmarks/gui/painting/drawtexture/CMakeLists.txt new file mode 100644 index 0000000000..1e9af29d7f --- /dev/null +++ b/tests/benchmarks/gui/painting/drawtexture/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## tst_bench_drawtexture Binary: +##################################################################### + +qt_internal_add_benchmark(tst_bench_drawtexture + SOURCES + tst_drawtexture.cpp + LIBRARIES + Qt::Gui + Qt::GuiPrivate + Qt::Test +) diff --git a/tests/benchmarks/gui/painting/drawtexture/drawtexture.pro b/tests/benchmarks/gui/painting/drawtexture/drawtexture.pro deleted file mode 100644 index aa4aee5bba..0000000000 --- a/tests/benchmarks/gui/painting/drawtexture/drawtexture.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += testlib -QT += gui-private - -TEMPLATE = app -TARGET = tst_bench_drawtexture - -SOURCES += tst_drawtexture.cpp diff --git a/tests/benchmarks/gui/painting/drawtexture/tst_drawtexture.cpp b/tests/benchmarks/gui/painting/drawtexture/tst_drawtexture.cpp index c16e68a0b1..4ab0a2db1e 100644 --- a/tests/benchmarks/gui/painting/drawtexture/tst_drawtexture.cpp +++ b/tests/benchmarks/gui/painting/drawtexture/tst_drawtexture.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qtest.h> #include <QPainter> diff --git a/tests/benchmarks/gui/painting/lancebench/CMakeLists.txt b/tests/benchmarks/gui/painting/lancebench/CMakeLists.txt new file mode 100644 index 0000000000..bfdd4df1c9 --- /dev/null +++ b/tests/benchmarks/gui/painting/lancebench/CMakeLists.txt @@ -0,0 +1,70 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## tst_bench_lancebench Binary: +##################################################################### + +qt_internal_add_benchmark(tst_bench_lancebench + SOURCES + ../../../../baseline/shared/paintcommands.cpp ../../../../baseline/shared/paintcommands.h + tst_lancebench.cpp + INCLUDE_DIRECTORIES + ../../../../baseline/shared + LIBRARIES + Qt::Gui + Qt::GuiPrivate + Qt::Test +) + +# Resources: +set(images_resource_files + "images/alpha.png" + "images/alpha2x2.png" + "images/bitmap.png" + "images/border.png" + "images/borderimage.png" + "images/dome_argb32.png" + "images/dome_indexed.png" + "images/dome_indexed_mask.png" + "images/dome_mono.png" + "images/dome_mono_128.png" + "images/dome_mono_palette.png" + "images/dome_rgb32.png" + "images/dot.png" + "images/face.png" + "images/gam030.png" + "images/gam045.png" + "images/gam056.png" + "images/gam100.png" + "images/gam200.png" + "images/image.png" + "images/mask.png" + "images/mask_100.png" + "images/masked.png" + "images/sign.png" + "images/solid.png" + "images/solid2x2.png" + "images/struct-image-01.jpg" + "images/struct-image-01.png" + "images/zebra.png" +) + +list(TRANSFORM images_resource_files PREPEND "../../../../baseline/painting/") + +qt_internal_add_resource(tst_bench_lancebench "images" + PREFIX + "/" + BASE + "../../../../baseline/painting" + FILES + ${images_resource_files} +) + +## Scopes: +##################################################################### + +qt_internal_extend_target(tst_bench_lancebench CONDITION QT_FEATURE_opengl + LIBRARIES + Qt::OpenGL +) diff --git a/tests/benchmarks/gui/painting/lancebench/lancebench.pro b/tests/benchmarks/gui/painting/lancebench/lancebench.pro deleted file mode 100644 index 6458c50861..0000000000 --- a/tests/benchmarks/gui/painting/lancebench/lancebench.pro +++ /dev/null @@ -1,13 +0,0 @@ -TEMPLATE = app -TARGET = tst_bench_lancebench - -QT += testlib gui-private - - -SOURCES += tst_lancebench.cpp - -SOURCES += ../../../../auto/other/lancelot/paintcommands.cpp -HEADERS += ../../../../auto/other/lancelot/paintcommands.h -RESOURCES += ../../../../auto/other/lancelot/images.qrc - -TESTDATA += ../../../../auto/other/lancelot/scripts/* diff --git a/tests/benchmarks/gui/painting/lancebench/tst_lancebench.cpp b/tests/benchmarks/gui/painting/lancebench/tst_lancebench.cpp index bd0889bf4a..67bef8ebfe 100644 --- a/tests/benchmarks/gui/painting/lancebench/tst_lancebench.cpp +++ b/tests/benchmarks/gui/painting/lancebench/tst_lancebench.cpp @@ -1,32 +1,7 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "../../../../auto/other/lancelot/paintcommands.h" +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "paintcommands.h" #include <qtest.h> #include <QDir> @@ -96,21 +71,21 @@ tst_LanceBench::tst_LanceBench() void tst_LanceBench::initTestCase() { - QString baseDir = QFINDTESTDATA("../../../../auto/other/lancelot/scripts/text.qps"); + QString baseDir = QFINDTESTDATA("../../../../baseline/painting/scripts/text.qps"); scriptsDir = baseDir.left(baseDir.lastIndexOf('/')) + '/'; QDir qpsDir(scriptsDir); qpsFiles = qpsDir.entryList(QStringList() << QLatin1String("*.qps"), QDir::Files | QDir::Readable); if (qpsFiles.isEmpty()) { - QWARN("No qps script files found in " + qpsDir.path().toLatin1()); + qWarning() << "No qps script files found in" << qpsDir.path(); QSKIP("Aborted due to errors."); } std::sort(qpsFiles.begin(), qpsFiles.end()); - for (const QString& fileName : qAsConst(qpsFiles)) { + for (const QString& fileName : std::as_const(qpsFiles)) { QFile file(scriptsDir + fileName); file.open(QFile::ReadOnly); QByteArray cont = file.readAll(); - scripts.insert(fileName, QString::fromUtf8(cont).split(QLatin1Char('\n'), QString::SkipEmptyParts)); + scripts.insert(fileName, QString::fromUtf8(cont).split(QLatin1Char('\n'), Qt::SkipEmptyParts)); } } @@ -262,7 +237,7 @@ void tst_LanceBench::testCoreOpenGL() void tst_LanceBench::setupTestSuite(const QStringList& blacklist) { QTest::addColumn<QString>("qpsFile"); - for (const QString &fileName : qAsConst(qpsFiles)) { + for (const QString &fileName : std::as_const(qpsFiles)) { if (blacklist.contains(fileName)) continue; QTest::newRow(fileName.toLatin1()) << fileName; diff --git a/tests/benchmarks/gui/painting/painting.pro b/tests/benchmarks/gui/painting/painting.pro deleted file mode 100644 index 400c2994a6..0000000000 --- a/tests/benchmarks/gui/painting/painting.pro +++ /dev/null @@ -1,13 +0,0 @@ -TEMPLATE = subdirs -SUBDIRS = \ - drawtexture \ - qcolor \ - qpainter \ - qregion \ - qtransform \ - qtbench \ - lancebench - -!qtHaveModule(widgets): SUBDIRS -= \ - qpainter \ - qtbench diff --git a/tests/benchmarks/gui/painting/qcolor/CMakeLists.txt b/tests/benchmarks/gui/painting/qcolor/CMakeLists.txt new file mode 100644 index 0000000000..a450c698bf --- /dev/null +++ b/tests/benchmarks/gui/painting/qcolor/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## tst_bench_qcolor Binary: +##################################################################### + +qt_internal_add_benchmark(tst_bench_qcolor + SOURCES + tst_qcolor.cpp + LIBRARIES + Qt::Gui + Qt::GuiPrivate + Qt::Test +) diff --git a/tests/benchmarks/gui/painting/qcolor/qcolor.pro b/tests/benchmarks/gui/painting/qcolor/qcolor.pro deleted file mode 100644 index 5ceb702323..0000000000 --- a/tests/benchmarks/gui/painting/qcolor/qcolor.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += testlib -QT += gui-private - -TEMPLATE = app -TARGET = tst_bench_qcolor - -SOURCES += tst_qcolor.cpp diff --git a/tests/benchmarks/gui/painting/qcolor/tst_qcolor.cpp b/tests/benchmarks/gui/painting/qcolor/tst_qcolor.cpp index 52a7673c0c..02fe3f986e 100644 --- a/tests/benchmarks/gui/painting/qcolor/tst_qcolor.cpp +++ b/tests/benchmarks/gui/painting/qcolor/tst_qcolor.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qtest.h> #include <QColor> diff --git a/tests/benchmarks/gui/painting/qpainter/CMakeLists.txt b/tests/benchmarks/gui/painting/qpainter/CMakeLists.txt new file mode 100644 index 0000000000..13a99ecc1d --- /dev/null +++ b/tests/benchmarks/gui/painting/qpainter/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## tst_bench_qpainter Binary: +##################################################################### + +qt_internal_add_benchmark(tst_bench_qpainter + SOURCES + tst_qpainter.cpp + LIBRARIES + Qt::Gui + Qt::GuiPrivate + Qt::Test + Qt::Widgets + Qt::WidgetsPrivate +) diff --git a/tests/benchmarks/gui/painting/qpainter/qpainter.pro b/tests/benchmarks/gui/painting/qpainter/qpainter.pro deleted file mode 100644 index 1a1f218033..0000000000 --- a/tests/benchmarks/gui/painting/qpainter/qpainter.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += widgets testlib -QT += gui-private widgets-private - -TEMPLATE = app -TARGET = tst_bench_qpainter - -SOURCES += tst_qpainter.cpp diff --git a/tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp b/tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp index 485306a8ac..7954e964b3 100644 --- a/tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp @@ -1,33 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses #include <qtest.h> #include <QPainter> +#include <QPainterPath> #include <QPixmap> #include <QImage> #include <QPaintEngine> @@ -219,6 +197,9 @@ private slots: void drawTransformedSemiTransparentImage(); void drawTransformedFilledImage(); + void drawPathExceedingDevice_data(); + void drawPathExceedingDevice(); + private: void setupBrushes(); void createPrimitives(); @@ -309,7 +290,7 @@ void tst_QPainter::drawLine_data() QTest::addColumn<QLine>("line"); QTest::addColumn<QPen>("pen"); - QVector<QPen> pens; + QList<QPen> pens; pens << QPen(Qt::black) << QPen(Qt::black, 0, Qt::DashDotLine) << QPen(Qt::black, 4) @@ -553,7 +534,7 @@ void tst_QPainter::drawLine_clipped() qMin(line.y1(), line.y2()) + 2*offset + qAbs(line.dy())); - const QRect clip = QRect(line.p1(), line.p2()).normalized(); + const QRect clip = QRect::span(line.p1(), line.p2()); pixmapClipped.fill(Qt::white); QPainter p(&pixmapClipped); @@ -588,7 +569,7 @@ void tst_QPainter::drawLine_antialiased_clipped() qMin(line.y1(), line.y2()) + 2*offset + qAbs(line.dy())); - const QRect clip = QRect(line.p1(), line.p2()).normalized(); + const QRect clip = QRect::span(line.p1(), line.p2()); pixmapClipped.fill(Qt::white); QPainter p(&pixmapClipped); @@ -694,7 +675,7 @@ void tst_QPainter::drawPixmapImage_data_helper(bool pixmaps) for (; *targetFormats != QImage::Format_Invalid; ++targetFormats) { const QImage::Format *sourceFormats = pixmaps ? pixmapFormats : sourceImageFormats; for (; *sourceFormats != QImage::Format_Invalid; ++sourceFormats) { - for (const QSize &s : qAsConst(sizes)) { + for (const QSize &s : std::as_const(sizes)) { for (int type=0; type<=3; ++type) { QString name = QString::fromLatin1("%1 on %2, (%3x%4), %5") .arg(formatNames[*sourceFormats]) @@ -1683,6 +1664,56 @@ void tst_QPainter::drawTransformedFilledImage() } } +void tst_QPainter::drawPathExceedingDevice_data() +{ + QTest::addColumn<int>("dim"); + QTest::addColumn<QPainterPath>("path"); + + const int dim = 512; + QPainterPath p; + const int ext = 10 * dim; + for (int i = 0; i < ext; i += (ext / 50)) { + p.lineTo(ext, i); + p.lineTo(0, dim); + p.moveTo(0, 0); + } + + { + QPainterPath preClip; + preClip.addRect(0, 0, dim, dim); + QTest::newRow("devicesize") << dim << p.intersected(preClip); + } + + { + QPainterPath preClip; + preClip.addRect(0, 0, 2*dim, 2*dim); + QTest::newRow("devicesizex2") << dim << p.intersected(preClip); + } + + { + QPainterPath preClip; + preClip.addRect(0, 0, 5*dim, 5*dim); + QTest::newRow("devicesizex5") << dim << p.intersected(preClip); + } + + QTest::newRow("devicesizex10") << dim << p; +} + +void tst_QPainter::drawPathExceedingDevice() +{ + QFETCH(int, dim); + QFETCH(QPainterPath, path); + + QImage img(dim, dim, QImage::Format_RGB32); + QPainter p(&img); + p.setRenderHint(QPainter::Antialiasing); + p.setPen(QPen(Qt::black, 3)); + p.setBrush(Qt::NoBrush); + + QBENCHMARK { + p.drawPath(path); + } +} QTEST_MAIN(tst_QPainter) diff --git a/tests/benchmarks/gui/painting/qregion/CMakeLists.txt b/tests/benchmarks/gui/painting/qregion/CMakeLists.txt new file mode 100644 index 0000000000..c242a2f588 --- /dev/null +++ b/tests/benchmarks/gui/painting/qregion/CMakeLists.txt @@ -0,0 +1,14 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## tst_bench_qregion Binary: +##################################################################### + +qt_internal_add_benchmark(tst_bench_qregion + SOURCES + main.cpp + LIBRARIES + Qt::Gui + Qt::Test +) diff --git a/tests/benchmarks/gui/painting/qregion/main.cpp b/tests/benchmarks/gui/painting/qregion/main.cpp index 9e926780ab..696972c140 100644 --- a/tests/benchmarks/gui/painting/qregion/main.cpp +++ b/tests/benchmarks/gui/painting/qregion/main.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only // This file contains benchmarks for QRegion functions. #include <QDebug> diff --git a/tests/benchmarks/gui/painting/qregion/qregion.pro b/tests/benchmarks/gui/painting/qregion/qregion.pro deleted file mode 100644 index 1ff55080c5..0000000000 --- a/tests/benchmarks/gui/painting/qregion/qregion.pro +++ /dev/null @@ -1,6 +0,0 @@ -TEMPLATE = app -TARGET = tst_bench_qregion -QT += testlib -CONFIG += release - -SOURCES += main.cpp diff --git a/tests/benchmarks/gui/painting/qtbench/CMakeLists.txt b/tests/benchmarks/gui/painting/qtbench/CMakeLists.txt new file mode 100644 index 0000000000..68fbf0984f --- /dev/null +++ b/tests/benchmarks/gui/painting/qtbench/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## tst_bench_qtbench Binary: +##################################################################### + +qt_internal_add_benchmark(tst_bench_qtbench + SOURCES + tst_qtbench.cpp + LIBRARIES + Qt::Gui + Qt::Test + Qt::Widgets +) diff --git a/tests/benchmarks/gui/painting/qtbench/benchmarktests.h b/tests/benchmarks/gui/painting/qtbench/benchmarktests.h index b31b6823aa..9d890f1577 100644 --- a/tests/benchmarks/gui/painting/qtbench/benchmarktests.h +++ b/tests/benchmarks/gui/painting/qtbench/benchmarktests.h @@ -1,42 +1,17 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the FOO module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef BENCHMARKTESTS_H #define BENCHMARKTESTS_H #include <QApplication> #include <QTextDocument> -#include <QDesktopWidget> #include <QTextLayout> #include <QFontMetrics> #include <QDebug> #include <QStaticText> #include <QPainter> +#include <QPainterPath> #include <QRandomGenerator> class Benchmark @@ -128,13 +103,15 @@ public: { } - virtual void draw(QPainter *p, const QRect &rect, int iterationCount) { + void draw(QPainter *p, const QRect &rect, int iterationCount) override + { p->fillRect(rect, randomColor(iterationCount)); } - virtual QString name() const { + QString name() const override + { return QString::fromLatin1("fillRect(%1)").arg(m_size.width()); - } + } }; class ImageFillRectBenchmark : public Benchmark @@ -154,13 +131,12 @@ public: m_brush = QBrush(m_content); } - virtual void draw(QPainter *p, const QRect &rect, int) { - p->fillRect(rect, m_brush); - } + void draw(QPainter *p, const QRect &rect, int) override { p->fillRect(rect, m_brush); } - virtual QString name() const { + QString name() const override + { return QString::fromLatin1("fillRect with image(%1)").arg(m_size.width()); - } + } private: QImage m_content; @@ -176,19 +152,18 @@ public: { } - virtual void begin(QPainter *p, int) { + void begin(QPainter *p, int) override + { p->setPen(Qt::NoPen); p->setBrush(randomColor(m_size.width())); } + void draw(QPainter *p, const QRect &rect, int) override { p->drawRect(rect); } - virtual void draw(QPainter *p, const QRect &rect, int) { - p->drawRect(rect); - } - - virtual QString name() const { + QString name() const override + { return QString::fromLatin1("drawRect(%1)").arg(m_size.width()); - } + } }; @@ -200,19 +175,18 @@ public: { } - virtual void begin(QPainter *p, int) { - p->setPen(Qt::NoPen); - } - + void begin(QPainter *p, int) override { p->setPen(Qt::NoPen); } - virtual void draw(QPainter *p, const QRect &rect, int i) { + void draw(QPainter *p, const QRect &rect, int i) override + { p->setBrush(randomColor(i)); p->drawRect(rect); } - virtual QString name() const { + QString name() const override + { return QString::fromLatin1("drawRect with brushchange(%1)").arg(m_size.width()); - } + } }; class RoundRectBenchmark : public Benchmark @@ -224,16 +198,19 @@ public: m_roundness = size / 4.; } - virtual void begin(QPainter *p, int) { + void begin(QPainter *p, int) override + { p->setPen(Qt::NoPen); p->setBrush(Qt::red); } - virtual void draw(QPainter *p, const QRect &rect, int) { + void draw(QPainter *p, const QRect &rect, int) override + { p->drawRoundedRect(rect, m_roundness, m_roundness); } - virtual QString name() const { + QString name() const override + { return QString::fromLatin1("drawRoundedRect(%1)").arg(m_size.width()); } @@ -262,7 +239,8 @@ public: { } - virtual void begin(QPainter *p, int) { + void begin(QPainter *p, int) override + { if (m_type & Stroked) p->setPen(Qt::black); else @@ -274,7 +252,8 @@ public: p->setBrush(Qt::NoBrush); } - virtual void draw(QPainter *p, const QRect &rect, int) { + void draw(QPainter *p, const QRect &rect, int) override + { switch (m_type & Shapes) { case ArcShape: p->drawArc(rect, 45*16, 120*16); @@ -291,7 +270,8 @@ public: } } - virtual QString name() const { + QString name() const override + { QString fillStroke; if ((m_type & (Stroked|Filled)) == (Stroked|Filled)) { @@ -336,24 +316,24 @@ public: { } - virtual void begin(QPainter *p, int) { - p->scale(m_scale, m_scale); - } + void begin(QPainter *p, int) override { p->scale(m_scale, m_scale); } - virtual void draw(QPainter *p, const QRect &rect, int) { + void draw(QPainter *p, const QRect &rect, int) override + { if (m_as_pixmap) p->drawPixmap(rect.topLeft(), m_pixmap); else p->drawImage(rect.topLeft(), m_image); } - virtual QString name() const { + QString name() const override + { return QString::fromLatin1("draw%4(%1) at scale=%2, depth=%3") .arg(m_size.width()) .arg(m_scale) .arg(m_as_pixmap ? m_pixmap.depth() : m_image.depth()) .arg(m_type); - } + } private: QImage m_image; @@ -382,7 +362,8 @@ public: { } - virtual void draw(QPainter *p, const QRect &rect, int) { + void draw(QPainter *p, const QRect &rect, int) override + { QTransform oldTransform = p->transform(); p->translate(0.5 * rect.width() + rect.left(), 0.5 * rect.height() + rect.top()); p->shear(0.25, 0.0); @@ -394,12 +375,13 @@ public: p->setTransform(oldTransform); } - virtual QString name() const { + QString name() const override + { return QString::fromLatin1("draw%3(%1) w/transform, depth=%2") .arg(m_size.width()) .arg(m_as_pixmap ? m_pixmap.depth() : m_image.depth()) .arg(m_type); - } + } private: QImage m_image; @@ -428,19 +410,21 @@ public: { } - virtual void draw(QPainter *p, const QRect &rect, int) { + void draw(QPainter *p, const QRect &rect, int) override + { if (m_as_pixmap) p->drawPixmap(rect.topLeft(), m_pixmap); else p->drawImage(rect.topLeft(), m_image); } - virtual QString name() const { + QString name() const override + { return QString::fromLatin1("draw%2(%1), depth=%3") .arg(m_size.width()) .arg(m_type) .arg(m_as_pixmap ? m_pixmap.depth() : m_image.depth()); - } + } private: QImage m_image; @@ -469,7 +453,8 @@ public: { } - virtual void begin(QPainter *p, int iterations) { + void begin(QPainter *p, int iterations) override + { m_staticTexts.clear(); m_currentStaticText = 0; m_pixmaps.clear(); @@ -544,20 +529,20 @@ public: m_staticTexts.append(staticText); QFontMetrics fm(p->font()); - m_size = QSize(fm.horizontalAdvance(m_text, m_text.length()), fm.height()); + m_size = QSize(fm.horizontalAdvance(m_text, m_text.size()), fm.height()); break; } case PainterQPointMode: { QFontMetrics fm(p->font()); - m_size = QSize(fm.horizontalAdvance(m_text, m_text.length()), fm.height()); + m_size = QSize(fm.horizontalAdvance(m_text, m_text.size()), fm.height()); break; } } } - virtual void draw(QPainter *p, const QRect &rect, int) + void draw(QPainter *p, const QRect &rect, int) override { switch (m_mode) { case PainterMode: @@ -589,8 +574,9 @@ public: } } - virtual QString name() const { - int letters = m_text.length(); + QString name() const override + { + int letters = m_text.size(); int lines = m_text.count('\n'); if (lines == 0) lines = 1; @@ -644,7 +630,8 @@ public: { } - virtual void begin(QPainter *p, int) { + void begin(QPainter *p, int) override + { QRect m_bounds = QRect(0,0,p->device()->width(), p->device()->height()); p->setPen(Qt::NoPen); p->setBrush(Qt::red); @@ -706,11 +693,10 @@ public: } } - virtual void draw(QPainter *p, const QRect &rect, int) { - p->drawRect(rect); - } + void draw(QPainter *p, const QRect &rect, int) override { p->drawRect(rect); } - virtual QString name() const { + QString name() const override + { QString namedType; switch (m_type) { case RectClip: @@ -739,7 +725,7 @@ public: break; } return QString::fromLatin1("%1-clipped-drawRect(%2)").arg(namedType).arg(m_size.width()); - } + } ClipType m_type; }; @@ -764,7 +750,8 @@ public: } - virtual void draw(QPainter *p, const QRect &rect, int) { + void draw(QPainter *p, const QRect &rect, int) override + { switch (m_type) { case Horizontal_Integer: p->drawLine(QLine(rect.x(), rect.y(), rect.x() + m_length, rect.y())); @@ -787,7 +774,8 @@ public: } } - virtual QString name() const { + QString name() const override + { const char *names[] = { "Hor_I", "Diag_I", diff --git a/tests/benchmarks/gui/painting/qtbench/qtbench.pro b/tests/benchmarks/gui/painting/qtbench/qtbench.pro deleted file mode 100644 index a4c7273b47..0000000000 --- a/tests/benchmarks/gui/painting/qtbench/qtbench.pro +++ /dev/null @@ -1,6 +0,0 @@ -QT += widgets testlib - -TEMPLATE = app -TARGET = tst_bench_qtbench - -SOURCES += tst_qtbench.cpp diff --git a/tests/benchmarks/gui/painting/qtbench/tst_qtbench.cpp b/tests/benchmarks/gui/painting/qtbench/tst_qtbench.cpp index c2ce15f720..45b7045f94 100644 --- a/tests/benchmarks/gui/painting/qtbench/tst_qtbench.cpp +++ b/tests/benchmarks/gui/painting/qtbench/tst_qtbench.cpp @@ -1,34 +1,12 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses #include <qtest.h> #include <QtCore/qmath.h> +#include <QtCore/QElapsedTimer> #include <QtWidgets/QWidget> #include "benchmarktests.h" @@ -38,13 +16,13 @@ class BenchWidget : public QWidget public: BenchWidget(Benchmark *benchmark); - void paintEvent(QPaintEvent *event); + void paintEvent(QPaintEvent *event) override; bool done() const { return m_done; } qreal result() const { return m_result; } public: - QTime timer; + QElapsedTimer timer; Benchmark *m_benchmark; @@ -54,7 +32,7 @@ public: uint m_total; uint m_iteration; - QVector<uint> iterationTimes; + QList<uint> iterationTimes; }; void BenchWidget::paintEvent(QPaintEvent *) @@ -77,7 +55,7 @@ void BenchWidget::paintEvent(QPaintEvent *) ++m_iteration; - uint currentElapsed = timer.isNull() ? 0 : timer.elapsed(); + uint currentElapsed = timer.isValid() ? timer.elapsed() : 0; timer.restart(); m_total += currentElapsed; @@ -131,9 +109,13 @@ class tst_QtBench : public QObject { Q_OBJECT + QList<Benchmark *> benchmarks; + private slots: void qtBench(); void qtBench_data(); + + void cleanupTestCase() { qDeleteAll(benchmarks); } }; QString makeString(int length) @@ -183,7 +165,6 @@ void tst_QtBench::qtBench_data() "i erat, sed pellentesque\n" "mi. Curabitur sed."; - QList<Benchmark *> benchmarks; benchmarks << (new DrawText(shortString, DrawText::PainterMode)); benchmarks << (new DrawText(middleString, DrawText::PainterMode)); benchmarks << (new DrawText(longString, DrawText::PainterMode)); diff --git a/tests/benchmarks/gui/painting/qtransform/CMakeLists.txt b/tests/benchmarks/gui/painting/qtransform/CMakeLists.txt new file mode 100644 index 0000000000..8915ca3eb7 --- /dev/null +++ b/tests/benchmarks/gui/painting/qtransform/CMakeLists.txt @@ -0,0 +1,14 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## tst_bench_qtransform Binary: +##################################################################### + +qt_internal_add_benchmark(tst_bench_qtransform + SOURCES + tst_qtransform.cpp + LIBRARIES + Qt::Gui + Qt::Test +) diff --git a/tests/benchmarks/gui/painting/qtransform/qtransform.pro b/tests/benchmarks/gui/painting/qtransform/qtransform.pro deleted file mode 100644 index e8de3fcbd4..0000000000 --- a/tests/benchmarks/gui/painting/qtransform/qtransform.pro +++ /dev/null @@ -1,5 +0,0 @@ -TEMPLATE = app -TARGET = tst_bench_qtransform -QT += testlib -SOURCES += tst_qtransform.cpp - diff --git a/tests/benchmarks/gui/painting/qtransform/tst_qtransform.cpp b/tests/benchmarks/gui/painting/qtransform/tst_qtransform.cpp index d7a7f383ac..e6442d0dff 100644 --- a/tests/benchmarks/gui/painting/qtransform/tst_qtransform.cpp +++ b/tests/benchmarks/gui/painting/qtransform/tst_qtransform.cpp @@ -1,33 +1,9 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qtest.h> #include <QTransform> +#include <QPainterPath> class tst_QTransform : public QObject { @@ -167,9 +143,7 @@ void tst_QTransform::func##_data() \ { \ QTest::addColumn<QTransform>("transform"); \ QMap<const char *, QTransform> x = generateTransforms(); \ - QMapIterator<const char *, QTransform> it(x); \ - while (it.hasNext()) { \ - it.next(); \ + for (auto it = x.begin(), end = x.end(); it != end; ++it) { \ QTest::newRow(it.key()) << it.value(); \ } \ } @@ -180,14 +154,10 @@ void tst_QTransform::func##_data() \ QTest::addColumn<QTransform>("x1"); \ QTest::addColumn<QTransform>("x2"); \ QMap<const char *, QTransform> x = generateTransforms(); \ - QMapIterator<const char *, QTransform> it(x); \ - while (it.hasNext()) { \ - it.next(); \ + for (auto it = x.cbegin(), end = x.cend(); it != end; ++it) { \ const char *key1 = it.key(); \ QTransform x1 = it.value(); \ - QMapIterator<const char *, QTransform> it2(x); \ - while (it2.hasNext()) { \ - it2.next(); \ + for (auto it2 = x.cbegin(), end = x.cend(); it2 != end; ++it2) { \ QTest::newRow(QString("%1 + %2").arg(key1).arg(it2.key()).toLatin1().constData()) \ << x1 << it2.value(); \ } \ @@ -271,7 +241,7 @@ void tst_QTransform::operatorEqual() QFETCH(QTransform, x2); QTransform x = x1; QBENCHMARK { - x == x2; + [[maybe_unused]] auto r = x == x2; } } @@ -283,7 +253,7 @@ void tst_QTransform::operatorNotEqual() QFETCH(QTransform, x2); QTransform x = x1; QBENCHMARK { - x != x2; + [[maybe_unused]] auto r = x != x2; } } @@ -295,7 +265,7 @@ void tst_QTransform::operatorMultiply() QFETCH(QTransform, x2); QTransform x = x1; QBENCHMARK { - x * x2; + [[maybe_unused]] auto r = x * x2; } } @@ -340,7 +310,7 @@ void tst_QTransform::operatorMultiplyEqualScalar() QFETCH(QTransform, transform); QTransform x = transform; QBENCHMARK { - x * 3; + x *= 3; } } @@ -362,7 +332,7 @@ void tst_QTransform::mapQPoint() QFETCH(QTransform, transform); QTransform x = transform; QBENCHMARK { - x.map(QPoint(3, 3)); + [[maybe_unused]] auto r = x.map(QPoint(3, 3)); } } @@ -373,7 +343,7 @@ void tst_QTransform::mapQPointF() QFETCH(QTransform, transform); QTransform x = transform; QBENCHMARK { - x.map(QPointF(3, 3)); + [[maybe_unused]] auto r = x.map(QPointF(3, 3)); } } @@ -384,7 +354,7 @@ void tst_QTransform::mapRect() QFETCH(QTransform, transform); QTransform x = transform; QBENCHMARK { - x.mapRect(QRect(0, 0, 100, 100)); + [[maybe_unused]] auto r = x.mapRect(QRect(0, 0, 100, 100)); } } @@ -395,7 +365,7 @@ void tst_QTransform::mapRectF() QFETCH(QTransform, transform); QTransform x = transform; QBENCHMARK { - x.mapRect(QRectF(0, 0, 100, 100)); + [[maybe_unused]] auto r = x.mapRect(QRectF(0, 0, 100, 100)); } } @@ -407,7 +377,7 @@ void tst_QTransform::mapQPolygon() QTransform x = transform; QPolygon poly = QPolygon(QRect(0, 0, 100, 100)); QBENCHMARK { - x.map(poly); + [[maybe_unused]] auto r = x.map(poly); } } @@ -419,7 +389,7 @@ void tst_QTransform::mapQPolygonF() QTransform x = transform; QPolygonF poly = QPolygonF(QRectF(0, 0, 100, 100)); QBENCHMARK { - x.map(poly); + [[maybe_unused]] auto r = x.map(poly); } } @@ -433,7 +403,7 @@ void tst_QTransform::mapQRegion() for (int i = 0; i < 10; ++i) region += QRect(i * 10, i * 10, 100, 100); QBENCHMARK { - x.map(region); + [[maybe_unused]] auto r = x.map(region); } } @@ -444,7 +414,7 @@ void tst_QTransform::mapToPolygon() QFETCH(QTransform, transform); QTransform x = transform; QBENCHMARK { - x.mapToPolygon(QRect(0, 0, 100, 100)); + [[maybe_unused]] auto r = x.mapToPolygon(QRect(0, 0, 100, 100)); } } @@ -459,7 +429,7 @@ void tst_QTransform::mapQPainterPath() for (int i = 0; i < 10; ++i) path.addEllipse(i * 10, i * 10, 100, 100); QBENCHMARK { - x.map(path); + [[maybe_unused]] auto r = x.map(path); } } @@ -469,7 +439,7 @@ void tst_QTransform::isIdentity() { QFETCH(QTransform, transform); QBENCHMARK { - transform.isIdentity(); + [[maybe_unused]] auto r = transform.isIdentity(); } } @@ -479,7 +449,7 @@ void tst_QTransform::isAffine() { QFETCH(QTransform, transform); QBENCHMARK { - transform.isAffine(); + [[maybe_unused]] auto r = transform.isAffine(); } } @@ -489,7 +459,7 @@ void tst_QTransform::isInvertible() { QFETCH(QTransform, transform); QBENCHMARK { - transform.isInvertible(); + [[maybe_unused]] auto r = transform.isInvertible(); } } @@ -499,7 +469,7 @@ void tst_QTransform::isRotating() { QFETCH(QTransform, transform); QBENCHMARK { - transform.isRotating(); + [[maybe_unused]] auto r = transform.isRotating(); } } @@ -509,7 +479,7 @@ void tst_QTransform::isScaling() { QFETCH(QTransform, transform); QBENCHMARK { - transform.isScaling(); + [[maybe_unused]] auto r = transform.isScaling(); } } @@ -519,7 +489,7 @@ void tst_QTransform::isTranslating() { QFETCH(QTransform, transform); QBENCHMARK { - transform.isTranslating(); + [[maybe_unused]] auto r = transform.isTranslating(); } } @@ -529,7 +499,7 @@ void tst_QTransform::type() { QFETCH(QTransform, transform); QBENCHMARK { - transform.type(); + [[maybe_unused]] auto r = transform.type(); } } @@ -539,7 +509,7 @@ void tst_QTransform::determinant() { QFETCH(QTransform, transform); QBENCHMARK { - transform.determinant(); + [[maybe_unused]] auto r = transform.determinant(); } } @@ -549,7 +519,7 @@ void tst_QTransform::adjoint() { QFETCH(QTransform, transform); QBENCHMARK { - transform.adjoint(); + Q_UNUSED(transform.adjoint()) } } @@ -559,7 +529,7 @@ void tst_QTransform::transposed() { QFETCH(QTransform, transform); QBENCHMARK { - transform.transposed(); + Q_UNUSED(transform.transposed()) } } @@ -569,7 +539,7 @@ void tst_QTransform::inverted() { QFETCH(QTransform, transform); QBENCHMARK { - transform.inverted(); + Q_UNUSED(transform.inverted()) } } |