aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quick/util/qquickpixmapcache.cpp12
-rw-r--r--tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp57
2 files changed, 66 insertions, 3 deletions
diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp
index 1f4da46ca6..6ac5be5f13 100644
--- a/src/quick/util/qquickpixmapcache.cpp
+++ b/src/quick/util/qquickpixmapcache.cpp
@@ -902,7 +902,10 @@ void QQuickPixmapData::release()
}
if (pixmapStatus == QQuickPixmap::Ready) {
- pixmapStore()->unreferencePixmap(this);
+ if (inCache)
+ pixmapStore()->unreferencePixmap(this);
+ else
+ delete this;
} else {
removeFromCache();
delete this;
@@ -1163,7 +1166,12 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &reques
QQuickPixmapKey key = { &url, &requestSize };
QQuickPixmapStore *store = pixmapStore();
- QHash<QQuickPixmapKey, QQuickPixmapData *>::Iterator iter = store->m_cache.find(key);
+ QHash<QQuickPixmapKey, QQuickPixmapData *>::Iterator iter = store->m_cache.end();
+
+ // If Cache is disabled, the pixmap will always be loaded, even if there is an existing
+ // cached version.
+ if (options & QQuickPixmap::Cache)
+ iter = store->m_cache.find(key);
if (iter == store->m_cache.end()) {
if (url.scheme() == QLatin1String("image")) {
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