From cc0cb02da6fda1af6e6cd4a27d1fb8962f9ecb6e Mon Sep 17 00:00:00 2001 From: Elvis Lee Date: Thu, 22 Jun 2017 18:40:35 +0900 Subject: webOS: Share images even if cache is false Regardless Image::cache property, pixmap will be shared between images having same source. Image::cache property had two aspect of internal functionality. 1. Share image instance if source file is same. 2. Store cache for a while even if unreferenced. So we couldn't choose one of them with existing the cache property. In webOS, sharing image instance is quite natural. So by default, the sharing is always supported regardless the cache property. And the property will only cares the 2nd functionality to store cache. Change-Id: I68208cf633ce2afd5f086a61dcc77d0f3d0da037 Task-number: QTBUG-83115 Reviewed-by: Risto Avila Reviewed-by: Shawn Rutledge (cherry picked from commit 60280cab2d96b0646469f3d85f8927c7baa166d1) --- src/quick/util/qquickpixmapcache.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp index d96ebe70b2..bc1b267797 100644 --- a/src/quick/util/qquickpixmapcache.cpp +++ b/src/quick/util/qquickpixmapcache.cpp @@ -250,6 +250,9 @@ public: providerOptions(po), appliedTransform(QQuickImageProviderOptions::UsePluginDefaultTransform), textureFactory(nullptr), reply(nullptr), prevUnreferenced(nullptr), prevUnreferencedPtr(nullptr), nextUnreferenced(nullptr) +#ifdef Q_OS_WEBOS + , storeToCache(true) +#endif { declarativePixmaps.insert(pixmap); } @@ -261,6 +264,9 @@ public: providerOptions(po), appliedTransform(aTransform), textureFactory(nullptr), reply(nullptr), prevUnreferenced(nullptr), prevUnreferencedPtr(nullptr), nextUnreferenced(nullptr) +#ifdef Q_OS_WEBOS + , storeToCache(true) +#endif { declarativePixmaps.insert(pixmap); } @@ -273,6 +279,9 @@ public: providerOptions(po), appliedTransform(aTransform), textureFactory(texture), reply(nullptr), prevUnreferenced(nullptr), prevUnreferencedPtr(nullptr), nextUnreferenced(nullptr) +#ifdef Q_OS_WEBOS + , storeToCache(true) +#endif { declarativePixmaps.insert(pixmap); } @@ -282,6 +291,9 @@ public: appliedTransform(QQuickImageProviderOptions::UsePluginDefaultTransform), textureFactory(texture), reply(nullptr), prevUnreferenced(nullptr), prevUnreferencedPtr(nullptr), nextUnreferenced(nullptr) +#ifdef Q_OS_WEBOS + , storeToCache(true) +#endif { if (texture) requestSize = implicitSize = texture->textureSize(); @@ -328,6 +340,10 @@ public: QQuickPixmapData *prevUnreferenced; QQuickPixmapData**prevUnreferencedPtr; QQuickPixmapData *nextUnreferenced; + +#ifdef Q_OS_WEBOS + bool storeToCache; +#endif }; int QQuickPixmapReply::finishedIndex = -1; @@ -1287,7 +1303,11 @@ void QQuickPixmapData::release() QQuickPixmapReader::readerMutex.unlock(); } - if (pixmapStatus == QQuickPixmap::Ready) { + if (pixmapStatus == QQuickPixmap::Ready +#ifdef Q_OS_WEBOS + && storeToCache +#endif + ) { if (inCache) pixmapStore()->unreferencePixmap(this); else @@ -1643,6 +1663,13 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QRect &reques QHash::Iterator iter = store->m_cache.end(); +#ifdef Q_OS_WEBOS + QQuickPixmap::Options orgOptions = options; + // In webOS, we suppose that cache is always enabled to share image instances along its source. + // So, original option(orgOptions) for cache only decides whether to store the instances when it's unreferenced. + options |= QQuickPixmap::Cache; +#endif + // If Cache is disabled, the pixmap will always be loaded, even if there is an existing // cached version. Unless it's an itemgrabber url, since the cache is used to pass // the result between QQuickItemGrabResult and QQuickImage. @@ -1678,6 +1705,9 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QRect &reques PIXMAP_PROFILE(pixmapLoadingFinished(url, QSize(width(), height()))); if (options & QQuickPixmap::Cache) d->addToCache(); +#ifdef Q_OS_WEBOS + d->storeToCache = orgOptions & QQuickPixmap::Cache; +#endif return; } if (d) { // loadable, but encountered error while loading @@ -1694,6 +1724,9 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QRect &reques QQuickImageProviderOptions::UsePluginDefaultTransform, frame, frameCount); if (options & QQuickPixmap::Cache) d->addToCache(); +#ifdef Q_OS_WEBOS + d->storeToCache = orgOptions & QQuickPixmap::Cache; +#endif QQuickPixmapReader::readerMutex.lock(); d->reply = QQuickPixmapReader::instance(engine)->getImage(d); -- cgit v1.2.3