summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/qgraphicsview
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@nokia.com>2009-05-11 14:29:14 (GMT)
committerAlexis Menard <alexis.menard@nokia.com>2009-05-11 14:29:14 (GMT)
commit23b5d04f75766fb2046007881c90e00855eee7c8 (patch)
tree7b4fbff8e7064820d7efd526548782cf93c76764 /tests/benchmarks/qgraphicsview
parent759c265d4e12d41add52880f3738d037ecce5215 (diff)
downloadQt-23b5d04f75766fb2046007881c90e00855eee7c8.zip
Qt-23b5d04f75766fb2046007881c90e00855eee7c8.tar.gz
Qt-23b5d04f75766fb2046007881c90e00855eee7c8.tar.bz2
Add a benchmark to measure performance on QGV with caching.
This commit add an benchmark to allow testing performance with cache enable or not. It covers different use cases with item rotating, moving and so on. Reviewed-by:bnilsen
Diffstat (limited to 'tests/benchmarks/qgraphicsview')
-rw-r--r--tests/benchmarks/qgraphicsview/images/wine.jpegbin0 -> 2265 bytes
-rw-r--r--tests/benchmarks/qgraphicsview/qgraphicsview.qrc1
-rw-r--r--tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp109
3 files changed, 110 insertions, 0 deletions
diff --git a/tests/benchmarks/qgraphicsview/images/wine.jpeg b/tests/benchmarks/qgraphicsview/images/wine.jpeg
new file mode 100644
index 0000000..8fe1d3a
--- /dev/null
+++ b/tests/benchmarks/qgraphicsview/images/wine.jpeg
Binary files differ
diff --git a/tests/benchmarks/qgraphicsview/qgraphicsview.qrc b/tests/benchmarks/qgraphicsview/qgraphicsview.qrc
index 9f280dd..5e80029 100644
--- a/tests/benchmarks/qgraphicsview/qgraphicsview.qrc
+++ b/tests/benchmarks/qgraphicsview/qgraphicsview.qrc
@@ -1,6 +1,7 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>images/designer.png</file>
+ <file>images/wine.jpeg</file>
<file>random.data</file>
</qresource>
</RCC>
diff --git a/tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp b/tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp
index d2213f4..a293de4 100644
--- a/tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp
@@ -122,6 +122,8 @@ private slots:
void imageRiver();
void textRiver_data();
void textRiver();
+ void moveItemCache_data();
+ void moveItemCache();
};
tst_QGraphicsView::tst_QGraphicsView()
@@ -688,5 +690,112 @@ void tst_QGraphicsView::textRiver()
}
}
+class AnimatedPixmapCacheItem : public QGraphicsPixmapItem
+{
+public:
+ AnimatedPixmapCacheItem(int x, int y, QGraphicsItem *parent = 0)
+ : QGraphicsPixmapItem(parent)
+ {
+ xspeed = x;
+ yspeed = y;
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0)
+ {
+ QGraphicsPixmapItem::paint(painter,option,widget);
+ //We just want to wait, and we don't want to process the event loop with qWait
+ QTest::qSleep(3);
+
+ }
+protected:
+ void advance(int i)
+ {
+ if (!i)
+ return;
+ int x = int(pos().x()) + pixmap().width();
+ x += xspeed;
+ x = (x % (300 + pixmap().width() * 2)) - pixmap().width();
+ int y = int(pos().y()) + pixmap().width();
+ y += yspeed;
+ y = (y % (300 + pixmap().width() * 2)) - pixmap().width();
+ setPos(x, y);
+ }
+
+private:
+ int xspeed;
+ int yspeed;
+};
+
+void tst_QGraphicsView::moveItemCache_data()
+{
+ QTest::addColumn<int>("direction");
+ QTest::addColumn<bool>("rotation");
+ QTest::addColumn<int>("cacheMode");
+ QTest::newRow("Horizontal movement : ItemCoordinate Cache") << 0 << false << (int)QGraphicsItem::ItemCoordinateCache;
+ QTest::newRow("Horizontal movement : DeviceCoordinate Cache") << 0 << false << (int)QGraphicsItem::DeviceCoordinateCache;
+ QTest::newRow("Horizontal movement : No Cache") << 0 << false << (int)QGraphicsItem::NoCache;
+ QTest::newRow("Vertical + Horizontal movement : ItemCoordinate Cache") << 2 << false << (int)QGraphicsItem::ItemCoordinateCache;
+ QTest::newRow("Vertical + Horizontal movement : DeviceCoordinate Cache") << 2 << false << (int)QGraphicsItem::DeviceCoordinateCache;
+ QTest::newRow("Vertical + Horizontal movement : No Cache") << 2 << false << (int)QGraphicsItem::NoCache;
+ QTest::newRow("Horizontal movement + Rotation : ItemCoordinate Cache") << 0 << true << (int)QGraphicsItem::ItemCoordinateCache;
+ QTest::newRow("Horizontal movement + Rotation : DeviceCoordinate Cache") << 0 << true << (int)QGraphicsItem::DeviceCoordinateCache;
+ QTest::newRow("Horizontal movement + Rotation : No Cache") << 0 << true << (int)QGraphicsItem::NoCache;
+}
+
+void tst_QGraphicsView::moveItemCache()
+{
+ QFETCH(int, direction);
+ QFETCH(bool, rotation);
+ QFETCH(int, cacheMode);
+
+ QGraphicsScene scene(0, 0, 300, 300);
+
+ CountPaintEventView view(&scene);
+ view.resize(600, 600);
+ view.setFrameStyle(0);
+ view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ view.show();
+
+ QPixmap pix(":/images/wine.jpeg");
+ QVERIFY(!pix.isNull());
+
+ QList<QGraphicsItem *> items;
+ QFile file(":/random.data");
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QDataStream str(&file);
+ for (int i = 0; i < 50; ++i) {
+ AnimatedPixmapCacheItem *item;
+ if (direction == 0) item = new AnimatedPixmapCacheItem((i % 4) + 1, 0);
+ if (direction == 1) item = new AnimatedPixmapCacheItem(0, (i % 4) + 1);
+ if (direction == 2) item = new AnimatedPixmapCacheItem((i % 4) + 1, (i % 4) + 1);
+ item->setPixmap(pix);
+ item->setCacheMode((QGraphicsItem::CacheMode)cacheMode);
+ if (rotation)
+ item->setTransform(QTransform().rotate(45));
+ int rnd1, rnd2;
+ str >> rnd1 >> rnd2;
+ item->setPos(-pix.width() + rnd1 % (view.width() + pix.width()),
+ -pix.height() + rnd2 % (view.height() + pix.height()));
+ scene.addItem(item);
+ }
+
+ view.count = 0;
+
+ QBENCHMARK {
+#ifdef CALLGRIND_DEBUG
+ CALLGRIND_START_INSTRUMENTATION
+#endif
+ for (int i = 0; i < 100; ++i) {
+ scene.advance();
+ while (view.count < (i+1))
+ qApp->processEvents();
+ }
+#ifdef CALLGRIND_DEBUG
+ CALLGRIND_STOP_INSTRUMENTATION
+#endif
+ }
+}
+
QTEST_MAIN(tst_QGraphicsView)
#include "tst_qgraphicsview.moc"