From d3224ad22a38264aaae81e96384182aee7c1053f Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 27 Jul 2012 13:38:43 +1000 Subject: Pixmap loader adds images to unreferenced list when cache: false Don't add uncached images to the unreferenced list, since they cannot be reused later as they are not in the cache. Additionally, we currently search for images in the cache, even if we set cache: false. Setting cache false should not put images in the cache and should not use images that are in the cache. Task-number: QTBUG-26676 Change-Id: Ib7eb42199ae6ae6154b696c83ad1dd959e0f208f Reviewed-by: Andrew den Exter Reviewed-by: Martin Jones --- .../qquickpixmapcache/tst_qquickpixmapcache.cpp | 57 +++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) (limited to 'tests/auto/quick') diff --git a/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp b/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp index fb2405c27a..c238ed863f 100644 --- a/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp +++ b/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp @@ -74,6 +74,7 @@ private slots: void networkCrash(); #endif void lockingCrash(); + void uncached(); #if PIXMAP_DATA_LEAK_TEST void dataLeak(); #endif @@ -352,11 +353,15 @@ public: virtual QPixmap requestPixmap(const QString &d, QSize *, const QSize &) { Q_UNUSED(d) QPixmap pix(800, 600); - pix.fill(Qt::red); + pix.fill(fillColor); return pix; } + + static QRgb fillColor; }; +QRgb MyPixmapProvider::fillColor = qRgb(255, 0, 0); + // QTBUG-13345 void tst_qquickpixmapcache::shrinkcache() { @@ -417,6 +422,56 @@ void tst_qquickpixmapcache::lockingCrash() } } +void tst_qquickpixmapcache::uncached() +{ + QQmlEngine engine; + engine.addImageProvider(QLatin1String("mypixmaps"), new MyPixmapProvider); + + QUrl url("image://mypixmaps/mypix"); + { + QQuickPixmap p; + p.load(&engine, url, 0); + QImage img = p.image(); + QCOMPARE(img.pixel(0,0), qRgb(255, 0, 0)); + } + + // uncached, so we will get a different colored image + MyPixmapProvider::fillColor = qRgb(0, 255, 0); + { + QQuickPixmap p; + p.load(&engine, url, 0); + QImage img = p.image(); + QCOMPARE(img.pixel(0,0), qRgb(0, 255, 0)); + } + + // Load the image with cache enabled + MyPixmapProvider::fillColor = qRgb(0, 0, 255); + { + QQuickPixmap p; + p.load(&engine, url, QQuickPixmap::Cache); + QImage img = p.image(); + QCOMPARE(img.pixel(0,0), qRgb(0, 0, 255)); + } + + // We should not get the cached version if we request uncached + MyPixmapProvider::fillColor = qRgb(255, 0, 255); + { + QQuickPixmap p; + p.load(&engine, url, 0); + QImage img = p.image(); + QCOMPARE(img.pixel(0,0), qRgb(255, 0, 255)); + } + + // If we again load the image with cache enabled, we should get the previously cached version + MyPixmapProvider::fillColor = qRgb(0, 255, 255); + { + QQuickPixmap p; + p.load(&engine, url, QQuickPixmap::Cache); + QImage img = p.image(); + QCOMPARE(img.pixel(0,0), qRgb(0, 0, 255)); + } +} + #if PIXMAP_DATA_LEAK_TEST // This test should not be enabled by default as it -- cgit v1.2.3