Skip to content

Commit

Permalink
wayland: add vulkan wayland platform support
Browse files Browse the repository at this point in the history
Add a `vulkan platform` implementation for wayland, effectively enabling
the usage of the vulkan libplacebo display on Wayland environments.
  • Loading branch information
alexandre-janniaux authored and jbkempf committed May 2, 2021
1 parent e7d0b88 commit a1814bd
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
11 changes: 11 additions & 0 deletions modules/video_output/wayland/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ libegl_wl_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -DUSE_PLATFORM_WAYLAND=1
libegl_wl_plugin_la_CFLAGS = $(AM_CFLAGS) $(EGL_CFLAGS) $(WAYLAND_EGL_CFLAGS)
libegl_wl_plugin_la_LIBADD = $(EGL_LIBS) $(WAYLAND_EGL_LIBS)

libvk_wl_plugin_la_SOURCES = \
video_output/vulkan/platform.h \
video_output/wayland/vulkan.c
libvk_wl_plugin_la_CFLAGS = $(AM_CFLAGS) \
$(WAYLAND_CFLAGS) $(VULKAN_COMMONCFLAGS) \
-DVK_USE_PLATFORM_WAYLAND_KHR
libvk_wl_plugin_la_LIBADD = $(VULKAN_COMMONLIBS) $(WAYLAND_LIBS)

if HAVE_WAYLAND
BUILT_SOURCES += $(nodist_libwl_shm_plugin_la_SOURCES)
vout_LTLIBRARIES += libwl_shm_plugin.la
Expand All @@ -82,4 +90,7 @@ vout_LTLIBRARIES += libxdg_shell_plugin.la
if HAVE_EGL
vout_LTLIBRARIES += libegl_wl_plugin.la
endif
if HAVE_VULKAN
vout_LTLIBRARIES += libvk_wl_plugin.la
endif
endif
76 changes: 76 additions & 0 deletions modules/video_output/wayland/vulkan.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* @file vulkan.c
* @brief Vulkan platform-specific code for Wayland
*/
/*****************************************************************************
* Copyright © 2020 VideoLabs
*
* 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.
*****************************************************************************/

#if HAVE_CONFIG_H
# include <config.h>
#endif

#include <vlc_common.h>
#include <vlc_plugin.h>

#include "../vulkan/instance.h"

static void ClosePlatform(vlc_vk_t *vk)
{ (void)vk; }

static int CreateSurface(vlc_vk_t *vk, VkInstance vkinst, VkSurfaceKHR *surface_out)
{
VkWaylandSurfaceCreateInfoKHR surface_info = {
.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR,
.display = vk->window->display.wl,
.surface = vk->window->handle.wl,
};

VkResult res = vkCreateWaylandSurfaceKHR(vkinst, &surface_info, NULL, surface_out);
if (res != VK_SUCCESS) {
msg_Err(vk, "Failed creating Wayland surface");
return VLC_EGENERIC;
}

return VLC_SUCCESS;
}

static const struct vlc_vk_operations platform_ops =
{
.close = ClosePlatform,
.create_surface = CreateSurface,
};

static int InitPlatform(vlc_vk_t *vk)
{
if (vk->window->type != VOUT_WINDOW_TYPE_WAYLAND)
return VLC_EGENERIC;

vk->platform_ext = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME;
vk->ops = &platform_ops;
return VLC_SUCCESS;
}

vlc_module_begin()
set_shortname("Vulkan Wayland")
set_description(N_("Wayland platform support for Vulkan"))
set_category(CAT_VIDEO)
set_subcategory(SUBCAT_VIDEO_VOUT)
set_capability("vulkan platform", 50)
set_callback(InitPlatform)
add_shortcut("vk_wl")
vlc_module_end()

0 comments on commit a1814bd

Please sign in to comment.