[vlc-devel] [PATCH] vout/vulkan: add macosx extension module

Marvin Scholz epirat07 at gmail.com
Thu Jan 9 01:06:24 CET 2020


---
 modules/video_output/Makefile.am              | 11 +++
 modules/video_output/vulkan/platform_macosx.m | 86 +++++++++++++++++++
 2 files changed, 97 insertions(+)
 create mode 100644 modules/video_output/vulkan/platform_macosx.m

diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am
index 3c1bee98cb..6504a745ee 100644
--- a/modules/video_output/Makefile.am
+++ b/modules/video_output/Makefile.am
@@ -140,6 +140,14 @@ libvk_android_plugin_la_CFLAGS = $(AM_CFLAGS) $(VULKAN_COMMONCFLAGS) \
 			       -DVK_USE_PLATFORM_ANDROID_KHR -DPLATFORM_NAME=Android
 libvk_android_plugin_la_LIBADD = $(VULKAN_COMMONLIBS)
 
+libvk_macosx_plugin_la_SOURCES = $(VULKAN_COMMONSOURCES) video_output/vulkan/surface.c \
+				video_output/vulkan/platform_macosx.m
+libvk_macosx_plugin_la_CFLAGS = $(AM_CFLAGS) $(VULKAN_COMMONCFLAGS) \
+			       -DVK_USE_PLATFORM_MACOS_MVK -DPLATFORM_NAME=macOS
+libvk_macosx_plugin_la_OBJCFLAGS = $(AM_OBJCFLAGS) $(VULKAN_COMMONCFLAGS) \
+			       -DVK_USE_PLATFORM_MACOS_MVK -DPLATFORM_NAME=macOS
+libvk_macosx_plugin_la_LIBADD = $(VULKAN_COMMONLIBS)
+
 if HAVE_VULKAN
 vout_LTLIBRARIES += libvk_plugin.la
 if HAVE_WIN32_DESKTOP
@@ -148,6 +156,9 @@ endif
 if HAVE_ANDROID
 vout_LTLIBRARIES += libvk_android_plugin.la
 endif
+if HAVE_OSX
+vout_LTLIBRARIES += libvk_macosx_plugin.la
+endif
 endif
 
 ### X11 ###
diff --git a/modules/video_output/vulkan/platform_macosx.m b/modules/video_output/vulkan/platform_macosx.m
new file mode 100644
index 0000000000..a2b4c478a0
--- /dev/null
+++ b/modules/video_output/vulkan/platform_macosx.m
@@ -0,0 +1,86 @@
+/**
+ * @file platform_macosx.c
+ * @brief Vulkan platform-specific code for macOS
+ */
+
+/*
+ * Copyright © 2019 Niklas Haas, Marvin Scholz
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#import <Cocoa/Cocoa.h>
+#import <MetalKit/MetalKit.h>
+
+#import <MoltenVK/mvk_vulkan.h>
+
+#include "platform.h"
+
+int vlc_vk_InitPlatform(vlc_vk_t *vk)
+{
+    if (vk->window->type != VOUT_WINDOW_TYPE_NSOBJECT)
+        return VLC_EGENERIC;
+
+    return VLC_SUCCESS;
+}
+
+void vlc_vk_ClosePlatform(vlc_vk_t *vk)
+{
+    VLC_UNUSED(vk);
+}
+
+const char * const vlc_vk_PlatformExt = VK_MVK_MACOS_SURFACE_EXTENSION_NAME;
+
+int vlc_vk_CreateSurface(vlc_vk_t *vk)
+{
+    VkInstance vkinst = vk->instance->instance;
+
+    // Create Metal view
+    NSView *containerView = vk->window->handle.nsobject;
+    MTKView *metalView = [[MTKView alloc] initWithFrame:containerView.frame
+                                                 device:nil];
+
+    if (metalView == nil) {
+        msg_Err(vk, "Failed creating MTKView");
+        return VLC_EGENERIC;
+    }
+
+    // Add as subview to our container view
+    [metalView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
+    [containerView addSubview:metalView];
+
+    VkMacOSSurfaceCreateInfoMVK sinfo = {
+         .sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK,
+         .pView = (void*)metalView,
+    };
+
+    // TODO: Use newer VK_EXT_metal_surface extension?
+
+    __block VkResult res;
+    dispatch_sync(dispatch_get_main_queue(), ^{
+        res = vkCreateMacOSSurfaceMVK(vkinst, &sinfo, NULL, &vk->surface);
+    });
+
+    if (res != VK_SUCCESS) {
+        msg_Err(vk, "Failed creating macOS surface");
+        return VLC_EGENERIC;
+    }
+
+    return VLC_SUCCESS;
+}
-- 
2.20.1 (Apple Git-117)



More information about the vlc-devel mailing list