Skip to content

Commit

Permalink
wayland: add support for linux-dmabuf
Browse files Browse the repository at this point in the history
wl_drm is a legacy protocol, and wlroots is getting rid of it [1].
Use the newer and standard linux-dmabuf protocol if available to
get the DRM device.

[1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4397

Signed-off-by: Simon Ser <contact@emersion.fr>
  • Loading branch information
emersion committed Jan 8, 2024
1 parent 3457aa8 commit 922ce7d
Show file tree
Hide file tree
Showing 7 changed files with 417 additions and 15 deletions.
13 changes: 12 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,16 @@ m4_define([libva_lt_age],
[m4_eval(libva_binary_age - libva_interface_age)])

# libdrm minimun version requirement
m4_define([libdrm_version], [2.4.60])
m4_define([libdrm_version], [2.4.109])

# Wayland minimum version number
# 1.11.0 for wl_proxy_create_wrapper
m4_define([wayland_api_version], [1.11.0])

# wayland-protocols minimum version number
# 1.24 for linux-dmabuf v4
m4_define([wayland_protocols_version], [1.24])

AC_PREREQ(2.57)
AC_INIT([libva],
[libva_version],
Expand Down Expand Up @@ -304,10 +308,15 @@ USE_WAYLAND="no"
if test "x$enable_wayland" != "xno"; then
PKG_CHECK_MODULES([WAYLAND], [wayland-client >= wayland_api_version],
[USE_WAYLAND="yes"], [:])
PKG_CHECK_MODULES([WAYLAND_PROTOCOLS], [wayland-protocols >= wayland_protocols_version],
[USE_WAYLAND="yes"], [:])

if test "x$USE_WAYLAND" = "xno" -a "x$enable_wayland" = "xyes"; then
AC_MSG_ERROR([wayland explicitly enabled, however $WAYLAND_PKG_ERRORS])
fi
if test "x$USE_WAYLAND_PROTOCOLS" = "xno" -a "x$enable_wayland" = "xyes"; then
AC_MSG_ERROR([wayland explicitly enabled, however $WAYLAND_PROTOCOLS_PKG_ERRORS])
fi

if test "$USE_WAYLAND" = "yes"; then

Expand All @@ -322,6 +331,8 @@ if test "x$enable_wayland" != "xno"; then
AC_SUBST(WAYLAND_SCANNER, `$PKG_CONFIG --variable=wayland_scanner wayland-scanner`)
fi

AC_SUBST(WAYLAND_PROTOCOLS_DIR, `$PKG_CONFIG --variable=pkgdatadir wayland-protocols`)

AC_DEFINE([HAVE_VA_WAYLAND], [1],
[Defined to 1 if VA/Wayland API is built])
fi
Expand Down
7 changes: 5 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ cc = meson.get_compiler('c')
dl_dep = cc.find_library('dl', required : false)

WITH_DRM = not get_option('disable_drm') and (host_machine.system() != 'windows')
libdrm_dep = dependency('libdrm', version : '>= 2.4.60', required : (host_machine.system() != 'windows'))
libdrm_dep = dependency('libdrm', version : '>= 2.4.109', required : (host_machine.system() != 'windows'))

WITH_X11 = false
if get_option('with_x11') != 'no'
Expand Down Expand Up @@ -121,7 +121,10 @@ if get_option('with_wayland') != 'no'
if wayland_scanner_dep.found()
wl_scanner = find_program(wayland_scanner_dep.get_variable(pkgconfig: 'wayland_scanner'))
endif
WITH_WAYLAND = wayland_dep.found() and wayland_scanner_dep.found()
wayland_protocols_dep = dependency('wayland-protocols', version : '>= 1.24',
required : get_option('with_wayland') == 'yes')
WITH_WAYLAND = wayland_dep.found() and wayland_scanner_dep.found() and \
wayland_protocols_dep.found()
endif

WITH_WIN32 = false
Expand Down
33 changes: 21 additions & 12 deletions va/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ endif
if WITH_WAYLAND
libva_wayland_sources = [
'wayland/va_wayland.c',
'wayland/va_wayland_linux_dmabuf.c',
'wayland/va_wayland_drm.c',
'wayland/va_wayland_emgd.c',
'drm/va_drm_utils.c',
Expand All @@ -240,24 +241,32 @@ if WITH_WAYLAND
libva_headers_subproject += libva_wayland_headers

libva_wayland_headers_priv = [
'wayland/va_wayland_linux_dmabuf.h',
'wayland/va_wayland_drm.h',
'wayland/va_wayland_emgd.h',
'wayland/va_wayland_private.h',
]

protocol_files = [
custom_target(
'wayland-drm-client-protocol.c',
output : 'wayland-drm-client-protocol.c',
input : 'wayland/wayland-drm.xml',
command : [wl_scanner, 'private-code', '@INPUT@', '@OUTPUT@']),

custom_target(
'wayland-drm-client-protocol.h',
output : 'wayland-drm-client-protocol.h',
input : 'wayland/wayland-drm.xml',
wayland_protocols_dir = wayland_protocols_dep.get_variable(pkgconfig : 'pkgdatadir')

protocols = {
'wayland-drm': 'wayland/wayland-drm.xml',
'linux-dmabuf-unstable-v1': wayland_protocols_dir / 'unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml',
}

protocol_files = []
foreach name, xml : protocols
protocol_files += custom_target(
name + '-client-protocol.c',
output : name + '-client-protocol.c',
input : xml,
command : [wl_scanner, 'private-code', '@INPUT@', '@OUTPUT@'])
protocol_files += custom_target(
name + '-client-protocol.h',
output : name + '-client-protocol.h',
input : xml,
command : [wl_scanner, 'client-header', '@INPUT@', '@OUTPUT@'])
]
endforeach

install_headers(libva_wayland_headers, subdir : 'va')

Expand Down
10 changes: 10 additions & 0 deletions va/wayland/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ AM_CPPFLAGS = \

source_c = \
va_wayland.c \
va_wayland_linux_dmabuf.c \
va_wayland_drm.c \
va_wayland_emgd.c \
../drm/va_drm_utils.c \
Expand All @@ -40,16 +41,19 @@ source_h = \
$(NULL)

source_h_priv = \
va_wayland_linux_dmabuf.h \
va_wayland_drm.h \
va_wayland_emgd.h \
va_wayland_private.h \
$(NULL)

protocol_source_c = \
linux-dmabuf-unstable-v1-client-protocol.c \
wayland-drm-client-protocol.c \
$(NULL)

protocol_source_h = \
linux-dmabuf-unstable-v1-client-protocol.h \
wayland-drm-client-protocol.h \
$(NULL)

Expand All @@ -66,6 +70,12 @@ va_wayland_drm.c: $(protocol_source_h)
%-client-protocol.c : %.xml
$(AM_V_GEN)$(WAYLAND_SCANNER) private-code < $< > $@

va_wayland_linux_dmabuf.c: $(protocol_source_h)
linux-dmabuf-unstable-v1-client-protocol.h: $(WAYLAND_PROTOCOLS_DIR)/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml
$(AM_V_GEN)$(WAYLAND_SCANNER) client-header < $< > $@
linux-dmabuf-unstable-v1-client-protocol.c : $(WAYLAND_PROTOCOLS_DIR)/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml
$(AM_V_GEN)$(WAYLAND_SCANNER) private-code < $< > $@

EXTRA_DIST = \
wayland-drm.xml \
$(NULL)
Expand Down
5 changes: 5 additions & 0 deletions va/wayland/va_wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "sysdeps.h"
#include <stdarg.h>
#include "va_wayland.h"
#include "va_wayland_linux_dmabuf.h"
#include "va_wayland_drm.h"
#include "va_wayland_emgd.h"
#include "va_wayland_private.h"
Expand Down Expand Up @@ -90,6 +91,10 @@ struct va_wayland_backend {
};

static const struct va_wayland_backend g_backends[] = {
{
va_wayland_linux_dmabuf_create,
va_wayland_linux_dmabuf_destroy
},
{
va_wayland_drm_create,
va_wayland_drm_destroy
Expand Down
Loading

0 comments on commit 922ce7d

Please sign in to comment.