diff options
author | Morten Johan Sørvig <morten.sorvig@qt.io> | 2018-04-04 14:11:43 +0200 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@qt.io> | 2018-05-11 09:13:55 +0000 |
commit | ee60a044c9afeab408085cac0214e0c3cf8b837a (patch) | |
tree | babeb849c7cd8ff192ec4ed753caf3f5b81b71cc /src/plugins | |
parent | 1332cca091bfa93da6e7c8983428909890fd6ccb (diff) |
macOS: Add QSurfaceType::MetalSurface
Add API to activate previously added Metal layer implementation.
This provides minimal support, and unlike VulkanSurface
there is no separate QWindow subclass.
What this does do is configure the QWindow to use a
Metal layer, and to send expose/update events when
the layer content should be redrawn. Qt will also update
the layer’s drawableSize and contentsScale when needed.
Application code can make use of this by accessing
the QWindow layer, which will be a CAMetalLayer:
CAMetalLayer *metalLayer = reinterpret_cast<CAMetalLayer *>(
reinterpret_cast<NSView *>(window->winId()).layer);
Change-Id: I514f5186133c3e610fd4e53ca91fe9c85c6d016e
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview_drawing.mm | 14 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowsnativeinterface.cpp | 5 |
2 files changed, 11 insertions, 8 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview_drawing.mm b/src/plugins/platforms/cocoa/qnsview_drawing.mm index daa1a2e250..5d637bb6b6 100644 --- a/src/plugins/platforms/cocoa/qnsview_drawing.mm +++ b/src/plugins/platforms/cocoa/qnsview_drawing.mm @@ -133,6 +133,12 @@ } } +- (BOOL)shouldUseMetalLayer:(QSurface::SurfaceType)surfaceType +{ + // MetalSurface needs a layer, and so does VulkanSurface (via MoltenVK) + return surfaceType == QWindow::MetalSurface || surfaceType == QWindow::VulkanSurface; +} + - (BOOL)wantsLayer { Q_ASSERT(m_platformWindow); @@ -144,16 +150,14 @@ bool layerRequested = qt_mac_resolveOption(false, m_platformWindow->window(), "_q_mac_wantsLayer", "QT_MAC_WANTS_LAYER"); - // Support Vulkan via MoltenVK, which requires a Metal layer - bool layerForVulkan = (m_platformWindow->window()->surfaceType() == QWindow::VulkanSurface); + bool layerForSurfaceType = [self shouldUseMetalLayer:m_platformWindow->window()->surfaceType()]; - return layerRequested || layerForVulkan; + return layerRequested || layerForSurfaceType; } - (CALayer *)makeBackingLayer { - // Support Vulkan via MoltenVK, which requires a Metal layer - bool makeMetalLayer = (m_platformWindow->window()->surfaceType() == QWindow::VulkanSurface); + bool makeMetalLayer = [self shouldUseMetalLayer:m_platformWindow->window()->surfaceType()]; if (makeMetalLayer) { // Check if Metal is supported. If it isn't then it's most likely // too late at this point and the QWindow will be non-functional, diff --git a/src/plugins/platforms/windows/qwindowsnativeinterface.cpp b/src/plugins/platforms/windows/qwindowsnativeinterface.cpp index 324b00144e..80f02c43e8 100644 --- a/src/plugins/platforms/windows/qwindowsnativeinterface.cpp +++ b/src/plugins/platforms/windows/qwindowsnativeinterface.cpp @@ -111,15 +111,14 @@ void *QWindowsNativeInterface::nativeResourceForWindow(const QByteArray &resourc return 0; } break; - case QWindow::OpenGLSurface: - case QWindow::OpenVGSurface: - break; case QWindow::VulkanSurface: #if QT_CONFIG(vulkan) if (type == VkSurface) return bw->surface(nullptr, nullptr); // returns the address of the VkSurfaceKHR, not the value, as expected #endif break; + default: + break; } qWarning("%s: Invalid key '%s' requested.", __FUNCTION__, resource.constData()); return 0; |