[vlc-devel] [PATCH 6/7] vout/vulkan: Add win32 extension module

Niklas Haas vlc at haasn.xyz
Mon Oct 1 16:51:51 CEST 2018


From: Marvin Scholz <epirat07 at gmail.com>

---
 modules/video_output/Makefile.am      | 12 ++++++++++++
 modules/video_output/vulkan/surface.c | 24 ++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am
index bd6c4456a4..b0636c4a64 100644
--- a/modules/video_output/Makefile.am
+++ b/modules/video_output/Makefile.am
@@ -181,11 +181,17 @@ libglx_plugin_la_SOURCES = video_output/glx.c
 libglx_plugin_la_CFLAGS = $(AM_CFLAGS) $(GL_CFLAGS)
 libglx_plugin_la_LIBADD = $(GL_LIBS) $(X_LIBS) $(X_PRE_LIBS) -lX11
 
+
 libvk_x11_plugin_la_SOURCES = $(VULKAN_COMMONSOURCES) video_output/vulkan/surface.c
 libvk_x11_plugin_la_CFLAGS = $(AM_CFLAGS) $(VULKAN_COMMONCFLAGS) \
 			     -DVK_USE_PLATFORM_XLIB_KHR
 libvk_x11_plugin_la_LIBADD = $(VULKAN_COMMONLIBS) $(X_LIBS) $(X_PRE_LIBS) -lX11
 
+libvk_win32_plugin_la_SOURCES = $(VULKAN_COMMONSOURCES) video_output/vulkan/surface.c
+libvk_win32_plugin_la_CFLAGS = $(AM_CFLAGS) $(VULKAN_COMMONCFLAGS) \
+			     -DVK_USE_PLATFORM_WIN32_KHR
+libvk_win32_plugin_la_LIBADD = $(VULKAN_COMMONLIBS)
+
 if HAVE_XCB
 pkglib_LTLIBRARIES += libvlc_xcb_events.la
 vout_LTLIBRARIES += libxcb_x11_plugin.la libxcb_window_plugin.la
@@ -207,6 +213,12 @@ vout_LTLIBRARIES += libvk_x11_plugin.la
 endif
 endif
 
+if HAVE_WIN32_DESKTOP
+if HAVE_VULKAN
+vout_LTLIBRARIES += libvk_win32_plugin.la
+endif
+endif
+
 
 ### Wayland ###
 libwl_shm_plugin_la_SOURCES = video_output/wayland/shm.c
diff --git a/modules/video_output/vulkan/surface.c b/modules/video_output/vulkan/surface.c
index 31865bd951..70e27d1042 100644
--- a/modules/video_output/vulkan/surface.c
+++ b/modules/video_output/vulkan/surface.c
@@ -36,6 +36,10 @@
 #include <vlc_xlib.h>
 #define MODULE_NAME N_("Vulkan context (Xlib)")
 
+#elif VK_USE_PLATFORM_WIN32_KHR
+
+#define MODULE_NAME N_("Vulkan context (Win32)")
+
 #else
 #error Trying to build vulkan/surface.c without any platform defined!
 #endif
@@ -60,6 +64,13 @@ static int Open (vlc_object_t *obj)
 
     surf_extension = VK_KHR_XLIB_SURFACE_EXTENSION_NAME;
 
+#elif VK_USE_PLATFORM_WIN32_KHR
+
+    if (vk->window->type != VOUT_WINDOW_TYPE_HWND)
+        return VLC_EGENERIC;
+
+    surf_extension = VK_KHR_WIN32_SURFACE_EXTENSION_NAME;
+
 #endif
 
     // Initialize Vulkan instance
@@ -90,6 +101,19 @@ static int Open (vlc_object_t *obj)
 
     VkResult res = vkCreateXlibSurfaceKHR(vkinst, &xinfo, NULL, &vk->surface);
 
+#elif VK_USE_PLATFORM_WIN32_KHR
+
+    // Get current win32 HINSTANCE
+    HINSTANCE hInst = GetModuleHandle(NULL);
+
+    VkWin32SurfaceCreateInfoKHR winfo = {
+         .sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR,
+         .hinstance = hInst,
+         .hwnd = (HWND) vk->window->handle.hwnd,
+    };
+
+    VkResult res = vkCreateWin32SurfaceKHR(vkinst, &winfo, NULL, &vk->surface);
+
 #endif
 
     if (res != VK_SUCCESS)
-- 
2.19.0



More information about the vlc-devel mailing list