diff options
author | Albert Astals Cid <albert.astals@canonical.com> | 2015-04-01 16:20:19 +0200 |
---|---|---|
committer | Albert Astals Cid <albert.astals@canonical.com> | 2015-04-09 08:30:29 +0000 |
commit | 3f16e67ecdc4ecbb6bbaeb9284cbdaf442baaa25 (patch) | |
tree | dbfcfbb46d773c8577b4e389262caeaa74cacef5 | |
parent | 067a01bc76b76599aa696d867018c1e060ff30c6 (diff) | |
download | qtdeclarative-3f16e67ecdc4ecbb6bbaeb9284cbdaf442baaa25.tar.gz qtdeclarative-3f16e67ecdc4ecbb6bbaeb9284cbdaf442baaa25.tar.bz2 qtdeclarative-3f16e67ecdc4ecbb6bbaeb9284cbdaf442baaa25.zip |
Do not stall loading of local images if network is slow
Without this patch it can happen that we're
loading IMAGEREQUEST_MAX_REQUEST_COUNT http based images,
if the next image to load is a local file it wouldn't be processed
until one of the http ones finishes, which makes not much sense
Change-Id: I515306005192a20722f0c4588a1db1241348407c
Reviewed-by: Alan Alpert (Personal) <416365416c@gmail.com>
-rw-r--r-- | src/quick/util/qquickpixmapcache.cpp | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp index 519980825..eabbda1cd 100644 --- a/src/quick/util/qquickpixmapcache.cpp +++ b/src/quick/util/qquickpixmapcache.cpp @@ -518,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 @@ -540,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; + + PIXMAP_PROFILE(pixmapStateChanged<QQuickProfiler::PixmapLoadingStarted>(url)); - QSize requestSize = runningJob->requestSize; - locker.unlock(); - processJob(runningJob, url, requestSize); - locker.relock(); + QSize requestSize = runningJob->requestSize; + locker.unlock(); + processJob(runningJob, url, requestSize); + locker.relock(); + } + } + + if (!usableJob) + return; } } } |