aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2018-02-26 12:00:04 +0100
committerEirik Aavitsland <eirik.aavitsland@qt.io>2018-03-01 11:54:26 +0000
commitf70392700c63d81ef8bcee7351d903e4823b4571 (patch)
treefc45835a7be86ca0c959122eb651d4b89f094114
parentcc71df112772ac5552ca5a698a837f3bbaeddc2a (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>
-rw-r--r--src/quick/util/qquickpixmapcache.cpp26
-rw-r--r--tests/auto/qmltest/image/tst_image.qml20
-rw-r--r--tests/auto/quick/qquickimage/data/car.ktx (renamed from tests/auto/qmltest/image/car.ktx)bin11908 -> 11908 bytes
-rw-r--r--tests/auto/quick/qquickimage/data/logo.pkm (renamed from tests/auto/qmltest/image/logo.pkm)bin32784 -> 32784 bytes
-rw-r--r--tests/auto/quick/qquickimage/tst_qquickimage.cpp28
5 files changed, 46 insertions, 28 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;
diff --git a/tests/auto/qmltest/image/tst_image.qml b/tests/auto/qmltest/image/tst_image.qml
index 346bee6969..f8f0e7b53c 100644
--- a/tests/auto/qmltest/image/tst_image.qml
+++ b/tests/auto/qmltest/image/tst_image.qml
@@ -122,16 +122,6 @@ Item {
fillMode: Image.TileHorizontally
}
- Image {
- id: pkmImage
- source: "logo.pkm"
- }
-
- Image {
- id: ktxImage
- source: "car.ktx"
- }
-
TestCase {
name: "Image"
@@ -231,15 +221,5 @@ Item {
compare(tileModes3.height, 150)
compare(tileModes3.fillMode, Image.TileHorizontally)
}
-
- function test_pkmImage() {
- compare(pkmImage.width, 256)
- compare(pkmImage.height, 256)
- }
-
- function test_ktxImage() {
- compare(ktxImage.width, 146)
- compare(ktxImage.height, 80)
- }
}
}
diff --git a/tests/auto/qmltest/image/car.ktx b/tests/auto/quick/qquickimage/data/car.ktx
index 2aefdd306b..2aefdd306b 100644
--- a/tests/auto/qmltest/image/car.ktx
+++ b/tests/auto/quick/qquickimage/data/car.ktx
Binary files differ
diff --git a/tests/auto/qmltest/image/logo.pkm b/tests/auto/quick/qquickimage/data/logo.pkm
index c0987c5c36..c0987c5c36 100644
--- a/tests/auto/qmltest/image/logo.pkm
+++ b/tests/auto/quick/qquickimage/data/logo.pkm
Binary files differ
diff --git a/tests/auto/quick/qquickimage/tst_qquickimage.cpp b/tests/auto/quick/qquickimage/tst_qquickimage.cpp
index 9a93bf8892..3613ba6d87 100644
--- a/tests/auto/quick/qquickimage/tst_qquickimage.cpp
+++ b/tests/auto/quick/qquickimage/tst_qquickimage.cpp
@@ -62,6 +62,7 @@ public:
tst_qquickimage();
private slots:
+ void initTestCase();
void cleanup();
void noSource();
void imageSource();
@@ -97,12 +98,22 @@ private slots:
private:
QQmlEngine engine;
+ QSGRendererInterface::GraphicsApi graphicsApi = QSGRendererInterface::Unknown;
};
tst_qquickimage::tst_qquickimage()
{
}
+void tst_qquickimage::initTestCase()
+{
+ QQmlDataTest::initTestCase();
+ QScopedPointer<QQuickView> window(new QQuickView(0));
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window.data()));
+ graphicsApi = window->rendererInterface()->graphicsApi();
+}
+
void tst_qquickimage::cleanup()
{
QQuickWindow window;
@@ -150,6 +161,11 @@ void tst_qquickimage::imageSource_data()
QTest::newRow("remote svg") << "/heart.svg" << 595.0 << 841.0 << true << false << false << "";
if (QImageReader::supportedImageFormats().contains("svgz"))
QTest::newRow("remote svgz") << "/heart.svgz" << 595.0 << 841.0 << true << false << false << "";
+ if (graphicsApi == QSGRendererInterface::OpenGL) {
+ QTest::newRow("texturefile pkm format") << testFileUrl("logo.pkm").toString() << 256.0 << 256.0 << false << false << true << "";
+ QTest::newRow("texturefile ktx format") << testFileUrl("car.ktx").toString() << 146.0 << 80.0 << false << false << true << "";
+ QTest::newRow("texturefile async") << testFileUrl("logo.pkm").toString() << 256.0 << 256.0 << false << true << true << "";
+ }
QTest::newRow("remote not found") << "/no-such-file.png" << 0.0 << 0.0 << true
<< false << true << "<Unknown File>:2:1: QML Image: Error transferring {{ServerBaseUrl}}/no-such-file.png - server replied: Not found";
QTest::newRow("extless") << testFileUrl("colors").toString() << 120.0 << 120.0 << false << false << true << "";
@@ -157,9 +173,15 @@ void tst_qquickimage::imageSource_data()
QTest::newRow("extless async") << testFileUrl("colors1").toString() << 120.0 << 120.0 << false << true << true << "";
QTest::newRow("extless not found") << testFileUrl("no-such-file").toString() << 0.0 << 0.0 << false
<< false << true << "<Unknown File>:2:1: QML Image: Cannot open: " + testFileUrl("no-such-file").toString();
- // Test that pkm is preferred over png. As pattern.pkm has different size than pattern.png, these tests verify that the right file has been loaded
- QTest::newRow("extless prefer-tex") << testFileUrl("pattern").toString() << 64.0 << 64.0 << false << false << true << "";
- QTest::newRow("extless prefer-tex async") << testFileUrl("pattern").toString() << 64.0 << 64.0 << false << true << true << "";
+ // Test that texture file is preferred over image file, when supported.
+ // Since pattern.pkm has different size than pattern.png, these tests verify that the right file has been loaded
+ if (graphicsApi == QSGRendererInterface::OpenGL) {
+ QTest::newRow("extless prefer-tex") << testFileUrl("pattern").toString() << 64.0 << 64.0 << false << false << true << "";
+ QTest::newRow("extless prefer-tex async") << testFileUrl("pattern").toString() << 64.0 << 64.0 << false << true << true << "";
+ } else {
+ QTest::newRow("extless ignore-tex") << testFileUrl("pattern").toString() << 200.0 << 200.0 << false << false << true << "";
+ QTest::newRow("extless ignore-tex async") << testFileUrl("pattern").toString() << 200.0 << 200.0 << false << true << true << "";
+ }
}