aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-03-08 11:45:46 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-03-11 10:04:17 +0100
commit18c2e2512b1256677ec09f8ac469f34ed30ce2f8 (patch)
tree828be34a15b7240cdd96554df5db21040e659659
parent4aeb72dc8414e55a76d7a8e7421a29ec1aa6cabb (diff)
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 <laszlo.agocs@qt.io>
-rw-r--r--src/quick/scenegraph/coreapi/qsgtexture.cpp4
-rw-r--r--src/quick/scenegraph/coreapi/qsgtexture_p.h6
-rw-r--r--src/quick/scenegraph/coreapi/qsgtexture_platform.h16
-rw-r--r--tests/auto/quick/scenegraph/tst_scenegraph.cpp54
4 files changed, 70 insertions, 10 deletions
diff --git a/src/quick/scenegraph/coreapi/qsgtexture.cpp b/src/quick/scenegraph/coreapi/qsgtexture.cpp
index d138b56625..c5acb2e462 100644
--- a/src/quick/scenegraph/coreapi/qsgtexture.cpp
+++ b/src/quick/scenegraph/coreapi/qsgtexture.cpp
@@ -87,7 +87,7 @@ QSGTexturePrivate::QSGTexturePrivate(QSGTexture *t)
, m_d3d11TextureAccessor(t)
, m_d3d12TextureAccessor(t)
#endif
-#if defined(__OBJC__)
+#if defined(Q_OS_APPLE)
, m_metalTextureAccessor(t)
#endif
#if QT_CONFIG(vulkan)
@@ -1047,7 +1047,7 @@ void *QSGTexture::resolveInterface(const char *name, int revision) const
#if QT_CONFIG(vulkan)
QT_NATIVE_INTERFACE_RETURN_IF(QSGVulkanTexture, &dd->m_vulkanTextureAccessor);
#endif
-#if defined(__OBJC__)
+#if defined(Q_OS_APPLE)
QT_NATIVE_INTERFACE_RETURN_IF(QSGMetalTexture, &dd->m_metalTextureAccessor);
#endif
#if defined(Q_OS_WIN)
diff --git a/src/quick/scenegraph/coreapi/qsgtexture_p.h b/src/quick/scenegraph/coreapi/qsgtexture_p.h
index 90356ee739..d6e943b392 100644
--- a/src/quick/scenegraph/coreapi/qsgtexture_p.h
+++ b/src/quick/scenegraph/coreapi/qsgtexture_p.h
@@ -69,14 +69,14 @@ public:
};
#endif
-#if defined(__OBJC__)
+#if defined(Q_OS_APPLE)
class Q_QUICK_EXPORT QSGTexturePlatformMetal : public QNativeInterface::QSGMetalTexture
{
public:
QSGTexturePlatformMetal(QSGTexture *t) : m_texture(t) { }
QSGTexture *m_texture;
- id<MTLTexture> nativeTexture() const override;
+ QT_OBJC_PROTOCOL(MTLTexture) nativeTexture() const override;
};
#endif
@@ -121,7 +121,7 @@ public:
QSGTexturePlatformD3D11 m_d3d11TextureAccessor;
QSGTexturePlatformD3D12 m_d3d12TextureAccessor;
#endif
-#if defined(__OBJC__)
+#if defined(Q_OS_APPLE)
QSGTexturePlatformMetal m_metalTextureAccessor;
#endif
#if QT_CONFIG(vulkan)
diff --git a/src/quick/scenegraph/coreapi/qsgtexture_platform.h b/src/quick/scenegraph/coreapi/qsgtexture_platform.h
index b854b2e185..29e3a41302 100644
--- a/src/quick/scenegraph/coreapi/qsgtexture_platform.h
+++ b/src/quick/scenegraph/coreapi/qsgtexture_platform.h
@@ -15,8 +15,14 @@
#include <QtGui/qvulkaninstance.h>
#endif
-#if defined(__OBJC__) || defined(Q_QDOC)
-@protocol MTLTexture;
+#if defined(Q_OS_APPLE) || defined(Q_QDOC)
+# if defined(__OBJC__) || defined(Q_QDOC)
+ @protocol MTLTexture;
+# define QT_OBJC_PROTOCOL(protocol) id<protocol>
+# else
+ typedef struct objc_object *id;
+# define QT_OBJC_PROTOCOL(protocol) id
+# endif
#endif
QT_BEGIN_NAMESPACE
@@ -62,12 +68,12 @@ struct Q_QUICK_EXPORT QSGD3D12Texture
};
#endif
-#if defined(__OBJC__) || defined(Q_QDOC)
+#if defined(Q_OS_APPLE) || defined(Q_QDOC)
struct Q_QUICK_EXPORT QSGMetalTexture
{
QT_DECLARE_NATIVE_INTERFACE(QSGMetalTexture, 1, QSGTexture)
- virtual id<MTLTexture> nativeTexture() const = 0;
- static QSGTexture *fromNative(id<MTLTexture> texture,
+ virtual QT_OBJC_PROTOCOL(MTLTexture) nativeTexture() const = 0;
+ static QSGTexture *fromNative(QT_OBJC_PROTOCOL(MTLTexture) texture,
QQuickWindow *window,
const QSize &size,
QQuickWindow::CreateTextureOptions options = {});
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<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 defined(Q_OS_MACOS) || defined(Q_OS_IOS)
+ 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;