diff options
author | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2018-02-26 12:00:04 +0100 |
---|---|---|
committer | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2018-03-01 11:54:26 +0000 |
commit | f70392700c63d81ef8bcee7351d903e4823b4571 (patch) | |
tree | fc45835a7be86ca0c959122eb651d4b89f094114 /src/quick/util | |
parent | cc71df112772ac5552ca5a698a837f3bbaeddc2a (diff) |
Fix: Do not read texture files when backend is not opengl
The software backend would assert for the compressed GL texture files.
Autotests updated for this functionality. Moved tests of the optional
texture-file support out of qmltest (where it did not belong) and into
tst_qquickimage, side by side with the tests of the optional svg
format.
Change-Id: I98c407093ccebeb70ba5a93ff0882dbd0b8060d5
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src/quick/util')
-rw-r--r-- | src/quick/util/qquickpixmapcache.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp index e1937aeec2..4237ec3edf 100644 --- a/src/quick/util/qquickpixmapcache.cpp +++ b/src/quick/util/qquickpixmapcache.cpp @@ -423,6 +423,24 @@ static QStringList fromLatin1List(const QList<QByteArray> &list) return res; } +class BackendSupport +{ +public: + BackendSupport() + { + delete QSGContext::createTextureFactoryFromImage(QImage()); // Force init of backend data + hasOpenGL = QQuickWindow::sceneGraphBackend().isEmpty(); // i.e. default + QList<QByteArray> list; + if (hasOpenGL) + list.append(QSGTextureReader::supportedFileFormats()); + list.append(QImageReader::supportedImageFormats()); + fileSuffixes = fromLatin1List(list); + } + bool hasOpenGL; + QStringList fileSuffixes; +}; +Q_GLOBAL_STATIC(BackendSupport, backendSupport); + static QString existingImageFileForPath(const QString &localFile) { // Do nothing if given filepath exists or already has a suffix @@ -430,11 +448,9 @@ static QString existingImageFileForPath(const QString &localFile) if (!fi.suffix().isEmpty() || fi.exists()) return localFile; - static const QStringList suffixes = fromLatin1List(QSGTextureReader::supportedFileFormats() + - QImageReader::supportedImageFormats()); QString tryFile = localFile + QStringLiteral(".xxxx"); const int suffixIdx = localFile.length() + 1; - for (const QString &suffix : suffixes) { + for (const QString &suffix : backendSupport()->fileSuffixes) { tryFile.replace(suffixIdx, 10, suffix); if (QFileInfo::exists(tryFile)) return tryFile; @@ -801,7 +817,7 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u QSize readSize; if (f.open(QIODevice::ReadOnly)) { QSGTextureReader texReader(&f, localFile); - if (texReader.isTexture()) { + if (backendSupport()->hasOpenGL && texReader.isTexture()) { QQuickTextureFactory *factory = texReader.read(); if (factory) { readSize = factory->textureSize(); @@ -1284,7 +1300,7 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q if (f.open(QIODevice::ReadOnly)) { QSGTextureReader texReader(&f, localFile); - if (texReader.isTexture()) { + if (backendSupport()->hasOpenGL && texReader.isTexture()) { QQuickTextureFactory *factory = texReader.read(); if (factory) { *ok = true; |