summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-02-18 23:46:03 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-02-18 23:46:03 (GMT)
commitefe3909d4ebfc08384a3762635b4217f18eeaf69 (patch)
treef4a16ae14a3a1c46b65c37b3c0cd6be174855fc9 /tests/benchmarks
parent47fb252279aa88631412a7422de0a30f40b96c17 (diff)
downloadQt-efe3909d4ebfc08384a3762635b4217f18eeaf69.zip
Qt-efe3909d4ebfc08384a3762635b4217f18eeaf69.tar.gz
Qt-efe3909d4ebfc08384a3762635b4217f18eeaf69.tar.bz2
Add pixmap benchmarks and make cached rounded rect the same as Rectangle.
Diffstat (limited to 'tests/benchmarks')
-rw-r--r--tests/benchmarks/declarative/painting/data/63x63.pngbin0 -> 3077 bytes
-rw-r--r--tests/benchmarks/declarative/painting/data/63x63_opaque.pngbin0 -> 3440 bytes
-rw-r--r--tests/benchmarks/declarative/painting/data/64x64.pngbin0 -> 3101 bytes
-rw-r--r--tests/benchmarks/declarative/painting/data/64x64_opaque.pngbin0 -> 3588 bytes
-rw-r--r--tests/benchmarks/declarative/painting/paintbenchmark.cpp116
5 files changed, 102 insertions, 14 deletions
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
--- /dev/null
+++ b/tests/benchmarks/declarative/painting/data/63x63.png
Binary files 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
--- /dev/null
+++ b/tests/benchmarks/declarative/painting/data/63x63_opaque.png
Binary files 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
--- /dev/null
+++ b/tests/benchmarks/declarative/painting/data/64x64.png
Binary files 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
--- /dev/null
+++ b/tests/benchmarks/declarative/painting/data/64x64_opaque.png
Binary files 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();