mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-06 09:15:23 +08:00
qt 6.5.1 original
This commit is contained in:
12
tests/benchmarks/gui/painting/CMakeLists.txt
Normal file
12
tests/benchmarks/gui/painting/CMakeLists.txt
Normal file
@ -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()
|
15
tests/benchmarks/gui/painting/drawtexture/CMakeLists.txt
Normal file
15
tests/benchmarks/gui/painting/drawtexture/CMakeLists.txt
Normal file
@ -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
|
||||
)
|
521
tests/benchmarks/gui/painting/drawtexture/tst_drawtexture.cpp
Normal file
521
tests/benchmarks/gui/painting/drawtexture/tst_drawtexture.cpp
Normal file
@ -0,0 +1,521 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <qtest.h>
|
||||
#include <QPainter>
|
||||
#include <QImage>
|
||||
|
||||
Q_DECLARE_METATYPE(QImage::Format)
|
||||
|
||||
#define SIZE 400
|
||||
|
||||
class tst_DrawTexture : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
void paint(bool smooth);
|
||||
|
||||
private slots:
|
||||
void simpleUpscale_data();
|
||||
void simpleUpscale();
|
||||
void simpleUpscaleSmooth_data();
|
||||
void simpleUpscaleSmooth();
|
||||
|
||||
void downscale_data();
|
||||
void downscale();
|
||||
void downscaleSmooth_data();
|
||||
void downscaleSmooth();
|
||||
|
||||
void upscale_data();
|
||||
void upscale();
|
||||
void upscaleSmooth_data();
|
||||
void upscaleSmooth();
|
||||
|
||||
void rotate_data();
|
||||
void rotate();
|
||||
void rotateSmooth_data();
|
||||
void rotateSmooth();
|
||||
|
||||
void perspective_data();
|
||||
void perspective();
|
||||
void perspectiveSmooth_data();
|
||||
void perspectiveSmooth();
|
||||
};
|
||||
|
||||
void tst_DrawTexture::simpleUpscale_data()
|
||||
{
|
||||
QTest::addColumn<QImage::Format>("sourceFormat");
|
||||
QTest::addColumn<QImage::Format>("targetFormat");
|
||||
QTest::addColumn<QTransform>("transform");
|
||||
|
||||
|
||||
QTransform matrix;
|
||||
matrix.scale(1.5, 1.5);
|
||||
QTest::newRow("rgb32 1.5x,1.5x on rgb32") << QImage::Format_RGB32
|
||||
<< QImage::Format_RGB32
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm 1.5x,1.5x on argb32pm") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("argb32 1.5x,1.5x on argb32pm") << QImage::Format_ARGB32
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgba8888pm 1.5x,1.5x on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied
|
||||
<< QImage::Format_RGBA8888_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgb16 1.5x,1.5x on rgb16") << QImage::Format_RGB16
|
||||
<< QImage::Format_RGB16
|
||||
<< matrix;
|
||||
QTest::newRow("rgb16 1.5x,1.5x on argb32pm") << QImage::Format_RGB16
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm 1.5x,1.5x on rgb30") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_RGB30
|
||||
<< matrix;
|
||||
matrix.reset();
|
||||
matrix.scale(5, 5);
|
||||
QTest::newRow("rgb32 5x,5x on rgb32") << QImage::Format_RGB32
|
||||
<< QImage::Format_RGB32
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm 5x,5x on argb32pm") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("argb32 5x,5x on argb32pm") << QImage::Format_ARGB32
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgba8888pm 5x,5x on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied
|
||||
<< QImage::Format_RGBA8888_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgb16 5x,5x on rgb16") << QImage::Format_RGB16
|
||||
<< QImage::Format_RGB16
|
||||
<< matrix;
|
||||
QTest::newRow("rgb16 5x,5x on rgb32") << QImage::Format_RGB16
|
||||
<< QImage::Format_RGB32
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm 5x,5x on rgb30") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_RGB30
|
||||
<< matrix;
|
||||
matrix.reset();
|
||||
matrix.translate(0, SIZE);
|
||||
matrix.scale(16, -1);
|
||||
QTest::newRow("rgb32 16x,-1x on rgb32") << QImage::Format_RGB32
|
||||
<< QImage::Format_RGB32
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm 16x,-1x on argb32pm") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("argb32 16x,-1x on argb32pm") << QImage::Format_ARGB32
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgba8888pm 16x,-1x on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied
|
||||
<< QImage::Format_RGBA8888_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgb16 16x,-1x on rgb16") << QImage::Format_RGB16
|
||||
<< QImage::Format_RGB16
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm 16x,-1x on rgb30") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_RGB30
|
||||
<< matrix;
|
||||
}
|
||||
|
||||
void tst_DrawTexture::downscale_data()
|
||||
{
|
||||
QTest::addColumn<QImage::Format>("sourceFormat");
|
||||
QTest::addColumn<QImage::Format>("targetFormat");
|
||||
QTest::addColumn<QTransform>("transform");
|
||||
|
||||
|
||||
QTransform matrix;
|
||||
matrix.translate(SIZE, 0);
|
||||
matrix.scale(-1.5, 1.5);
|
||||
QTest::newRow("rgb32 -1.5x,1.5x on rgb32") << QImage::Format_RGB32
|
||||
<< QImage::Format_RGB32
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm -1.5x,1.5x on argb32pm") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("argb32 -1.5x,1.5x on argb32pm") << QImage::Format_ARGB32
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgba8888pm -1.5x,1.5x on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied
|
||||
<< QImage::Format_RGBA8888_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgb16 -1.5x,1.5x on rgb16") << QImage::Format_RGB16
|
||||
<< QImage::Format_RGB16
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm -1.5x,1.5x on rgb30") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_RGB30
|
||||
<< matrix;
|
||||
matrix.reset();
|
||||
matrix.scale(.5, .5);
|
||||
QTest::newRow("rgb32 .5x,.5x on rgb32") << QImage::Format_RGB32
|
||||
<< QImage::Format_RGB32
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm .5x,.5x on argb32pm") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("argb32 .5x,.5x on argb32pm") << QImage::Format_ARGB32
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgba8888pm .5x,.5x on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied
|
||||
<< QImage::Format_RGBA8888_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgb16 .5x,.5x on rgb16") << QImage::Format_RGB16
|
||||
<< QImage::Format_RGB16
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm .5x,.5x on rgb30") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_RGB30
|
||||
<< matrix;
|
||||
matrix.reset();
|
||||
matrix.scale(.2, 2);
|
||||
QTest::newRow("rgb32 .2x,2x on rgb32") << QImage::Format_RGB32
|
||||
<< QImage::Format_RGB32
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm .2x,2x on argb32pm") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("argb32 .2x,2x on argb32pm") << QImage::Format_ARGB32
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgba8888pm .2x,2x on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied
|
||||
<< QImage::Format_RGBA8888_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgb16 .2x,2x on rgb16") << QImage::Format_RGB16
|
||||
<< QImage::Format_RGB16
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm .2x,2x on rgb30") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_RGB30
|
||||
<< matrix;
|
||||
}
|
||||
|
||||
void tst_DrawTexture::upscale_data()
|
||||
{
|
||||
QTest::addColumn<QImage::Format>("sourceFormat");
|
||||
QTest::addColumn<QImage::Format>("targetFormat");
|
||||
QTest::addColumn<QTransform>("transform");
|
||||
|
||||
|
||||
QTransform matrix;
|
||||
matrix.translate(SIZE, 0);
|
||||
matrix.scale(-8, 8);
|
||||
QTest::newRow("rgb32 -8x,8x on rgb32") << QImage::Format_RGB32
|
||||
<< QImage::Format_RGB32
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm -8x,8x on argb32pm") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("argb32 -8x,8x on argb32pm") << QImage::Format_ARGB32
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgba8888pm -8x,8x on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied
|
||||
<< QImage::Format_RGBA8888_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgb16 -8x,8x on rgb16") << QImage::Format_RGB16
|
||||
<< QImage::Format_RGB16
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm -8x,8x on rgb30") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_RGB30
|
||||
<< matrix;
|
||||
matrix.reset();
|
||||
matrix.translate(SIZE, SIZE);
|
||||
matrix.scale(-10, -10);
|
||||
QTest::newRow("rgb32 -10x,-10x on rgb32") << QImage::Format_RGB32
|
||||
<< QImage::Format_RGB32
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm -10x,-10x on argb32pm") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("argb32 -10x,-10x on argb32pm") << QImage::Format_ARGB32
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgba8888pm -10x,-10x on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied
|
||||
<< QImage::Format_RGBA8888_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgb16 -10x,-10x on rgb16") << QImage::Format_RGB16
|
||||
<< QImage::Format_RGB16
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm -10x,-10x on rgb30") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_RGB30
|
||||
<< matrix;
|
||||
|
||||
matrix.reset();
|
||||
matrix.translate(SIZE, 0);
|
||||
matrix.scale(-1, 16);
|
||||
QTest::newRow("rgb32 -1x,16x on rgb32") << QImage::Format_RGB32
|
||||
<< QImage::Format_RGB32
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm -1x,16x on argb32pm") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("argb32 -1x,16x on argb32pm") << QImage::Format_ARGB32
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgba8888pm -1x,16x on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied
|
||||
<< QImage::Format_RGBA8888_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgb16 -1x,16x on rgb16") << QImage::Format_RGB16
|
||||
<< QImage::Format_RGB16
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm -1x,16x on rgb30") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_RGB30
|
||||
<< matrix;
|
||||
}
|
||||
|
||||
void tst_DrawTexture::rotate_data()
|
||||
{
|
||||
QTest::addColumn<QImage::Format>("sourceFormat");
|
||||
QTest::addColumn<QImage::Format>("targetFormat");
|
||||
QTest::addColumn<QTransform>("transform");
|
||||
|
||||
QTransform matrix;
|
||||
matrix.translate(SIZE/2, SIZE/2);
|
||||
matrix.rotate(-90);
|
||||
matrix.translate(-SIZE/2, -SIZE/2);
|
||||
QTest::newRow("rgb32 -90deg on rgb32") << QImage::Format_RGB32
|
||||
<< QImage::Format_RGB32
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm -90deg on argb32pm") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("argb32 -90deg on argb32pm") << QImage::Format_ARGB32
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgba8888pm -90deg on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied
|
||||
<< QImage::Format_RGBA8888_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgb16 -90deg rgb16") << QImage::Format_RGB16
|
||||
<< QImage::Format_RGB16
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm -90deg on rgb30") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_RGB30
|
||||
<< matrix;
|
||||
matrix.reset();
|
||||
matrix.translate(SIZE/2, SIZE/2);
|
||||
matrix.rotate(45);
|
||||
matrix.translate(-SIZE/2, -SIZE/2);
|
||||
QTest::newRow("rgb32 45deg on rgb32") << QImage::Format_RGB32
|
||||
<< QImage::Format_RGB32
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm 45deg on argb32pm") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("argb32 45deg on argb32pm") << QImage::Format_ARGB32
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgba8888pm 45deg on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied
|
||||
<< QImage::Format_RGBA8888_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgb16 45deg on rgb16") << QImage::Format_RGB16
|
||||
<< QImage::Format_RGB16
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm 45deg on rgb30") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_RGB30
|
||||
<< matrix;
|
||||
|
||||
matrix.reset();
|
||||
matrix.translate(SIZE/2, SIZE/2);
|
||||
matrix.rotate(135);
|
||||
matrix.scale(2, 2);
|
||||
matrix.translate(-SIZE/4, -SIZE/4);
|
||||
QTest::newRow("rgb32 rotate+scale on rgb32") << QImage::Format_RGB32
|
||||
<< QImage::Format_RGB32
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm rotate+scale on argb32pm") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("argb32 rotate+scale on argb32pm") << QImage::Format_ARGB32
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgba8888pm rotate+scale on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied
|
||||
<< QImage::Format_RGBA8888_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgb16 rotate+scale on rgb16") << QImage::Format_RGB16
|
||||
<< QImage::Format_RGB16
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm rotate+scale on rgb30") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_RGB30
|
||||
<< matrix;
|
||||
}
|
||||
|
||||
void tst_DrawTexture::perspective_data()
|
||||
{
|
||||
QTest::addColumn<QImage::Format>("sourceFormat");
|
||||
QTest::addColumn<QImage::Format>("targetFormat");
|
||||
QTest::addColumn<QTransform>("transform");
|
||||
|
||||
QTransform matrix;
|
||||
QPolygonF quad1, quad2;
|
||||
quad1 << QPointF(0.0, 0.0) << QPointF(SIZE,0.0) << QPointF(SIZE,SIZE) << QPointF(0.0,SIZE);
|
||||
quad2 << QPointF(SIZE/6, SIZE/6) << QPointF(SIZE*4/5,SIZE/5) << QPointF(SIZE*4/5,SIZE*5/6) << QPointF(SIZE/5,SIZE*3/5);
|
||||
QTransform::quadToQuad(quad1, quad2, matrix);
|
||||
|
||||
QTest::newRow("rgb32 perspective1 on rgb32") << QImage::Format_RGB32
|
||||
<< QImage::Format_RGB32
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm perspective1 on argb32pm") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("argb32 perspective1 on argb32pm") << QImage::Format_ARGB32
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgba8888pm perspective1 on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied
|
||||
<< QImage::Format_RGBA8888_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgb16 perspective1 on rgb16") << QImage::Format_RGB16
|
||||
<< QImage::Format_RGB16
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm perspective1 on rgb30") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_RGB30
|
||||
<< matrix;
|
||||
|
||||
matrix.reset();
|
||||
quad1.clear(); quad2.clear();
|
||||
quad1 << QPointF(0.0, 0.0) << QPointF(SIZE,0.0) << QPointF(SIZE,SIZE) << QPointF(0.0,SIZE);
|
||||
quad2 << QPointF(0.0, 0.0) << QPointF(SIZE*4/5,SIZE/4) << QPointF(SIZE*4/5,SIZE*3/4) << QPointF(0.0,SIZE);
|
||||
QTransform::quadToQuad(quad1, quad2, matrix);
|
||||
|
||||
QTest::newRow("rgb32 perspective2 on rgb32") << QImage::Format_RGB32
|
||||
<< QImage::Format_RGB32
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm perspective2 on argb32pm") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("argb32 perspective2 on argb32pm") << QImage::Format_ARGB32
|
||||
<< QImage::Format_ARGB32_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgba8888pm perspective2 on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied
|
||||
<< QImage::Format_RGBA8888_Premultiplied
|
||||
<< matrix;
|
||||
QTest::newRow("rgb16 perspective2 on rgb16") << QImage::Format_RGB16
|
||||
<< QImage::Format_RGB16
|
||||
<< matrix;
|
||||
QTest::newRow("argb32pm perspective2 on rgb30") << QImage::Format_ARGB32_Premultiplied
|
||||
<< QImage::Format_RGB30
|
||||
<< matrix;
|
||||
}
|
||||
|
||||
void tst_DrawTexture::simpleUpscaleSmooth_data()
|
||||
{
|
||||
simpleUpscale_data();
|
||||
}
|
||||
|
||||
void tst_DrawTexture::downscaleSmooth_data()
|
||||
{
|
||||
downscale_data();
|
||||
}
|
||||
|
||||
void tst_DrawTexture::upscaleSmooth_data()
|
||||
{
|
||||
upscale_data();
|
||||
}
|
||||
|
||||
void tst_DrawTexture::rotateSmooth_data()
|
||||
{
|
||||
rotate_data();
|
||||
}
|
||||
|
||||
void tst_DrawTexture::perspectiveSmooth_data()
|
||||
{
|
||||
perspective_data();
|
||||
}
|
||||
|
||||
static QImage createImage(const QSize &size, QImage::Format format, bool smooth)
|
||||
{
|
||||
QImage base(size, format);
|
||||
base.fill(Qt::transparent);
|
||||
QLinearGradient grad(0.0, 0.0, 1.0, 0.0);
|
||||
grad.setCoordinateMode(QGradient::ObjectBoundingMode);
|
||||
grad.setColorAt(0.0, Qt::red);
|
||||
grad.setColorAt(0.4, Qt::white);
|
||||
grad.setColorAt(0.6, Qt::white);
|
||||
grad.setColorAt(1.0, Qt::blue);
|
||||
QBrush brush(grad);
|
||||
QPainter p(&base);
|
||||
p.setRenderHint(QPainter::Antialiasing, smooth);
|
||||
p.setBrush(brush);
|
||||
p.setPen(Qt::NoPen);
|
||||
p.drawEllipse(0, 0, size.width(), size.height());
|
||||
p.end();
|
||||
return base;
|
||||
}
|
||||
|
||||
|
||||
void tst_DrawTexture::paint(bool smooth)
|
||||
{
|
||||
QFETCH(QImage::Format, sourceFormat);
|
||||
QFETCH(QImage::Format, targetFormat);
|
||||
QFETCH(QTransform, transform);
|
||||
|
||||
QSize size(SIZE, SIZE);
|
||||
QRect rect(QPoint(0,0), size);
|
||||
if (transform.isAffine())
|
||||
rect = transform.inverted().mapRect(rect);
|
||||
|
||||
QImage sourceImage = createImage(rect.size(), sourceFormat, smooth);
|
||||
QImage targetImage(size, targetFormat);
|
||||
targetImage.fill(Qt::gray);
|
||||
|
||||
QPainter p(&targetImage);
|
||||
p.setRenderHints(QPainter::SmoothPixmapTransform, smooth);
|
||||
p.setRenderHints(QPainter::Antialiasing, smooth);
|
||||
p.setWorldTransform(transform, false);
|
||||
|
||||
QBENCHMARK {
|
||||
p.drawImage(0, 0, sourceImage);
|
||||
}
|
||||
// targetImage.save(QString::fromLatin1(QTest::currentTestFunction()) + QChar('_') + QString::fromLatin1(QTest::currentDataTag()) + QStringLiteral(".png"));
|
||||
}
|
||||
|
||||
void tst_DrawTexture::simpleUpscale()
|
||||
{
|
||||
paint(false);
|
||||
}
|
||||
|
||||
void tst_DrawTexture::upscale()
|
||||
{
|
||||
paint(false);
|
||||
}
|
||||
|
||||
void tst_DrawTexture::downscale()
|
||||
{
|
||||
paint(false);
|
||||
}
|
||||
|
||||
void tst_DrawTexture::rotate()
|
||||
{
|
||||
paint(false);
|
||||
}
|
||||
|
||||
void tst_DrawTexture::perspective()
|
||||
{
|
||||
paint(false);
|
||||
}
|
||||
|
||||
void tst_DrawTexture::simpleUpscaleSmooth()
|
||||
{
|
||||
paint(true);
|
||||
}
|
||||
|
||||
void tst_DrawTexture::upscaleSmooth()
|
||||
{
|
||||
paint(true);
|
||||
}
|
||||
|
||||
void tst_DrawTexture::downscaleSmooth()
|
||||
{
|
||||
paint(true);
|
||||
}
|
||||
|
||||
void tst_DrawTexture::rotateSmooth()
|
||||
{
|
||||
paint(true);
|
||||
}
|
||||
|
||||
void tst_DrawTexture::perspectiveSmooth()
|
||||
{
|
||||
paint(true);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_DrawTexture)
|
||||
|
||||
#include "tst_drawtexture.moc"
|
70
tests/benchmarks/gui/painting/lancebench/CMakeLists.txt
Normal file
70
tests/benchmarks/gui/painting/lancebench/CMakeLists.txt
Normal file
@ -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
|
||||
)
|
303
tests/benchmarks/gui/painting/lancebench/tst_lancebench.cpp
Normal file
303
tests/benchmarks/gui/painting/lancebench/tst_lancebench.cpp
Normal file
@ -0,0 +1,303 @@
|
||||
// Copyright (C) 2018 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "paintcommands.h"
|
||||
|
||||
#include <qtest.h>
|
||||
#include <QDir>
|
||||
#include <QPainter>
|
||||
|
||||
#ifndef QT_NO_OPENGL
|
||||
#include <QOpenGLFramebufferObjectFormat>
|
||||
#include <QOpenGLContext>
|
||||
#include <QOpenGLPaintDevice>
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
class tst_LanceBench : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
tst_LanceBench();
|
||||
|
||||
private:
|
||||
enum GraphicsEngine {
|
||||
Raster = 0,
|
||||
OpenGL = 1
|
||||
};
|
||||
|
||||
void setupTestSuite(const QStringList& blacklist = QStringList());
|
||||
void runTestSuite(GraphicsEngine engine, QImage::Format format, const QSurfaceFormat &contextFormat = QSurfaceFormat());
|
||||
void paint(QPaintDevice *device, GraphicsEngine engine, QImage::Format format, const QStringList &script, const QString &filePath);
|
||||
|
||||
QStringList qpsFiles;
|
||||
QHash<QString, QStringList> scripts;
|
||||
QString scriptsDir;
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void cleanupTestCase() {}
|
||||
|
||||
void testRasterARGB32PM_data();
|
||||
void testRasterARGB32PM();
|
||||
void testRasterRGB32_data();
|
||||
void testRasterRGB32();
|
||||
void testRasterARGB32_data();
|
||||
void testRasterARGB32();
|
||||
void testRasterRGB16_data();
|
||||
void testRasterRGB16();
|
||||
void testRasterBGR30_data();
|
||||
void testRasterBGR30();
|
||||
void testRasterARGB8565PM_data();
|
||||
void testRasterARGB8565PM();
|
||||
void testRasterGrayscale8_data();
|
||||
void testRasterGrayscale8();
|
||||
|
||||
#ifndef QT_NO_OPENGL
|
||||
void testOpenGL_data();
|
||||
void testOpenGL();
|
||||
void testCoreOpenGL_data();
|
||||
void testCoreOpenGL();
|
||||
private:
|
||||
bool checkSystemGLSupport();
|
||||
bool checkSystemCoreGLSupport();
|
||||
#endif
|
||||
};
|
||||
|
||||
tst_LanceBench::tst_LanceBench()
|
||||
{
|
||||
}
|
||||
|
||||
void tst_LanceBench::initTestCase()
|
||||
{
|
||||
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()) {
|
||||
qWarning() << "No qps script files found in" << qpsDir.path();
|
||||
QSKIP("Aborted due to errors.");
|
||||
}
|
||||
|
||||
std::sort(qpsFiles.begin(), qpsFiles.end());
|
||||
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'), Qt::SkipEmptyParts));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_LanceBench::testRasterARGB32PM_data()
|
||||
{
|
||||
setupTestSuite();
|
||||
}
|
||||
|
||||
void tst_LanceBench::testRasterARGB32PM()
|
||||
{
|
||||
runTestSuite(Raster, QImage::Format_ARGB32_Premultiplied);
|
||||
}
|
||||
|
||||
void tst_LanceBench::testRasterRGB32_data()
|
||||
{
|
||||
setupTestSuite();
|
||||
}
|
||||
|
||||
void tst_LanceBench::testRasterRGB32()
|
||||
{
|
||||
runTestSuite(Raster, QImage::Format_RGB32);
|
||||
}
|
||||
|
||||
void tst_LanceBench::testRasterARGB32_data()
|
||||
{
|
||||
setupTestSuite();
|
||||
}
|
||||
|
||||
void tst_LanceBench::testRasterARGB32()
|
||||
{
|
||||
runTestSuite(Raster, QImage::Format_ARGB32);
|
||||
}
|
||||
|
||||
void tst_LanceBench::testRasterRGB16_data()
|
||||
{
|
||||
setupTestSuite();
|
||||
}
|
||||
|
||||
void tst_LanceBench::testRasterRGB16()
|
||||
{
|
||||
runTestSuite(Raster, QImage::Format_RGB16);
|
||||
}
|
||||
|
||||
void tst_LanceBench::testRasterBGR30_data()
|
||||
{
|
||||
setupTestSuite();
|
||||
}
|
||||
|
||||
void tst_LanceBench::testRasterBGR30()
|
||||
{
|
||||
runTestSuite(Raster, QImage::Format_BGR30);
|
||||
}
|
||||
|
||||
void tst_LanceBench::testRasterARGB8565PM_data()
|
||||
{
|
||||
setupTestSuite();
|
||||
}
|
||||
|
||||
void tst_LanceBench::testRasterARGB8565PM()
|
||||
{
|
||||
runTestSuite(Raster, QImage::Format_ARGB8565_Premultiplied);
|
||||
}
|
||||
|
||||
void tst_LanceBench::testRasterGrayscale8_data()
|
||||
{
|
||||
setupTestSuite();
|
||||
}
|
||||
|
||||
void tst_LanceBench::testRasterGrayscale8()
|
||||
{
|
||||
runTestSuite(Raster, QImage::Format_Grayscale8);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_OPENGL
|
||||
bool tst_LanceBench::checkSystemGLSupport()
|
||||
{
|
||||
QWindow win;
|
||||
win.setSurfaceType(QSurface::OpenGLSurface);
|
||||
win.create();
|
||||
QOpenGLFramebufferObjectFormat fmt;
|
||||
fmt.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
|
||||
fmt.setSamples(4);
|
||||
QOpenGLContext ctx;
|
||||
if (!ctx.create() || !ctx.makeCurrent(&win))
|
||||
return false;
|
||||
QOpenGLFramebufferObject fbo(800, 800, fmt);
|
||||
if (!fbo.isValid() || !fbo.bind())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tst_LanceBench::checkSystemCoreGLSupport()
|
||||
{
|
||||
if (QOpenGLContext::openGLModuleType() != QOpenGLContext::LibGL)
|
||||
return false;
|
||||
|
||||
QSurfaceFormat coreFormat;
|
||||
coreFormat.setVersion(3, 2);
|
||||
coreFormat.setProfile(QSurfaceFormat::CoreProfile);
|
||||
QWindow win;
|
||||
win.setSurfaceType(QSurface::OpenGLSurface);
|
||||
win.setFormat(coreFormat);
|
||||
win.create();
|
||||
QOpenGLFramebufferObjectFormat fmt;
|
||||
fmt.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
|
||||
fmt.setSamples(4);
|
||||
QOpenGLContext ctx;
|
||||
ctx.setFormat(coreFormat);
|
||||
if (!ctx.create() || !ctx.makeCurrent(&win))
|
||||
return false;
|
||||
QOpenGLFramebufferObject fbo(800, 800, fmt);
|
||||
if (!fbo.isValid() || !fbo.bind())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void tst_LanceBench::testOpenGL_data()
|
||||
{
|
||||
if (!checkSystemGLSupport())
|
||||
QSKIP("System under test does not meet preconditions for GL testing. Skipping.");
|
||||
QStringList localBlacklist = QStringList() << QLatin1String("rasterops.qps");
|
||||
setupTestSuite(localBlacklist);
|
||||
}
|
||||
|
||||
void tst_LanceBench::testOpenGL()
|
||||
{
|
||||
runTestSuite(OpenGL, QImage::Format_RGB32);
|
||||
}
|
||||
|
||||
void tst_LanceBench::testCoreOpenGL_data()
|
||||
{
|
||||
if (!checkSystemCoreGLSupport())
|
||||
QSKIP("System under test does not meet preconditions for Core Profile GL testing. Skipping.");
|
||||
QStringList localBlacklist = QStringList() << QLatin1String("rasterops.qps");
|
||||
setupTestSuite(localBlacklist);
|
||||
}
|
||||
|
||||
void tst_LanceBench::testCoreOpenGL()
|
||||
{
|
||||
QSurfaceFormat coreFormat;
|
||||
coreFormat.setVersion(3, 2);
|
||||
coreFormat.setProfile(QSurfaceFormat::CoreProfile);
|
||||
runTestSuite(OpenGL, QImage::Format_RGB32, coreFormat);
|
||||
}
|
||||
#endif
|
||||
|
||||
void tst_LanceBench::setupTestSuite(const QStringList& blacklist)
|
||||
{
|
||||
QTest::addColumn<QString>("qpsFile");
|
||||
for (const QString &fileName : std::as_const(qpsFiles)) {
|
||||
if (blacklist.contains(fileName))
|
||||
continue;
|
||||
QTest::newRow(fileName.toLatin1()) << fileName;
|
||||
}
|
||||
}
|
||||
|
||||
void tst_LanceBench::runTestSuite(GraphicsEngine engine, QImage::Format format, const QSurfaceFormat &contextFormat)
|
||||
{
|
||||
QFETCH(QString, qpsFile);
|
||||
|
||||
QString filePath = scriptsDir + qpsFile;
|
||||
QStringList script = scripts.value(qpsFile);
|
||||
QImage rendered;
|
||||
|
||||
if (engine == Raster) {
|
||||
QImage img(800, 800, format);
|
||||
paint(&img, engine, format, script, QFileInfo(filePath).absoluteFilePath());
|
||||
rendered = img;
|
||||
#ifndef QT_NO_OPENGL
|
||||
} else if (engine == OpenGL) {
|
||||
QWindow win;
|
||||
win.setSurfaceType(QSurface::OpenGLSurface);
|
||||
win.setFormat(contextFormat);
|
||||
win.create();
|
||||
QOpenGLFramebufferObjectFormat fmt;
|
||||
fmt.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
|
||||
fmt.setSamples(4);
|
||||
QOpenGLContext ctx;
|
||||
ctx.setFormat(contextFormat);
|
||||
QVERIFY(ctx.create());
|
||||
QVERIFY(ctx.makeCurrent(&win));
|
||||
QOpenGLFramebufferObject fbo(800, 800, fmt);
|
||||
fbo.bind();
|
||||
QOpenGLPaintDevice pdv(800, 800);
|
||||
paint(&pdv, engine, format, script, QFileInfo(filePath).absoluteFilePath());
|
||||
rendered = fbo.toImage().convertToFormat(format);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void tst_LanceBench::paint(QPaintDevice *device, GraphicsEngine engine, QImage::Format format, const QStringList &script, const QString &filePath)
|
||||
{
|
||||
PaintCommands pcmd(script, 800, 800, format);
|
||||
switch (engine) {
|
||||
case OpenGL:
|
||||
pcmd.setType(OpenGLBufferType); // version/profile is communicated through the context's format()
|
||||
break;
|
||||
case Raster:
|
||||
pcmd.setType(ImageType);
|
||||
break;
|
||||
}
|
||||
pcmd.setFilePath(filePath);
|
||||
QBENCHMARK {
|
||||
QPainter p(device);
|
||||
pcmd.setPainter(&p);
|
||||
pcmd.runCommands();
|
||||
p.end();
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_LanceBench)
|
||||
|
||||
#include "tst_lancebench.moc"
|
15
tests/benchmarks/gui/painting/qcolor/CMakeLists.txt
Normal file
15
tests/benchmarks/gui/painting/qcolor/CMakeLists.txt
Normal file
@ -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
|
||||
)
|
37
tests/benchmarks/gui/painting/qcolor/tst_qcolor.cpp
Normal file
37
tests/benchmarks/gui/painting/qcolor/tst_qcolor.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
// 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 WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <qtest.h>
|
||||
#include <QColor>
|
||||
|
||||
|
||||
class tst_QColor : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void nameRgb();
|
||||
void nameArgb();
|
||||
};
|
||||
|
||||
void tst_QColor::nameRgb()
|
||||
{
|
||||
QColor color(128, 255, 10);
|
||||
QCOMPARE(color.name(), QStringLiteral("#80ff0a"));
|
||||
QBENCHMARK {
|
||||
color.name();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QColor::nameArgb()
|
||||
{
|
||||
QColor color(128, 255, 0, 102);
|
||||
QCOMPARE(color.name(QColor::HexArgb), QStringLiteral("#6680ff00"));
|
||||
QBENCHMARK {
|
||||
color.name(QColor::HexArgb);
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QColor)
|
||||
|
||||
#include "tst_qcolor.moc"
|
17
tests/benchmarks/gui/painting/qpainter/CMakeLists.txt
Normal file
17
tests/benchmarks/gui/painting/qpainter/CMakeLists.txt
Normal file
@ -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
|
||||
)
|
1665
tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp
Normal file
1665
tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp
Normal file
File diff suppressed because it is too large
Load Diff
14
tests/benchmarks/gui/painting/qregion/CMakeLists.txt
Normal file
14
tests/benchmarks/gui/painting/qregion/CMakeLists.txt
Normal file
@ -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
|
||||
)
|
101
tests/benchmarks/gui/painting/qregion/main.cpp
Normal file
101
tests/benchmarks/gui/painting/qregion/main.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
// This file contains benchmarks for QRegion functions.
|
||||
|
||||
#include <QDebug>
|
||||
#include <qtest.h>
|
||||
|
||||
class tst_qregion : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void map_data();
|
||||
void map();
|
||||
|
||||
void intersects_data();
|
||||
void intersects();
|
||||
};
|
||||
|
||||
|
||||
void tst_qregion::map_data()
|
||||
{
|
||||
QTest::addColumn<QRegion>("region");
|
||||
|
||||
{
|
||||
QRegion region(0, 0, 100, 100);
|
||||
QTest::newRow("single rect") << region;
|
||||
}
|
||||
{
|
||||
QRegion region;
|
||||
region = region.united(QRect(0, 0, 100, 100));
|
||||
region = region.united(QRect(120, 20, 100, 100));
|
||||
|
||||
QTest::newRow("two rects") << region;
|
||||
}
|
||||
{
|
||||
QRegion region(0, 0, 100, 100, QRegion::Ellipse);
|
||||
QTest::newRow("ellipse") << region;
|
||||
}
|
||||
}
|
||||
|
||||
void tst_qregion::map()
|
||||
{
|
||||
QFETCH(QRegion, region);
|
||||
|
||||
QTransform transform;
|
||||
transform.rotate(30);
|
||||
QBENCHMARK {
|
||||
transform.map(region);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_qregion::intersects_data()
|
||||
{
|
||||
QTest::addColumn<QRegion>("region");
|
||||
QTest::addColumn<QRect>("rect");
|
||||
|
||||
QRegion region(0, 0, 100, 100);
|
||||
QRegion complexRegion;
|
||||
complexRegion = complexRegion.united(QRect(0, 0, 100, 100));
|
||||
complexRegion = complexRegion.united(QRect(120, 20, 100, 100));
|
||||
|
||||
{
|
||||
QRect rect(0, 0, 100, 100);
|
||||
QTest::newRow("same -- simple") << region << rect;
|
||||
}
|
||||
{
|
||||
QRect rect(10, 10, 10, 10);
|
||||
QTest::newRow("inside -- simple") << region << rect;
|
||||
}
|
||||
{
|
||||
QRect rect(110, 110, 10, 10);
|
||||
QTest::newRow("outside -- simple") << region << rect;
|
||||
}
|
||||
|
||||
{
|
||||
QRect rect(0, 0, 100, 100);
|
||||
QTest::newRow("same -- complex") << complexRegion << rect;
|
||||
}
|
||||
{
|
||||
QRect rect(10, 10, 10, 10);
|
||||
QTest::newRow("inside -- complex") << complexRegion << rect;
|
||||
}
|
||||
{
|
||||
QRect rect(110, 110, 10, 10);
|
||||
QTest::newRow("outside -- complex") << complexRegion << rect;
|
||||
}
|
||||
}
|
||||
|
||||
void tst_qregion::intersects()
|
||||
{
|
||||
QFETCH(QRegion, region);
|
||||
QFETCH(QRect, rect);
|
||||
|
||||
QBENCHMARK {
|
||||
region.intersects(rect);
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_qregion)
|
||||
|
||||
#include "main.moc"
|
15
tests/benchmarks/gui/painting/qtbench/CMakeLists.txt
Normal file
15
tests/benchmarks/gui/painting/qtbench/CMakeLists.txt
Normal file
@ -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
|
||||
)
|
794
tests/benchmarks/gui/painting/qtbench/benchmarktests.h
Normal file
794
tests/benchmarks/gui/painting/qtbench/benchmarktests.h
Normal file
@ -0,0 +1,794 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#ifndef BENCHMARKTESTS_H
|
||||
#define BENCHMARKTESTS_H
|
||||
|
||||
#include <QApplication>
|
||||
#include <QTextDocument>
|
||||
#include <QTextLayout>
|
||||
#include <QFontMetrics>
|
||||
#include <QDebug>
|
||||
#include <QStaticText>
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
#include <QRandomGenerator>
|
||||
|
||||
class Benchmark
|
||||
{
|
||||
public:
|
||||
virtual ~Benchmark() {}
|
||||
|
||||
Benchmark(const QSize &size)
|
||||
: m_size(size)
|
||||
{
|
||||
for (int i=0; i<16; ++i) {
|
||||
m_colors[i] = QColor::fromRgbF((QRandomGenerator::global()->bounded(4)) / 3.0,
|
||||
(QRandomGenerator::global()->bounded(4)) / 3.0,
|
||||
(QRandomGenerator::global()->bounded(4)) / 3.0,
|
||||
1);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void draw(QPainter *p, const QRect &rect, int iteration) = 0;
|
||||
virtual QString name() const = 0;
|
||||
|
||||
inline const QSize &size() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
virtual void begin(QPainter *, int iterations = 1) { Q_UNUSED(iterations); }
|
||||
virtual void end(QPainter *) { }
|
||||
|
||||
inline const QColor &randomColor(int i) { return m_colors[i % 16]; }
|
||||
|
||||
protected:
|
||||
QColor m_colors[16];
|
||||
QSize m_size;
|
||||
};
|
||||
|
||||
class PaintingRectAdjuster
|
||||
{
|
||||
public:
|
||||
PaintingRectAdjuster()
|
||||
: m_benchmark(0),
|
||||
m_bounds(),
|
||||
m_screen_filled(false)
|
||||
{
|
||||
}
|
||||
|
||||
const QRect &newPaintingRect() {
|
||||
m_rect.translate(m_rect.width(), 0);
|
||||
|
||||
if (m_rect.right() > m_bounds.width()) {
|
||||
m_rect.moveLeft(m_bounds.left());
|
||||
m_rect.translate(0,m_rect.height());
|
||||
if (m_rect.bottom() > m_bounds.height()) {
|
||||
m_screen_filled = true;
|
||||
m_rect.moveTo(m_bounds.topLeft());
|
||||
}
|
||||
}
|
||||
return m_rect;
|
||||
}
|
||||
|
||||
inline bool isScreenFilled() const
|
||||
{ return m_screen_filled; }
|
||||
|
||||
void reset(const QRect &bounds)
|
||||
{
|
||||
m_bounds = bounds;
|
||||
m_rect.moveTo(m_bounds.topLeft());
|
||||
m_rect = QRect(m_bounds.topLeft(),m_benchmark->size());
|
||||
m_rect.translate(-m_rect.width(),0);
|
||||
m_screen_filled = false;
|
||||
}
|
||||
|
||||
inline void setNewBenchmark( Benchmark *benchmark )
|
||||
{
|
||||
m_benchmark = benchmark;
|
||||
}
|
||||
|
||||
protected:
|
||||
Benchmark *m_benchmark;
|
||||
QRect m_rect;
|
||||
QRect m_bounds;
|
||||
bool m_screen_filled;
|
||||
};
|
||||
|
||||
class FillRectBenchmark : public Benchmark
|
||||
{
|
||||
public:
|
||||
FillRectBenchmark(int size)
|
||||
: Benchmark(QSize(size, size))
|
||||
{
|
||||
}
|
||||
|
||||
void draw(QPainter *p, const QRect &rect, int iterationCount) override
|
||||
{
|
||||
p->fillRect(rect, randomColor(iterationCount));
|
||||
}
|
||||
|
||||
QString name() const override
|
||||
{
|
||||
return QString::fromLatin1("fillRect(%1)").arg(m_size.width());
|
||||
}
|
||||
};
|
||||
|
||||
class ImageFillRectBenchmark : public Benchmark
|
||||
{
|
||||
public:
|
||||
ImageFillRectBenchmark(int size)
|
||||
: Benchmark(QSize(size, size))
|
||||
{
|
||||
int s = QRandomGenerator::global()->bounded(24) + 8;
|
||||
m_content = QImage(s, s, QImage::Format_ARGB32_Premultiplied);
|
||||
QPainter p(&m_content);
|
||||
p.fillRect(0, 0, s, s, Qt::white);
|
||||
p.fillRect(s/2, 0, s/2, s/2, Qt::gray);
|
||||
p.fillRect(0, s/2, s/2, s/2, Qt::gray);
|
||||
p.end();
|
||||
|
||||
m_brush = QBrush(m_content);
|
||||
}
|
||||
|
||||
void draw(QPainter *p, const QRect &rect, int) override { p->fillRect(rect, m_brush); }
|
||||
|
||||
QString name() const override
|
||||
{
|
||||
return QString::fromLatin1("fillRect with image(%1)").arg(m_size.width());
|
||||
}
|
||||
|
||||
private:
|
||||
QImage m_content;
|
||||
QBrush m_brush;
|
||||
};
|
||||
|
||||
|
||||
class DrawRectBenchmark : public Benchmark
|
||||
{
|
||||
public:
|
||||
DrawRectBenchmark(int size)
|
||||
: Benchmark(QSize(size, size))
|
||||
{
|
||||
}
|
||||
|
||||
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); }
|
||||
|
||||
QString name() const override
|
||||
{
|
||||
return QString::fromLatin1("drawRect(%1)").arg(m_size.width());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class DrawRectWithBrushChangeBenchmark : public Benchmark
|
||||
{
|
||||
public:
|
||||
DrawRectWithBrushChangeBenchmark(int size)
|
||||
: Benchmark(QSize(size, size))
|
||||
{
|
||||
}
|
||||
|
||||
void begin(QPainter *p, int) override { p->setPen(Qt::NoPen); }
|
||||
|
||||
void draw(QPainter *p, const QRect &rect, int i) override
|
||||
{
|
||||
p->setBrush(randomColor(i));
|
||||
p->drawRect(rect);
|
||||
}
|
||||
|
||||
QString name() const override
|
||||
{
|
||||
return QString::fromLatin1("drawRect with brushchange(%1)").arg(m_size.width());
|
||||
}
|
||||
};
|
||||
|
||||
class RoundRectBenchmark : public Benchmark
|
||||
{
|
||||
public:
|
||||
RoundRectBenchmark(int size)
|
||||
: Benchmark(QSize(size, size))
|
||||
{
|
||||
m_roundness = size / 4.;
|
||||
}
|
||||
|
||||
void begin(QPainter *p, int) override
|
||||
{
|
||||
p->setPen(Qt::NoPen);
|
||||
p->setBrush(Qt::red);
|
||||
}
|
||||
|
||||
void draw(QPainter *p, const QRect &rect, int) override
|
||||
{
|
||||
p->drawRoundedRect(rect, m_roundness, m_roundness);
|
||||
}
|
||||
|
||||
QString name() const override
|
||||
{
|
||||
return QString::fromLatin1("drawRoundedRect(%1)").arg(m_size.width());
|
||||
}
|
||||
|
||||
qreal m_roundness;
|
||||
};
|
||||
|
||||
|
||||
class ArcsBenchmark : public Benchmark
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
Stroked = 0x0001,
|
||||
Filled = 0x0002,
|
||||
|
||||
ArcShape = 0x0010,
|
||||
ChordShape = 0x0020,
|
||||
PieShape = 0x0040,
|
||||
CircleShape = 0x0080,
|
||||
Shapes = 0x00f0
|
||||
|
||||
};
|
||||
|
||||
ArcsBenchmark(int size, uint type)
|
||||
: Benchmark(QSize(size, size)),
|
||||
m_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
void begin(QPainter *p, int) override
|
||||
{
|
||||
if (m_type & Stroked)
|
||||
p->setPen(Qt::black);
|
||||
else
|
||||
p->setPen(Qt::NoPen);
|
||||
|
||||
if (m_type & Filled)
|
||||
p->setBrush(Qt::red);
|
||||
else
|
||||
p->setBrush(Qt::NoBrush);
|
||||
}
|
||||
|
||||
void draw(QPainter *p, const QRect &rect, int) override
|
||||
{
|
||||
switch (m_type & Shapes) {
|
||||
case ArcShape:
|
||||
p->drawArc(rect, 45*16, 120*16);
|
||||
break;
|
||||
case ChordShape:
|
||||
p->drawChord(rect, 45*16, 120*16);
|
||||
break;
|
||||
case PieShape:
|
||||
p->drawPie(rect, 45*16, 120*16);
|
||||
break;
|
||||
case CircleShape:
|
||||
p->drawEllipse(rect);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QString name() const override
|
||||
{
|
||||
QString fillStroke;
|
||||
|
||||
if ((m_type & (Stroked|Filled)) == (Stroked|Filled)) {
|
||||
fillStroke = QLatin1String("Fill & Outline");
|
||||
} else if (m_type & Stroked) {
|
||||
fillStroke = QLatin1String("Outline");
|
||||
} else if (m_type & Filled) {
|
||||
fillStroke = QLatin1String("Fill");
|
||||
}
|
||||
|
||||
QString shape;
|
||||
if (m_type & PieShape) shape = QLatin1String("drawPie");
|
||||
else if (m_type & ChordShape) shape = QLatin1String("drawChord");
|
||||
else if (m_type & ArcShape) shape = QLatin1String("drawArc");
|
||||
else if (m_type & CircleShape) shape = QLatin1String("drawEllipse");
|
||||
|
||||
return QString::fromLatin1("%1(%2) %3").arg(shape).arg(m_size.width()).arg(fillStroke);
|
||||
}
|
||||
|
||||
uint m_type;
|
||||
};
|
||||
|
||||
|
||||
class DrawScaledImage : public Benchmark
|
||||
{
|
||||
public:
|
||||
DrawScaledImage(const QImage &image, qreal scale, bool asPixmap)
|
||||
: Benchmark(QSize(image.width(), image.height())),
|
||||
m_image(image),
|
||||
m_type(asPixmap ? "Pixmap" : "Image"),
|
||||
m_scale(scale),
|
||||
m_as_pixmap(asPixmap)
|
||||
{
|
||||
m_pixmap = QPixmap::fromImage(m_image);
|
||||
}
|
||||
DrawScaledImage(const QString& type, const QPixmap &pixmap, qreal scale)
|
||||
: Benchmark(QSize(pixmap.width(), pixmap.height())),
|
||||
m_type(type),
|
||||
m_scale(scale),
|
||||
m_as_pixmap(true),
|
||||
m_pixmap(pixmap)
|
||||
{
|
||||
}
|
||||
|
||||
void begin(QPainter *p, int) override { p->scale(m_scale, m_scale); }
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
QString m_type;
|
||||
qreal m_scale;
|
||||
bool m_as_pixmap;
|
||||
QPixmap m_pixmap;
|
||||
};
|
||||
|
||||
class DrawTransformedImage : public Benchmark
|
||||
{
|
||||
public:
|
||||
DrawTransformedImage(const QImage &image, bool asPixmap)
|
||||
: Benchmark(QSize(image.width(), image.height())),
|
||||
m_image(image),
|
||||
m_type(asPixmap ? "Pixmap" : "Image"),
|
||||
m_as_pixmap(asPixmap)
|
||||
{
|
||||
m_pixmap = QPixmap::fromImage(m_image);
|
||||
}
|
||||
DrawTransformedImage(const QString& type, const QPixmap &pixmap)
|
||||
: Benchmark(QSize(pixmap.width(), pixmap.height())),
|
||||
m_type(type),
|
||||
m_as_pixmap(true),
|
||||
m_pixmap(pixmap)
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
p->rotate(5.0);
|
||||
if (m_as_pixmap)
|
||||
p->drawPixmap(-0.5 * rect.width(), -0.5 * rect.height(), m_pixmap);
|
||||
else
|
||||
p->drawImage(-0.5 * rect.width(), -0.5 * rect.height(), m_image);
|
||||
p->setTransform(oldTransform);
|
||||
}
|
||||
|
||||
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;
|
||||
QString m_type;
|
||||
bool m_as_pixmap;
|
||||
QPixmap m_pixmap;
|
||||
};
|
||||
|
||||
|
||||
class DrawImage : public Benchmark
|
||||
{
|
||||
public:
|
||||
DrawImage(const QImage &image, bool asPixmap)
|
||||
: Benchmark(QSize(image.width(), image.height())),
|
||||
m_image(image),
|
||||
m_type(asPixmap ? "Pixmap" : "Image"),
|
||||
m_as_pixmap(asPixmap)
|
||||
{
|
||||
m_pixmap = QPixmap::fromImage(image);
|
||||
}
|
||||
DrawImage(const QString& type, const QPixmap &pixmap)
|
||||
: Benchmark(QSize(pixmap.width(), pixmap.height())),
|
||||
m_type(type),
|
||||
m_as_pixmap(true),
|
||||
m_pixmap(pixmap)
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
QString m_type;
|
||||
bool m_as_pixmap;
|
||||
QPixmap m_pixmap;
|
||||
};
|
||||
|
||||
|
||||
class DrawText : public Benchmark
|
||||
{
|
||||
public:
|
||||
enum Mode {
|
||||
PainterMode,
|
||||
PainterQPointMode,
|
||||
LayoutMode,
|
||||
DocumentMode,
|
||||
PixmapMode,
|
||||
StaticTextMode,
|
||||
StaticTextWithMaximumSizeMode,
|
||||
StaticTextBackendOptimizations
|
||||
};
|
||||
|
||||
DrawText(const QString &text, Mode mode)
|
||||
: Benchmark(QSize()), m_mode(mode), m_text(text), m_document(text), m_layout(text)
|
||||
{
|
||||
}
|
||||
|
||||
void begin(QPainter *p, int iterations) override
|
||||
{
|
||||
m_staticTexts.clear();
|
||||
m_currentStaticText = 0;
|
||||
m_pixmaps.clear();
|
||||
m_currentPixmap = 0;
|
||||
QRect m_bounds = QRect(0,0,p->device()->width(), p->device()->height());
|
||||
switch (m_mode) {
|
||||
case PainterMode:
|
||||
m_size = (p->boundingRect(m_bounds, 0, m_text)).size();
|
||||
// m_rect = m_rect.translated(-m_rect.topLeft());
|
||||
break;
|
||||
case DocumentMode:
|
||||
m_size = QSize(m_document.size().toSize());
|
||||
break;
|
||||
case PixmapMode:
|
||||
for (int i=0; i<4; ++i) {
|
||||
m_size = (p->boundingRect(m_bounds, 0, m_text)).size();
|
||||
QPixmap pixmap = QPixmap(m_size);
|
||||
pixmap.fill(Qt::transparent);
|
||||
{
|
||||
QPainter p(&pixmap);
|
||||
p.drawText(pixmap.rect(), m_text);
|
||||
}
|
||||
m_pixmaps.append(pixmap);
|
||||
}
|
||||
break;
|
||||
|
||||
case LayoutMode: {
|
||||
QRect r = p->boundingRect(m_bounds, 0, m_text);
|
||||
QStringList lines = m_text.split('\n');
|
||||
int height = 0;
|
||||
int leading = p->fontMetrics().leading();
|
||||
m_layout.beginLayout();
|
||||
for (int i=0; i<lines.size(); ++i) {
|
||||
QTextLine textLine = m_layout.createLine();
|
||||
if (textLine.isValid()) {
|
||||
textLine.setLineWidth(r.width());
|
||||
textLine.setPosition(QPointF(0, height));
|
||||
height += leading + textLine.height();
|
||||
}
|
||||
}
|
||||
m_layout.endLayout();
|
||||
m_layout.setCacheEnabled(true);
|
||||
m_size = m_layout.boundingRect().toRect().size();
|
||||
break; }
|
||||
|
||||
case StaticTextWithMaximumSizeMode: {
|
||||
QStaticText staticText;
|
||||
m_size = (p->boundingRect(m_bounds, 0, m_text)).size();
|
||||
staticText.setTextWidth(m_size.width() + 10);
|
||||
staticText.setText(m_text);
|
||||
staticText.prepare(p->transform(), p->font());
|
||||
m_staticTexts.append(staticText);
|
||||
break;
|
||||
}
|
||||
case StaticTextBackendOptimizations: {
|
||||
m_size = (p->boundingRect(m_bounds, 0, m_text)).size();
|
||||
for (int i=0; i<iterations; ++i) {
|
||||
QStaticText staticText;
|
||||
staticText.setPerformanceHint(QStaticText::AggressiveCaching);
|
||||
staticText.setTextWidth(m_size.width() + 10);
|
||||
staticText.setText(m_text);
|
||||
staticText.prepare(p->transform(), p->font());
|
||||
m_staticTexts.append(staticText);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case StaticTextMode: {
|
||||
QStaticText staticText;
|
||||
staticText.setText(m_text);
|
||||
staticText.prepare(p->transform(), p->font());
|
||||
m_staticTexts.append(staticText);
|
||||
|
||||
QFontMetrics fm(p->font());
|
||||
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.size()), fm.height());
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void draw(QPainter *p, const QRect &rect, int) override
|
||||
{
|
||||
switch (m_mode) {
|
||||
case PainterMode:
|
||||
p->drawText(rect, 0, m_text);
|
||||
break;
|
||||
case PainterQPointMode:
|
||||
p->drawText(rect.topLeft(), m_text);
|
||||
break;
|
||||
case PixmapMode:
|
||||
p->drawPixmap(rect.topLeft(), m_pixmaps.at(m_currentPixmap));
|
||||
m_currentPixmap = (m_currentPixmap + 1) % m_pixmaps.size();
|
||||
break;
|
||||
case DocumentMode:
|
||||
p->translate(rect.topLeft());
|
||||
m_document.drawContents(p);
|
||||
p->translate(-rect.topLeft());
|
||||
break;
|
||||
case LayoutMode:
|
||||
m_layout.draw(p, rect.topLeft());
|
||||
break;
|
||||
case StaticTextWithMaximumSizeMode:
|
||||
case StaticTextMode:
|
||||
p->drawStaticText(rect.topLeft(), m_staticTexts.at(0));
|
||||
break;
|
||||
case StaticTextBackendOptimizations:
|
||||
p->drawStaticText(rect.topLeft(), m_staticTexts.at(m_currentStaticText));
|
||||
m_currentStaticText = (m_currentStaticText + 1) % m_staticTexts.size();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QString name() const override
|
||||
{
|
||||
int letters = m_text.size();
|
||||
int lines = m_text.count('\n');
|
||||
if (lines == 0)
|
||||
lines = 1;
|
||||
QString type;
|
||||
switch (m_mode) {
|
||||
case PainterMode: type = "drawText(rect)"; break;
|
||||
case PainterQPointMode: type = "drawText(point)"; break;
|
||||
case LayoutMode: type = "layout.draw()"; break;
|
||||
case DocumentMode: type = "doc.drawContents()"; break;
|
||||
case PixmapMode: type = "pixmap cached text"; break;
|
||||
case StaticTextMode: type = "drawStaticText()"; break;
|
||||
case StaticTextWithMaximumSizeMode: type = "drawStaticText() w/ maxsize"; break;
|
||||
case StaticTextBackendOptimizations: type = "drawStaticText() w/ backend optimizations"; break;
|
||||
}
|
||||
|
||||
return QString::fromLatin1("%3, len=%1, lines=%2")
|
||||
.arg(letters)
|
||||
.arg(lines)
|
||||
.arg(type);
|
||||
}
|
||||
|
||||
private:
|
||||
Mode m_mode;
|
||||
QString m_text;
|
||||
QTextDocument m_document;
|
||||
QTextLayout m_layout;
|
||||
|
||||
QList<QPixmap> m_pixmaps;
|
||||
int m_currentPixmap;
|
||||
|
||||
int m_currentStaticText;
|
||||
QList<QStaticText> m_staticTexts;
|
||||
};
|
||||
|
||||
class ClippedDrawRectBenchmark : public Benchmark
|
||||
{
|
||||
public:
|
||||
enum ClipType {
|
||||
RectClip,
|
||||
TwoRectRegionClip,
|
||||
EllipseRegionClip,
|
||||
TwoRectPathClip,
|
||||
EllipsePathClip,
|
||||
AAEllipsePathClip,
|
||||
EllipseRegionThenRectClip,
|
||||
EllipsePathThenRectClip
|
||||
};
|
||||
|
||||
ClippedDrawRectBenchmark(int size, ClipType type)
|
||||
: Benchmark(QSize(size, size)), m_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
switch (m_type) {
|
||||
case RectClip:
|
||||
p->setClipRect(m_bounds.adjusted(1, 1, -1, -1));
|
||||
break;
|
||||
case TwoRectRegionClip:
|
||||
p->setClipRegion(QRegion(m_bounds.adjusted(0, 0, -1, -1))
|
||||
| QRegion(m_bounds.adjusted(1, 1, 0, 0)));
|
||||
break;
|
||||
case EllipseRegionClip:
|
||||
p->setClipRegion(QRegion(m_bounds, QRegion::Ellipse));
|
||||
break;
|
||||
case TwoRectPathClip:
|
||||
{
|
||||
QPainterPath path;
|
||||
path.addRect(m_bounds.adjusted(0, 0, -1, -1));
|
||||
path.addRect(m_bounds.adjusted(1, 1, 0, 0));
|
||||
path.setFillRule(Qt::WindingFill);
|
||||
p->setClipPath(path);
|
||||
}
|
||||
break;
|
||||
case EllipsePathClip:
|
||||
{
|
||||
QPainterPath path;
|
||||
path.addEllipse(m_bounds);
|
||||
p->setClipPath(path);
|
||||
}
|
||||
break;
|
||||
case AAEllipsePathClip:
|
||||
{
|
||||
QPainterPath path;
|
||||
path.addEllipse(m_bounds);
|
||||
p->setRenderHint(QPainter::Antialiasing);
|
||||
p->setClipPath(path);
|
||||
p->setRenderHint(QPainter::Antialiasing, false);
|
||||
}
|
||||
break;
|
||||
case EllipseRegionThenRectClip:
|
||||
p->setClipRegion(QRegion(m_bounds, QRegion::Ellipse));
|
||||
p->setClipRegion(QRegion(m_bounds.width() / 4,
|
||||
m_bounds.height() / 4,
|
||||
m_bounds.width() / 2,
|
||||
m_bounds.height() / 2), Qt::IntersectClip);
|
||||
break;
|
||||
case EllipsePathThenRectClip:
|
||||
{
|
||||
QPainterPath path;
|
||||
path.addEllipse(m_bounds);
|
||||
p->setClipPath(path);
|
||||
p->setClipRegion(QRegion(m_bounds.width() / 4,
|
||||
m_bounds.height() / 4,
|
||||
m_bounds.width() / 2,
|
||||
m_bounds.height() / 2), Qt::IntersectClip);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void draw(QPainter *p, const QRect &rect, int) override { p->drawRect(rect); }
|
||||
|
||||
QString name() const override
|
||||
{
|
||||
QString namedType;
|
||||
switch (m_type) {
|
||||
case RectClip:
|
||||
namedType = "rect";
|
||||
break;
|
||||
case TwoRectRegionClip:
|
||||
namedType = "two-rect-region";
|
||||
break;
|
||||
case EllipseRegionClip:
|
||||
namedType = "ellipse-region";
|
||||
break;
|
||||
case TwoRectPathClip:
|
||||
namedType = "two-rect-path";
|
||||
break;
|
||||
case EllipsePathClip:
|
||||
namedType = "ellipse-path";
|
||||
break;
|
||||
case AAEllipsePathClip:
|
||||
namedType = "aa-ellipse-path";
|
||||
break;
|
||||
case EllipseRegionThenRectClip:
|
||||
namedType = "ellipseregion&rect";
|
||||
break;
|
||||
case EllipsePathThenRectClip:
|
||||
namedType = "ellipsepath&rect";
|
||||
break;
|
||||
}
|
||||
return QString::fromLatin1("%1-clipped-drawRect(%2)").arg(namedType).arg(m_size.width());
|
||||
}
|
||||
|
||||
ClipType m_type;
|
||||
};
|
||||
|
||||
class LinesBenchmark : public Benchmark
|
||||
{
|
||||
public:
|
||||
enum LineType {
|
||||
Horizontal_Integer,
|
||||
Diagonal_Integer,
|
||||
Vertical_Integer,
|
||||
Horizontal_Float,
|
||||
Diagonal_Float,
|
||||
Vertical_Float
|
||||
};
|
||||
|
||||
LinesBenchmark(int length, LineType type)
|
||||
: Benchmark(QSize(qAbs(length), qAbs(length))),
|
||||
m_type(type),
|
||||
m_length(length)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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()));
|
||||
break;
|
||||
case Diagonal_Integer:
|
||||
p->drawLine(QLine(rect.x(), rect.y(), rect.x() + m_length, rect.y() + m_length));
|
||||
break;
|
||||
case Vertical_Integer:
|
||||
p->drawLine(QLine(rect.x() + 4, rect.y(), rect.x() + 4, rect.y() + m_length));
|
||||
break;
|
||||
case Horizontal_Float:
|
||||
p->drawLine(QLineF(rect.x(), rect.y(), rect.x() + m_length, rect.y()));
|
||||
break;
|
||||
case Diagonal_Float:
|
||||
p->drawLine(QLineF(rect.x(), rect.y(), rect.x() + m_length, rect.y() + m_length));
|
||||
break;
|
||||
case Vertical_Float:
|
||||
p->drawLine(QLineF(rect.x() + 4, rect.y(), rect.x() + 4, rect.y() + m_length));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QString name() const override
|
||||
{
|
||||
const char *names[] = {
|
||||
"Hor_I",
|
||||
"Diag_I",
|
||||
"Ver_I",
|
||||
"Hor_F",
|
||||
"Diag_F",
|
||||
"Ver_F"
|
||||
};
|
||||
return QString::fromLatin1("drawLine(size=%1,type=%2)").arg(m_length).arg(names[m_type]);
|
||||
}
|
||||
|
||||
LineType m_type;
|
||||
int m_length;
|
||||
};
|
||||
|
||||
#endif // BENCHMARKTESTS_H
|
214
tests/benchmarks/gui/painting/qtbench/tst_qtbench.cpp
Normal file
214
tests/benchmarks/gui/painting/qtbench/tst_qtbench.cpp
Normal file
@ -0,0 +1,214 @@
|
||||
// Copyright (C) 2020 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <qtest.h>
|
||||
|
||||
#include <QtCore/qmath.h>
|
||||
#include <QtCore/QElapsedTimer>
|
||||
#include <QtWidgets/QWidget>
|
||||
|
||||
#include "benchmarktests.h"
|
||||
|
||||
class BenchWidget : public QWidget
|
||||
{
|
||||
public:
|
||||
BenchWidget(Benchmark *benchmark);
|
||||
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
bool done() const { return m_done; }
|
||||
qreal result() const { return m_result; }
|
||||
|
||||
public:
|
||||
QElapsedTimer timer;
|
||||
|
||||
Benchmark *m_benchmark;
|
||||
|
||||
bool m_done;
|
||||
qreal m_result;
|
||||
|
||||
uint m_total;
|
||||
uint m_iteration;
|
||||
|
||||
QList<uint> iterationTimes;
|
||||
};
|
||||
|
||||
void BenchWidget::paintEvent(QPaintEvent *)
|
||||
{
|
||||
if (m_done)
|
||||
return;
|
||||
|
||||
QPainter p(this);
|
||||
|
||||
m_benchmark->begin(&p, 100);
|
||||
|
||||
PaintingRectAdjuster adjuster;
|
||||
adjuster.setNewBenchmark(m_benchmark);
|
||||
adjuster.reset(rect());
|
||||
|
||||
for (int i = 0; i < 100; ++i)
|
||||
m_benchmark->draw(&p, adjuster.newPaintingRect(), i);
|
||||
|
||||
m_benchmark->end(&p);
|
||||
|
||||
++m_iteration;
|
||||
|
||||
uint currentElapsed = timer.isValid() ? timer.elapsed() : 0;
|
||||
timer.restart();
|
||||
|
||||
m_total += currentElapsed;
|
||||
|
||||
// warm up for at most 5 iterations or half a second
|
||||
if (m_iteration >= 5 || m_total >= 500) {
|
||||
iterationTimes << currentElapsed;
|
||||
|
||||
if (iterationTimes.size() >= 5) {
|
||||
qreal mean = 0;
|
||||
qreal stddev = 0;
|
||||
uint min = INT_MAX;
|
||||
|
||||
for (int i = 0; i < iterationTimes.size(); ++i) {
|
||||
mean += iterationTimes.at(i);
|
||||
min = qMin(min, iterationTimes.at(i));
|
||||
}
|
||||
|
||||
mean /= qreal(iterationTimes.size());
|
||||
|
||||
for (int i = 0; i < iterationTimes.size(); ++i) {
|
||||
qreal delta = iterationTimes.at(i) - mean;
|
||||
stddev += delta * delta;
|
||||
}
|
||||
|
||||
stddev = qSqrt(stddev / iterationTimes.size());
|
||||
|
||||
stddev = 100 * stddev / mean;
|
||||
// do 50 iterations, break earlier if we spend more than 5 seconds or have a low std deviation after 2 seconds
|
||||
if (iterationTimes.size() >= 50 || m_total >= 5000 || (m_total >= 2000 && stddev < 4)) {
|
||||
m_result = min;
|
||||
m_done = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BenchWidget::BenchWidget(Benchmark *benchmark)
|
||||
: m_benchmark(benchmark)
|
||||
, m_done(false)
|
||||
, m_result(0)
|
||||
, m_total(0)
|
||||
, m_iteration(0)
|
||||
{
|
||||
setWindowTitle(benchmark->name());
|
||||
resize(640, 480);
|
||||
}
|
||||
|
||||
class tst_QtBench : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void qtBench();
|
||||
void qtBench_data();
|
||||
};
|
||||
|
||||
QString makeString(int length)
|
||||
{
|
||||
const char chars[] = "abcd efgh ijkl mnop qrst uvwx yz!$. ABCD 1234";
|
||||
const int len = int(strlen(chars));
|
||||
|
||||
QString ret;
|
||||
for (int j = 0; j < length; j++) {
|
||||
ret += QChar(chars[(j * 97) % len]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void tst_QtBench::qtBench_data()
|
||||
{
|
||||
QTest::addColumn<void *>("benchmark");
|
||||
|
||||
QString shortString = makeString(5);
|
||||
QString middleString = makeString(50);
|
||||
QString longString = makeString(35) + "\n"
|
||||
+ makeString(45) + "\n"
|
||||
+ makeString(75);
|
||||
QString superLongString = "Lorem ipsum dolor sit am\n"
|
||||
"et, consectetur adipisci\n"
|
||||
"ng elit. Integer mi leo,\n"
|
||||
"interdum ut congue at, p\n"
|
||||
"ulvinar et tellus. Quisq\n"
|
||||
"ue pretium eleifend laci\n"
|
||||
"nia. Ut semper gravida l\n"
|
||||
"ectus in commodo. Vestib\n"
|
||||
"ulum pharetra arcu in en\n"
|
||||
"im ultrices hendrerit. P\n"
|
||||
"ellentesque habitant mor\n"
|
||||
"bi tristique senectus et\n"
|
||||
"netus et malesuada fames\n"
|
||||
"ac turpis egestas. Ut er\n"
|
||||
"os sem, feugiat in eleme\n"
|
||||
"ntum in, porta sit amet \n"
|
||||
"neque. Fusce mi tellus, \n"
|
||||
"congue non dapibus eget,\n"
|
||||
"pharetra quis quam. Duis\n"
|
||||
"dui massa, pulvinar ac s\n"
|
||||
"odales pharetra, dictum \n"
|
||||
"in enim. Phasellus a nis\n"
|
||||
"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));
|
||||
benchmarks << (new DrawText(superLongString, DrawText::PainterMode));
|
||||
|
||||
benchmarks << (new DrawText(shortString, DrawText::PainterQPointMode));
|
||||
benchmarks << (new DrawText(middleString, DrawText::PainterQPointMode));
|
||||
benchmarks << (new DrawText(longString, DrawText::PainterQPointMode));
|
||||
benchmarks << (new DrawText(superLongString, DrawText::PainterQPointMode));
|
||||
|
||||
benchmarks << (new DrawText(shortString, DrawText::PixmapMode));
|
||||
benchmarks << (new DrawText(middleString, DrawText::PixmapMode));
|
||||
benchmarks << (new DrawText(longString, DrawText::PixmapMode));
|
||||
benchmarks << (new DrawText(superLongString, DrawText::PixmapMode));
|
||||
|
||||
benchmarks << (new DrawText(shortString, DrawText::StaticTextMode));
|
||||
benchmarks << (new DrawText(middleString, DrawText::StaticTextMode));
|
||||
benchmarks << (new DrawText(longString, DrawText::StaticTextMode));
|
||||
benchmarks << (new DrawText(superLongString, DrawText::StaticTextMode));
|
||||
|
||||
benchmarks << (new DrawText(shortString, DrawText::StaticTextWithMaximumSizeMode));
|
||||
benchmarks << (new DrawText(middleString, DrawText::StaticTextWithMaximumSizeMode));
|
||||
benchmarks << (new DrawText(longString, DrawText::StaticTextWithMaximumSizeMode));
|
||||
benchmarks << (new DrawText(superLongString, DrawText::StaticTextWithMaximumSizeMode));
|
||||
|
||||
benchmarks << (new DrawText(shortString, DrawText::StaticTextBackendOptimizations));
|
||||
benchmarks << (new DrawText(middleString, DrawText::StaticTextBackendOptimizations));
|
||||
benchmarks << (new DrawText(longString, DrawText::StaticTextBackendOptimizations));
|
||||
benchmarks << (new DrawText(superLongString, DrawText::StaticTextBackendOptimizations));
|
||||
|
||||
foreach (Benchmark *benchmark, benchmarks)
|
||||
QTest::newRow(qPrintable(benchmark->name())) << reinterpret_cast<void *>(benchmark);
|
||||
}
|
||||
|
||||
void tst_QtBench::qtBench()
|
||||
{
|
||||
QFETCH(void *, benchmark);
|
||||
|
||||
BenchWidget widget(reinterpret_cast<Benchmark *>(benchmark));
|
||||
widget.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&widget));
|
||||
|
||||
while (!widget.done()) {
|
||||
widget.update();
|
||||
QApplication::processEvents();
|
||||
}
|
||||
|
||||
QTest::setBenchmarkResult(widget.result(), QTest::WalltimeMilliseconds);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QtBench)
|
||||
#include "tst_qtbench.moc"
|
14
tests/benchmarks/gui/painting/qtransform/CMakeLists.txt
Normal file
14
tests/benchmarks/gui/painting/qtransform/CMakeLists.txt
Normal file
@ -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
|
||||
)
|
547
tests/benchmarks/gui/painting/qtransform/tst_qtransform.cpp
Normal file
547
tests/benchmarks/gui/painting/qtransform/tst_qtransform.cpp
Normal file
@ -0,0 +1,547 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <qtest.h>
|
||||
#include <QTransform>
|
||||
#include <QPainterPath>
|
||||
|
||||
class tst_QTransform : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
tst_QTransform();
|
||||
virtual ~tst_QTransform();
|
||||
|
||||
public slots:
|
||||
void init();
|
||||
void cleanup();
|
||||
|
||||
private slots:
|
||||
void construct();
|
||||
void translate_data();
|
||||
void translate();
|
||||
void scale_data();
|
||||
void scale();
|
||||
void shear_data();
|
||||
void shear();
|
||||
void rotate_data();
|
||||
void rotate();
|
||||
void rotateXYZ_data();
|
||||
void rotateXYZ();
|
||||
void operatorAssign_data();
|
||||
void operatorAssign();
|
||||
void operatorEqual_data();
|
||||
void operatorEqual();
|
||||
void operatorNotEqual_data();
|
||||
void operatorNotEqual();
|
||||
void operatorMultiply_data();
|
||||
void operatorMultiply();
|
||||
void operatorPlusEqualScalar_data();
|
||||
void operatorPlusEqualScalar();
|
||||
void operatorMinusEqualScalar_data();
|
||||
void operatorMinusEqualScalar();
|
||||
void operatorMultiplyEqual_data();
|
||||
void operatorMultiplyEqual();
|
||||
void operatorMultiplyEqualScalar_data();
|
||||
void operatorMultiplyEqualScalar();
|
||||
void operatorDivideEqualScalar_data();
|
||||
void operatorDivideEqualScalar();
|
||||
void mapQPoint_data();
|
||||
void mapQPoint();
|
||||
void mapQPointF_data();
|
||||
void mapQPointF();
|
||||
void mapRect_data();
|
||||
void mapRect();
|
||||
void mapRectF_data();
|
||||
void mapRectF();
|
||||
void mapQPolygon_data();
|
||||
void mapQPolygon();
|
||||
void mapQPolygonF_data();
|
||||
void mapQPolygonF();
|
||||
void mapQRegion_data();
|
||||
void mapQRegion();
|
||||
void mapToPolygon_data();
|
||||
void mapToPolygon();
|
||||
void mapQPainterPath_data();
|
||||
void mapQPainterPath();
|
||||
void isIdentity_data();
|
||||
void isIdentity();
|
||||
void isAffine_data();
|
||||
void isAffine();
|
||||
void isInvertible_data();
|
||||
void isInvertible();
|
||||
void isRotating_data();
|
||||
void isRotating();
|
||||
void isScaling_data();
|
||||
void isScaling();
|
||||
void isTranslating_data();
|
||||
void isTranslating();
|
||||
void type_data();
|
||||
void type();
|
||||
void determinant_data();
|
||||
void determinant();
|
||||
void adjoint_data();
|
||||
void adjoint();
|
||||
void transposed_data();
|
||||
void transposed();
|
||||
void inverted_data();
|
||||
void inverted();
|
||||
|
||||
private:
|
||||
QMap<const char *, QTransform> generateTransforms() const;
|
||||
};
|
||||
|
||||
tst_QTransform::tst_QTransform()
|
||||
{
|
||||
}
|
||||
|
||||
tst_QTransform::~tst_QTransform()
|
||||
{
|
||||
}
|
||||
|
||||
void tst_QTransform::init()
|
||||
{
|
||||
}
|
||||
|
||||
void tst_QTransform::cleanup()
|
||||
{
|
||||
}
|
||||
|
||||
QMap<const char *, QTransform> tst_QTransform::generateTransforms() const
|
||||
{
|
||||
QMap<const char *, QTransform> x;
|
||||
x["0: identity"] = QTransform();
|
||||
x["1: translate"] = QTransform().translate(10, 10);
|
||||
x["2: translate"] = QTransform().translate(-10, -10);
|
||||
x["3: rotate45"] = QTransform().rotate(45);
|
||||
x["4: rotate90"] = QTransform().rotate(90);
|
||||
x["5: rotate180"] = QTransform().rotate(180);
|
||||
x["6: shear2,2"] = QTransform().shear(2, 2);
|
||||
x["7: shear-2,-2"] = QTransform().shear(-2, -2);
|
||||
x["8: scaleUp2,2"] = QTransform().scale(2, 2);
|
||||
x["9: scaleUp2,3"] = QTransform().scale(2, 3);
|
||||
x["10: scaleDown0.5,0.5"] = QTransform().scale(0.5, 0.5);
|
||||
x["11: scaleDown0.5,0.25"] = QTransform().scale(0.5, 0.25);
|
||||
x["12: rotateX"] = QTransform().rotate(45, Qt::XAxis);
|
||||
x["13: rotateY"] = QTransform().rotate(45, Qt::YAxis);
|
||||
x["14: rotateXY"] = QTransform().rotate(45, Qt::XAxis).rotate(45, Qt::YAxis);
|
||||
x["15: rotateYZ"] = QTransform().rotate(45, Qt::YAxis).rotate(45, Qt::ZAxis);
|
||||
x["16: full"] = QTransform().translate(10, 10).rotate(45).shear(2, 2).scale(2, 2).rotate(45, Qt::YAxis).rotate(45, Qt::XAxis).rotate(45, Qt::ZAxis);
|
||||
return x;
|
||||
}
|
||||
|
||||
void tst_QTransform::construct()
|
||||
{
|
||||
QBENCHMARK {
|
||||
QTransform x;
|
||||
}
|
||||
}
|
||||
|
||||
#define SINGLE_DATA_IMPLEMENTATION(func) \
|
||||
void tst_QTransform::func##_data() \
|
||||
{ \
|
||||
QTest::addColumn<QTransform>("transform"); \
|
||||
QMap<const char *, QTransform> x = generateTransforms(); \
|
||||
for (auto it = x.begin(), end = x.end(); it != end; ++it) { \
|
||||
QTest::newRow(it.key()) << it.value(); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DOUBLE_DATA_IMPLEMENTATION(func) \
|
||||
void tst_QTransform::func##_data() \
|
||||
{ \
|
||||
QTest::addColumn<QTransform>("x1"); \
|
||||
QTest::addColumn<QTransform>("x2"); \
|
||||
QMap<const char *, QTransform> x = generateTransforms(); \
|
||||
for (auto it = x.cbegin(), end = x.cend(); it != end; ++it) { \
|
||||
const char *key1 = it.key(); \
|
||||
QTransform x1 = it.value(); \
|
||||
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(); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(translate)
|
||||
|
||||
void tst_QTransform::translate()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QTransform x = transform;
|
||||
QBENCHMARK {
|
||||
x.translate(10, 10);
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(scale)
|
||||
|
||||
void tst_QTransform::scale()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QTransform x = transform;
|
||||
QBENCHMARK {
|
||||
x.scale(2, 2);
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(shear)
|
||||
|
||||
void tst_QTransform::shear()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QTransform x = transform;
|
||||
QBENCHMARK {
|
||||
x.shear(2, 2);
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(rotate)
|
||||
|
||||
void tst_QTransform::rotate()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QTransform x = transform;
|
||||
QBENCHMARK {
|
||||
x.rotate(45);
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(rotateXYZ)
|
||||
|
||||
void tst_QTransform::rotateXYZ()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QTransform x = transform;
|
||||
QBENCHMARK {
|
||||
x.rotate(45, Qt::XAxis);
|
||||
x.rotate(45, Qt::YAxis);
|
||||
x.rotate(45, Qt::ZAxis);
|
||||
}
|
||||
}
|
||||
|
||||
DOUBLE_DATA_IMPLEMENTATION(operatorAssign)
|
||||
|
||||
void tst_QTransform::operatorAssign()
|
||||
{
|
||||
QFETCH(QTransform, x1);
|
||||
QFETCH(QTransform, x2);
|
||||
QTransform x = x1;
|
||||
QBENCHMARK {
|
||||
x = x2;
|
||||
}
|
||||
}
|
||||
|
||||
DOUBLE_DATA_IMPLEMENTATION(operatorEqual)
|
||||
|
||||
void tst_QTransform::operatorEqual()
|
||||
{
|
||||
QFETCH(QTransform, x1);
|
||||
QFETCH(QTransform, x2);
|
||||
QTransform x = x1;
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = x == x2;
|
||||
}
|
||||
}
|
||||
|
||||
DOUBLE_DATA_IMPLEMENTATION(operatorNotEqual)
|
||||
|
||||
void tst_QTransform::operatorNotEqual()
|
||||
{
|
||||
QFETCH(QTransform, x1);
|
||||
QFETCH(QTransform, x2);
|
||||
QTransform x = x1;
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = x != x2;
|
||||
}
|
||||
}
|
||||
|
||||
DOUBLE_DATA_IMPLEMENTATION(operatorMultiply)
|
||||
|
||||
void tst_QTransform::operatorMultiply()
|
||||
{
|
||||
QFETCH(QTransform, x1);
|
||||
QFETCH(QTransform, x2);
|
||||
QTransform x = x1;
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = x * x2;
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(operatorPlusEqualScalar)
|
||||
|
||||
void tst_QTransform::operatorPlusEqualScalar()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QTransform x = transform;
|
||||
QBENCHMARK {
|
||||
x += 3.14;
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(operatorMinusEqualScalar)
|
||||
|
||||
void tst_QTransform::operatorMinusEqualScalar()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QTransform x = transform;
|
||||
QBENCHMARK {
|
||||
x -= 3.14;
|
||||
}
|
||||
}
|
||||
|
||||
DOUBLE_DATA_IMPLEMENTATION(operatorMultiplyEqual)
|
||||
|
||||
void tst_QTransform::operatorMultiplyEqual()
|
||||
{
|
||||
QFETCH(QTransform, x1);
|
||||
QFETCH(QTransform, x2);
|
||||
QTransform x = x1;
|
||||
QBENCHMARK {
|
||||
x *= x2;
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(operatorMultiplyEqualScalar)
|
||||
|
||||
void tst_QTransform::operatorMultiplyEqualScalar()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QTransform x = transform;
|
||||
QBENCHMARK {
|
||||
x *= 3;
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(operatorDivideEqualScalar)
|
||||
|
||||
void tst_QTransform::operatorDivideEqualScalar()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QTransform x = transform;
|
||||
QBENCHMARK {
|
||||
x /= 3;
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(mapQPoint)
|
||||
|
||||
void tst_QTransform::mapQPoint()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QTransform x = transform;
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = x.map(QPoint(3, 3));
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(mapQPointF)
|
||||
|
||||
void tst_QTransform::mapQPointF()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QTransform x = transform;
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = x.map(QPointF(3, 3));
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(mapRect)
|
||||
|
||||
void tst_QTransform::mapRect()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QTransform x = transform;
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = x.mapRect(QRect(0, 0, 100, 100));
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(mapRectF)
|
||||
|
||||
void tst_QTransform::mapRectF()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QTransform x = transform;
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = x.mapRect(QRectF(0, 0, 100, 100));
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(mapQPolygon)
|
||||
|
||||
void tst_QTransform::mapQPolygon()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QTransform x = transform;
|
||||
QPolygon poly = QPolygon(QRect(0, 0, 100, 100));
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = x.map(poly);
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(mapQPolygonF)
|
||||
|
||||
void tst_QTransform::mapQPolygonF()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QTransform x = transform;
|
||||
QPolygonF poly = QPolygonF(QRectF(0, 0, 100, 100));
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = x.map(poly);
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(mapQRegion)
|
||||
|
||||
void tst_QTransform::mapQRegion()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QTransform x = transform;
|
||||
QRegion region;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
region += QRect(i * 10, i * 10, 100, 100);
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = x.map(region);
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(mapToPolygon)
|
||||
|
||||
void tst_QTransform::mapToPolygon()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QTransform x = transform;
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = x.mapToPolygon(QRect(0, 0, 100, 100));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(mapQPainterPath)
|
||||
|
||||
void tst_QTransform::mapQPainterPath()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QTransform x = transform;
|
||||
QPainterPath path;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
path.addEllipse(i * 10, i * 10, 100, 100);
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = x.map(path);
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(isIdentity)
|
||||
|
||||
void tst_QTransform::isIdentity()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = transform.isIdentity();
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(isAffine)
|
||||
|
||||
void tst_QTransform::isAffine()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = transform.isAffine();
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(isInvertible)
|
||||
|
||||
void tst_QTransform::isInvertible()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = transform.isInvertible();
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(isRotating)
|
||||
|
||||
void tst_QTransform::isRotating()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = transform.isRotating();
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(isScaling)
|
||||
|
||||
void tst_QTransform::isScaling()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = transform.isScaling();
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(isTranslating)
|
||||
|
||||
void tst_QTransform::isTranslating()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = transform.isTranslating();
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(type)
|
||||
|
||||
void tst_QTransform::type()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = transform.type();
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(determinant)
|
||||
|
||||
void tst_QTransform::determinant()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QBENCHMARK {
|
||||
[[maybe_unused]] auto r = transform.determinant();
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(adjoint)
|
||||
|
||||
void tst_QTransform::adjoint()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QBENCHMARK {
|
||||
Q_UNUSED(transform.adjoint())
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(transposed)
|
||||
|
||||
void tst_QTransform::transposed()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QBENCHMARK {
|
||||
Q_UNUSED(transform.transposed())
|
||||
}
|
||||
}
|
||||
|
||||
SINGLE_DATA_IMPLEMENTATION(inverted)
|
||||
|
||||
void tst_QTransform::inverted()
|
||||
{
|
||||
QFETCH(QTransform, transform);
|
||||
QBENCHMARK {
|
||||
Q_UNUSED(transform.inverted())
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QTransform)
|
||||
#include "tst_qtransform.moc"
|
Reference in New Issue
Block a user