From 18c2e2512b1256677ec09f8ac469f34ed30ce2f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 8 Mar 2024 11:45:46 +0100 Subject: Make the QSGTexture native accessor query work on macOS/iOS Also add an autotest. Pick-to: 6.7 6.6 6.5 Fixes: QTBUG-108019 Change-Id: Ie809041019b0a1b842791994e42d9d75578eb350 Reviewed-by: Laszlo Agocs --- tests/auto/quick/scenegraph/tst_scenegraph.cpp | 54 ++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'tests/auto/quick/scenegraph/tst_scenegraph.cpp') diff --git a/tests/auto/quick/scenegraph/tst_scenegraph.cpp b/tests/auto/quick/scenegraph/tst_scenegraph.cpp index 02c9d49796..aa275f8bfc 100644 --- a/tests/auto/quick/scenegraph/tst_scenegraph.cpp +++ b/tests/auto/quick/scenegraph/tst_scenegraph.cpp @@ -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); @@ -783,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 scene(createOffscreenScene(testFileUrl(QLatin1String("renderControl_rect.qml")))); + QVERIFY(scene->renderControl && scene->window && scene->rootItem); + + QImage image(512, 512, QImage::Format_RGBA8888); + + QScopedPointer texture(scene->window->createTextureFromImage(image, QQuickWindow::TextureHasAlphaChannel)); + QVERIFY(texture.data()); + + commitTexture(scene->window->rhi(), texture.data()); + +#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) + if (scene->window->graphicsApi() == QSGRendererInterface::Metal) { + auto texNatIf = texture->nativeInterface(); + QVERIFY(texNatIf); + QVERIFY(texNatIf->nativeTexture()); + } +#endif + +#if defined(Q_OS_WIN) + if (scene->window->graphicsApi() == QSGRendererInterface::Direct3D11) { + auto texNatIf = texture->nativeInterface(); + QVERIFY(texNatIf); + QVERIFY(texNatIf->nativeTexture()); + } else if (scene->window->graphicsApi() == QSGRendererInterface::Direct3D12) { + auto texNatIf = texture->nativeInterface(); + QVERIFY(texNatIf); + QVERIFY(texNatIf->nativeTexture()); + } +#endif + +#if QT_CONFIG(opengl) + if (scene->window->graphicsApi() == QSGRendererInterface::OpenGL) { + auto texNatIf = texture->nativeInterface(); + QVERIFY(texNatIf); + QVERIFY(texNatIf->nativeTexture()); + } +#endif + +#if QT_CONFIG(vulkan) + if (scene->window->graphicsApi() == QSGRendererInterface::Vulkan) { + auto texNatIf = texture->nativeInterface(); + QVERIFY(texNatIf); + QVERIFY(texNatIf->nativeImage()); + } +#endif +} + bool tst_SceneGraph::isRunningOnRhi() { static bool retval = false; -- cgit v1.2.3