tests/benchmarks/gui/image/qpixmap/tst_qpixmap.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
child 33 3e2da88830cd
--- a/tests/benchmarks/gui/image/qpixmap/tst_qpixmap.cpp	Wed Jun 23 19:07:03 2010 +0300
+++ b/tests/benchmarks/gui/image/qpixmap/tst_qpixmap.cpp	Tue Jul 06 15:10:48 2010 +0300
@@ -43,6 +43,7 @@
 #include <QPixmap>
 #include <QBitmap>
 #include <QPainter>
+#include <private/qpixmap_raster_p.h>
 
 class tst_QPixmap : public QObject
 {
@@ -67,6 +68,31 @@
 Q_DECLARE_METATYPE(Qt::AspectRatioMode)
 Q_DECLARE_METATYPE(Qt::TransformationMode)
 
+QPixmap rasterPixmap(int width, int height)
+{
+    QPixmapData *data =
+        new QRasterPixmapData(QPixmapData::PixmapType);
+
+    data->resize(width, height);
+
+    return QPixmap(data);
+}
+
+QPixmap rasterPixmap(const QSize &size)
+{
+    return rasterPixmap(size.width(), size.height());
+}
+
+QPixmap rasterPixmap(const QImage &image)
+{
+    QPixmapData *data =
+        new QRasterPixmapData(QPixmapData::PixmapType);
+
+    data->fromImage(image, Qt::AutoColor);
+
+    return QPixmap(data);
+}
+
 tst_QPixmap::tst_QPixmap()
 {
 }
@@ -90,7 +116,7 @@
     QFETCH(int, height);
 
     const QColor color = opaque ? QColor(255, 0, 0) : QColor(255, 0, 0, 200);
-    QPixmap pixmap(width, height);
+    QPixmap pixmap = rasterPixmap(width, height);
 
     QBENCHMARK {
         pixmap.fill(color);
@@ -126,8 +152,8 @@
     QFETCH(Qt::AspectRatioMode, ratioMode);
     QFETCH(Qt::TransformationMode, transformMode);
 
-    QPixmap opaque(size);
-    QPixmap transparent(size);
+    QPixmap opaque = rasterPixmap(size);
+    QPixmap transparent = rasterPixmap(size);
     opaque.fill(QColor(255, 0, 0));
     transparent.fill(QColor(255, 0, 0, 200));
 
@@ -180,8 +206,8 @@
     QFETCH(QTransform, transform);
     QFETCH(Qt::TransformationMode, transformMode);
 
-    QPixmap opaque(size);
-    QPixmap transparent(size);
+    QPixmap opaque = rasterPixmap(size);
+    QPixmap transparent = rasterPixmap(size);
     opaque.fill(QColor(255, 0, 0));
     transparent.fill(QColor(255, 0, 0, 200));
 
@@ -209,7 +235,7 @@
 {
     QFETCH(QSize, size);
 
-    QPixmap src(size);
+    QPixmap src = rasterPixmap(size);
     src.fill(Qt::transparent);
     {
         QPainter p(&src);