diff options
Diffstat (limited to 'src/quick/util/qquickpixmapcache.cpp')
-rw-r--r-- | src/quick/util/qquickpixmapcache.cpp | 67 |
1 files changed, 46 insertions, 21 deletions
diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp index 42e6b818fb..eabbda1cdf 100644 --- a/src/quick/util/qquickpixmapcache.cpp +++ b/src/quick/util/qquickpixmapcache.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtQuick module of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ @@ -46,6 +46,7 @@ #include <QtQuick/private/qsgtexture_p.h> #include <QtQuick/private/qsgcontext_p.h> +#include <QQuickWindow> #include <QCoreApplication> #include <QImageReader> #include <QHash> @@ -101,13 +102,16 @@ QQuickDefaultTextureFactory::QQuickDefaultTextureFactory(const QImage &image) } else { im = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); } + size = im.size(); } -QSGTexture *QQuickDefaultTextureFactory::createTexture(QQuickWindow *) const +QSGTexture *QQuickDefaultTextureFactory::createTexture(QQuickWindow *window) const { - QSGPlainTexture *t = new QSGPlainTexture(); - t->setImage(im); + QSGTexture *t = window->createTextureFromImage(im, QQuickWindow::TextureCanUseAtlas); + static bool transient = qEnvironmentVariableIsSet("QSG_TRANSIENT_IMAGES"); + if (transient) + const_cast<QQuickDefaultTextureFactory *>(this)->im = QImage(); return t; } @@ -514,7 +518,7 @@ void QQuickPixmapReader::processJobs() QMutexLocker locker(&mutex); while (true) { - if (cancelled.isEmpty() && (jobs.isEmpty() || replies.count() >= IMAGEREQUEST_MAX_REQUEST_COUNT)) + if (cancelled.isEmpty() && jobs.isEmpty()) return; // Nothing else to do // Clean cancelled jobs @@ -536,17 +540,36 @@ void QQuickPixmapReader::processJobs() cancelled.clear(); } - if (!jobs.isEmpty() && replies.count() < IMAGEREQUEST_MAX_REQUEST_COUNT) { - QQuickPixmapReply *runningJob = jobs.takeLast(); - runningJob->loading = true; + if (!jobs.isEmpty()) { + // Find a job we can use + bool usableJob = false; + for (int i = jobs.count() - 1; !usableJob && i >= 0; i--) { + QQuickPixmapReply *runningJob = jobs[i]; + const QUrl url = runningJob->url; + + if (url.scheme() == QLatin1String("image")) { + usableJob = true; + } else { + const QString localFile = QQmlFile::urlToLocalFileOrQrc(url); + usableJob = !localFile.isEmpty() || replies.count() < IMAGEREQUEST_MAX_REQUEST_COUNT; + } - QUrl url = runningJob->url; - PIXMAP_PROFILE(pixmapStateChanged<QQuickProfiler::PixmapLoadingStarted>(url)); + if (usableJob) { + jobs.removeAt(i); + + runningJob->loading = true; - QSize requestSize = runningJob->requestSize; - locker.unlock(); - processJob(runningJob, url, requestSize); - locker.relock(); + PIXMAP_PROFILE(pixmapStateChanged<QQuickProfiler::PixmapLoadingStarted>(url)); + + QSize requestSize = runningJob->requestSize; + locker.unlock(); + processJob(runningJob, url, requestSize); + locker.relock(); + } + } + + if (!usableJob) + return; } } } @@ -833,8 +856,10 @@ void QQuickPixmapStore::unreferencePixmap(QQuickPixmapData *data) shrinkCache(-1); // Shrink the cache in case it has become larger than cache_limit - if (m_timerId == -1 && m_unreferencedPixmaps && !m_destroying) + if (m_timerId == -1 && m_unreferencedPixmaps + && !m_destroying && !QCoreApplication::closingDown()) { m_timerId = startTimer(CACHE_EXPIRE_TIME * 1000); + } } void QQuickPixmapStore::referencePixmap(QQuickPixmapData *data) |