summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/benchmarks/qgraphicsview/images/wine-big.jpegbin0 -> 12249 bytes
-rw-r--r--tests/benchmarks/qgraphicsview/qgraphicsview.qrc1
-rw-r--r--tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp102
3 files changed, 103 insertions, 0 deletions
diff --git a/tests/benchmarks/qgraphicsview/images/wine-big.jpeg b/tests/benchmarks/qgraphicsview/images/wine-big.jpeg
new file mode 100644
index 0000000..9900a50
--- /dev/null
+++ b/tests/benchmarks/qgraphicsview/images/wine-big.jpeg
Binary files differ
diff --git a/tests/benchmarks/qgraphicsview/qgraphicsview.qrc b/tests/benchmarks/qgraphicsview/qgraphicsview.qrc
index 5e80029..3681648 100644
--- a/tests/benchmarks/qgraphicsview/qgraphicsview.qrc
+++ b/tests/benchmarks/qgraphicsview/qgraphicsview.qrc
@@ -2,6 +2,7 @@
<qresource>
<file>images/designer.png</file>
<file>images/wine.jpeg</file>
+ <file>images/wine-big.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 a06e033..570f744 100644
--- a/tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp
@@ -124,6 +124,8 @@ private slots:
void textRiver();
void moveItemCache_data();
void moveItemCache();
+ void paintItemCache_data();
+ void paintItemCache();
};
tst_QGraphicsView::tst_QGraphicsView()
@@ -796,5 +798,105 @@ void tst_QGraphicsView::moveItemCache()
}
}
+class UpdatedPixmapCacheItem : public QGraphicsPixmapItem
+{
+public:
+ UpdatedPixmapCacheItem(bool partial, QGraphicsItem *parent = 0)
+ : QGraphicsPixmapItem(parent), partial(partial)
+ {
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0)
+ {
+ QGraphicsPixmapItem::paint(painter,option,widget);
+ }
+protected:
+ void advance(int i)
+ {
+ if (partial)
+ update(QRectF(boundingRect().center().x(), boundingRect().center().x(), 30, 30));
+ else
+ update();
+ }
+
+private:
+ bool partial;
+};
+
+void tst_QGraphicsView::paintItemCache_data()
+{
+ QTest::addColumn<bool>("updatePartial");
+ QTest::addColumn<bool>("rotation");
+ QTest::addColumn<int>("cacheMode");
+ QTest::newRow("Partial Update : ItemCoordinate Cache") << true << false << (int)QGraphicsItem::ItemCoordinateCache;
+ QTest::newRow("Partial Update : DeviceCoordinate Cache") << true << false << (int)QGraphicsItem::DeviceCoordinateCache;
+ QTest::newRow("Partial Update : No Cache") << true << false << (int)QGraphicsItem::NoCache;
+ QTest::newRow("Full Update : ItemCoordinate Cache") << false << false << (int)QGraphicsItem::ItemCoordinateCache;
+ QTest::newRow("Full Update : DeviceCoordinate Cache") << false << false << (int)QGraphicsItem::DeviceCoordinateCache;
+ QTest::newRow("Full Update : No Cache") << false << false << (int)QGraphicsItem::NoCache;
+ QTest::newRow("Partial Update : ItemCoordinate Cache item rotated") << true << true << (int)QGraphicsItem::ItemCoordinateCache;
+ QTest::newRow("Partial Update : DeviceCoordinate Cache item rotated") << true << true << (int)QGraphicsItem::DeviceCoordinateCache;
+ QTest::newRow("Partial Update : No Cache item rotated") << true << true << (int)QGraphicsItem::NoCache;
+ QTest::newRow("Full Update : ItemCoordinate Cache item rotated") << false << true << (int)QGraphicsItem::ItemCoordinateCache;
+ QTest::newRow("Full Update : DeviceCoordinate Cache item rotated") << false << true << (int)QGraphicsItem::DeviceCoordinateCache;
+ QTest::newRow("Full Update : No Cache item rotated") << false << true <<(int)QGraphicsItem::NoCache;
+}
+
+void tst_QGraphicsView::paintItemCache()
+{
+ QFETCH(bool, updatePartial);
+ 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);
+ UpdatedPixmapCacheItem *item = new UpdatedPixmapCacheItem(updatePartial);
+ item->setPixmap(pix);
+ item->setCacheMode((QGraphicsItem::CacheMode)cacheMode);
+ if (rotation)
+ item->setTransform(QTransform().rotate(45));
+ item->setPos(-100, -100);
+ scene.addItem(item);
+
+ QPixmap pix2(":/images/wine-big.jpeg");
+ item = new UpdatedPixmapCacheItem(updatePartial);
+ item->setPixmap(pix2);
+ item->setCacheMode((QGraphicsItem::CacheMode)cacheMode);
+ if (rotation)
+ item->setTransform(QTransform().rotate(45));
+ item->setPos(0, 0);
+ scene.addItem(item);
+
+ view.count = 0;
+
+ QBENCHMARK {
+#ifdef CALLGRIND_DEBUG
+ CALLGRIND_START_INSTRUMENTATION
+#endif
+ for (int i = 0; i < 50; ++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"