From efe3909d4ebfc08384a3762635b4217f18eeaf69 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 19 Feb 2010 09:46:03 +1000 Subject: Add pixmap benchmarks and make cached rounded rect the same as Rectangle. --- .../benchmarks/declarative/painting/data/63x63.png | Bin 0 -> 3077 bytes .../declarative/painting/data/63x63_opaque.png | Bin 0 -> 3440 bytes .../benchmarks/declarative/painting/data/64x64.png | Bin 0 -> 3101 bytes .../declarative/painting/data/64x64_opaque.png | Bin 0 -> 3588 bytes .../declarative/painting/paintbenchmark.cpp | 116 ++++++++++++++++++--- 5 files changed, 102 insertions(+), 14 deletions(-) create mode 100644 tests/benchmarks/declarative/painting/data/63x63.png create mode 100644 tests/benchmarks/declarative/painting/data/63x63_opaque.png create mode 100644 tests/benchmarks/declarative/painting/data/64x64.png create mode 100644 tests/benchmarks/declarative/painting/data/64x64_opaque.png diff --git a/tests/benchmarks/declarative/painting/data/63x63.png b/tests/benchmarks/declarative/painting/data/63x63.png new file mode 100644 index 0000000..d9efda8 Binary files /dev/null and b/tests/benchmarks/declarative/painting/data/63x63.png differ diff --git a/tests/benchmarks/declarative/painting/data/63x63_opaque.png b/tests/benchmarks/declarative/painting/data/63x63_opaque.png new file mode 100644 index 0000000..d142908 Binary files /dev/null and b/tests/benchmarks/declarative/painting/data/63x63_opaque.png differ diff --git a/tests/benchmarks/declarative/painting/data/64x64.png b/tests/benchmarks/declarative/painting/data/64x64.png new file mode 100644 index 0000000..b149f33 Binary files /dev/null and b/tests/benchmarks/declarative/painting/data/64x64.png differ diff --git a/tests/benchmarks/declarative/painting/data/64x64_opaque.png b/tests/benchmarks/declarative/painting/data/64x64_opaque.png new file mode 100644 index 0000000..94c07f3 Binary files /dev/null and b/tests/benchmarks/declarative/painting/data/64x64_opaque.png differ diff --git a/tests/benchmarks/declarative/painting/paintbenchmark.cpp b/tests/benchmarks/declarative/painting/paintbenchmark.cpp index d6a873c..8452bed 100644 --- a/tests/benchmarks/declarative/painting/paintbenchmark.cpp +++ b/tests/benchmarks/declarative/painting/paintbenchmark.cpp @@ -60,6 +60,7 @@ const int spacing = 36; QSizeF size(1000, 800); const qreal lineWidth = 1000; QString strings[lines]; +QGLWidget *testWidget = 0; void paint_QTextLayout(QPainter &p, bool useCache) { @@ -160,6 +161,15 @@ void paint_QPixmapCachedText(QPainter &p) void paint_RoundedRect(QPainter &p) { + static bool first = true; + if (first) { + if (testWidget) { + QGLFormat format = testWidget->format(); + if (!format.sampleBuffers()) + qWarning() << "Cannot paint antialiased rounded rect without sampleBuffers"; + } + first = false; + } p.setRenderHint(QPainter::Antialiasing, true); p.setPen(Qt::black); p.setBrush(Qt::red); @@ -174,27 +184,101 @@ void paint_RoundedRect(QPainter &p) void paint_QPixmapCachedRoundedRect(QPainter &p) { static bool first = true; - static QPixmap cacheRect[lines]; + static QPixmap cacheRect; if (first) { - for (int i = 0; i < lines; ++i) { - QSize size((i+1)*50, spacing-1); - cacheRect[i] = QPixmap(size); - cacheRect[i].fill(Qt::transparent); - QPainter paint(&cacheRect[i]); - paint.setRenderHint(QPainter::Antialiasing); - paint.setPen(Qt::black); - paint.setBrush(Qt::red); - paint.drawRoundedRect(QRect(QPoint(0,0), size), 8, 8); + const int pw = 0; + const int radius = 8; + cacheRect = QPixmap(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2); + cacheRect.fill(Qt::transparent); + QPainter paint(&cacheRect); + paint.setRenderHint(QPainter::Antialiasing); + paint.setPen(Qt::black); + paint.setBrush(Qt::red); + if (pw%2) + paint.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, cacheRect.width()-(pw+1), cacheRect.height()-(pw+1)), radius, radius); + else + paint.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, cacheRect.width()-pw, cacheRect.height()-pw), radius, radius); + + first = false; + } + for (int i = 0; i < count; i++) { + for (int j = 0; j < lines; ++j) { + QSize size((j+1)*50, spacing-1); + + p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, true); + + const int pw = 0; + + int xOffset = (cacheRect.width()-1)/2; + int yOffset = (cacheRect.height()-1)/2; + + QMargins margins(xOffset, yOffset, xOffset, yOffset); + QTileRules rules(Qt::StretchTile, Qt::StretchTile); + //NOTE: even though our item may have qreal-based width and height, qDrawBorderPixmap only supports QRects + qDrawBorderPixmap(&p, QRect(-pw/2, j*spacing-pw/2, size.width()+pw, size.height()+pw), margins, cacheRect, cacheRect.rect(), margins, rules); + } + } +} + +void paint_QPixmap63x63_opaque(QPainter &p) +{ + static bool first = true; + static QPixmap pm; + if (first) { + pm.load("data/63x63_opaque.png"); + first = false; + } + for (int i = 0; i < count; i++) { + for (int j = 0; j < lines; ++j) { + p.drawPixmap((i%10) * 64,j*spacing, pm); + } + } +} + +void paint_QPixmap64x64_opaque(QPainter &p) +{ + static bool first = true; + static QPixmap pm; + if (first) { + pm.load("data/64x64_opaque.png"); + first = false; + } + for (int i = 0; i < count; i++) { + for (int j = 0; j < lines; ++j) { + p.drawPixmap((i%10) * 64,j*spacing, pm); } + } +} + +void paint_QPixmap63x63(QPainter &p) +{ + static bool first = true; + static QPixmap pm; + if (first) { + pm.load("data/63x63.png"); first = false; } for (int i = 0; i < count; i++) { for (int j = 0; j < lines; ++j) { - p.drawPixmap(0,j*spacing,cacheRect[j]); + p.drawPixmap((i%10) * 64,j*spacing, pm); } } } +void paint_QPixmap64x64(QPainter &p) +{ + static bool first = true; + static QPixmap pm; + if (first) { + pm.load("data/64x64.png"); + first = false; + } + for (int i = 0; i < count; i++) { + for (int j = 0; j < lines; ++j) { + p.drawPixmap((i%10) * 64,j*spacing, pm); + } + } +} typedef void(*PaintFunc)(QPainter &); struct { @@ -210,6 +294,10 @@ struct { { "CachedText", &paint_QPixmapCachedText }, { "RoundedRect", &paint_RoundedRect }, { "CachedRoundedRect", &paint_QPixmapCachedRoundedRect }, + { "QPixmap63x63_opaque", &paint_QPixmap63x63_opaque }, + { "QPixmap64x64_opaque", &paint_QPixmap64x64_opaque }, + { "QPixmap63x63", &paint_QPixmap63x63 }, + { "QPixmap64x64", &paint_QPixmap64x64 }, { 0, 0 } }; @@ -297,11 +385,11 @@ int main(int argc, char *argv[]) QWidget w; QGLFormat format = QGLFormat::defaultFormat(); format.setSampleBuffers(sampleBuffers); - MyGLWidget *glw = new MyGLWidget(format); - glw->setAutoFillBackground(false); + testWidget = new MyGLWidget(format); + testWidget->setAutoFillBackground(false); QVBoxLayout *layout = new QVBoxLayout(&w); w.setLayout(layout); - layout->addWidget(glw); + layout->addWidget(testWidget); w.showFullScreen(); app.exec(); -- cgit v0.12