diff options
Diffstat (limited to 'tests/auto/quick/scenegraph/tst_scenegraph.cpp')
-rw-r--r-- | tests/auto/quick/scenegraph/tst_scenegraph.cpp | 72 |
1 files changed, 66 insertions, 6 deletions
diff --git a/tests/auto/quick/scenegraph/tst_scenegraph.cpp b/tests/auto/quick/scenegraph/tst_scenegraph.cpp index 64c50f74ae..1d76fe3181 100644 --- a/tests/auto/quick/scenegraph/tst_scenegraph.cpp +++ b/tests/auto/quick/scenegraph/tst_scenegraph.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qtest.h> @@ -96,6 +96,7 @@ private slots: void createTextureFromImage(); void withAdoptedRhi(); void resizeTextureFromImage(); + void textureNativeInterface(); private: QQuickView *createView(const QString &file, QWindow *parent = nullptr, int x = -1, int y = -1, int w = -1, int h = -1); @@ -289,7 +290,9 @@ struct Sample { } bool check(const QImage &image, qreal scale) { - QColor color(image.pixel(x * scale, y * scale)); + const int scaledX = qRound(x * scale); + const int scaledY = qRound(y * scale); + const QColor color(image.pixel(scaledX, scaledY)); return qAbs(color.redF() - r) <= tolerance && qAbs(color.greenF() - g) <= tolerance && qAbs(color.blueF() - b) <= tolerance; @@ -370,16 +373,16 @@ void tst_SceneGraph::render_data() QRegularExpression baseSamples("#base: *(\\d+) *(\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+)"); QRegularExpression finalSamples("#final: *(\\d+) *(\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+)"); - foreach (QString fileName, files) { + for (QString fileName : std::as_const(files)) { QFile file(testFile(fileName)); if (!file.open(QFile::ReadOnly)) { qFatal("render_data: QFile::open failed! file=%s, error=%s", qPrintable(fileName), qPrintable(file.errorString())); } - QStringList contents = QString::fromLatin1(file.readAll()).split(QLatin1Char('\n')); + const QStringList contents = QString::fromLatin1(file.readAll()).split(QLatin1Char('\n')); int samples = -1; - foreach (QString line, contents) { + for (const QString &line : contents) { auto match = sampleCount.match(line); if (match.hasMatch()) { samples = match.captured(1).toInt(); @@ -390,7 +393,7 @@ void tst_SceneGraph::render_data() qFatal("render_data: failed to find string '#samples: [count], file=%s", qPrintable(fileName)); QList<Sample> baseStage, finalStage; - foreach (QString line, contents) { + for (const QString &line : contents) { auto match = baseSamples.match(line); if (match.hasMatch()) baseStage << sample_from_regexp(&match); @@ -430,6 +433,10 @@ void tst_SceneGraph::render() // ideal world. // Just keep this in mind when writing tests. qreal scale = view.devicePixelRatio(); + const bool isIntegerScale = qFuzzyIsNull(qreal(qFloor(scale)) - scale); + + if (file == "render_OutOfFloatRange.qml" && !isIntegerScale) + QSKIP("render_OutOfFloatRange doesn't work with non-integer scaling factors"); // Grab the window and check all our base stage samples QImage content = view.grabWindow(); @@ -777,6 +784,59 @@ void tst_SceneGraph::resizeTextureFromImage() TestOffscreenScene::cleanup(); } +void tst_SceneGraph::textureNativeInterface() +{ + if (!isRunningOnRhi()) + QSKIP("Skipping texture native interface tests due to not running with QRhi"); + + // test it offscreen because we want to do QSG stuff here on the main thread + QScopedPointer<TestOffscreenScene> scene(createOffscreenScene(testFileUrl(QLatin1String("renderControl_rect.qml")))); + QVERIFY(scene->renderControl && scene->window && scene->rootItem); + + QImage image(512, 512, QImage::Format_RGBA8888); + + QScopedPointer<QSGTexture> texture(scene->window->createTextureFromImage(image, QQuickWindow::TextureHasAlphaChannel)); + QVERIFY(texture.data()); + + commitTexture(scene->window->rhi(), texture.data()); + +#if QT_CONFIG(metal) + if (scene->window->graphicsApi() == QSGRendererInterface::Metal) { + auto texNatIf = texture->nativeInterface<QNativeInterface::QSGMetalTexture>(); + QVERIFY(texNatIf); + QVERIFY(texNatIf->nativeTexture()); + } +#endif + +#if defined(Q_OS_WIN) + if (scene->window->graphicsApi() == QSGRendererInterface::Direct3D11) { + auto texNatIf = texture->nativeInterface<QNativeInterface::QSGD3D11Texture>(); + QVERIFY(texNatIf); + QVERIFY(texNatIf->nativeTexture()); + } else if (scene->window->graphicsApi() == QSGRendererInterface::Direct3D12) { + auto texNatIf = texture->nativeInterface<QNativeInterface::QSGD3D12Texture>(); + QVERIFY(texNatIf); + QVERIFY(texNatIf->nativeTexture()); + } +#endif + +#if QT_CONFIG(opengl) + if (scene->window->graphicsApi() == QSGRendererInterface::OpenGL) { + auto texNatIf = texture->nativeInterface<QNativeInterface::QSGOpenGLTexture>(); + QVERIFY(texNatIf); + QVERIFY(texNatIf->nativeTexture()); + } +#endif + +#if QT_CONFIG(vulkan) + if (scene->window->graphicsApi() == QSGRendererInterface::Vulkan) { + auto texNatIf = texture->nativeInterface<QNativeInterface::QSGVulkanTexture>(); + QVERIFY(texNatIf); + QVERIFY(texNatIf->nativeImage()); + } +#endif +} + bool tst_SceneGraph::isRunningOnRhi() { static bool retval = false; |