From 24ef34f680246dff3a086022216d90a7fb77ac15 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 12 Dec 2023 16:38:15 +0100 Subject: [PATCH] tests/wayland-test-clients: Add gbm_device to WaylandDisplay We'll use this later to allocate dma-bufs from. Part-of: --- src/tests/wayland-test-clients/meson.build | 6 ++--- .../wayland-test-client-utils.c | 22 +++++++++++++++++++ .../wayland-test-client-utils.h | 4 ++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/tests/wayland-test-clients/meson.build b/src/tests/wayland-test-clients/meson.build index ed779f55c..beaf36c8b 100644 --- a/src/tests/wayland-test-clients/meson.build +++ b/src/tests/wayland-test-clients/meson.build @@ -20,10 +20,6 @@ wayland_test_clients = [ }, { 'name': 'dma-buf-scanout', - 'extra_deps': [ - libdrm_dep, - libgbm_dep, - ], }, { 'name': 'fractional-scale', @@ -92,6 +88,8 @@ foreach test : wayland_test_clients glib_dep, gobject_dep, wayland_client_dep, + libdrm_dep, + libgbm_dep, m_dep, ] if test.has_key('extra_deps') diff --git a/src/tests/wayland-test-clients/wayland-test-client-utils.c b/src/tests/wayland-test-clients/wayland-test-client-utils.c index c89d3f7c9..9623131cb 100644 --- a/src/tests/wayland-test-clients/wayland-test-client-utils.c +++ b/src/tests/wayland-test-clients/wayland-test-client-utils.c @@ -107,6 +107,26 @@ create_anonymous_file (off_t size) return fd; } +static struct gbm_device * +create_gbm_device (WaylandDisplay *display) +{ + const char *gpu_path; + int fd; + + gpu_path = lookup_property_value (display, "gpu-path"); + if (!gpu_path) + return NULL; + + fd = open (gpu_path, O_RDWR); + if (fd < 0) + { + g_error ("Failed to open drm render node %s: %s", + gpu_path, g_strerror (errno)); + } + + return gbm_create_device (fd); +} + static void handle_xdg_wm_base_ping (void *user_data, struct xdg_wm_base *xdg_wm_base, @@ -261,6 +281,8 @@ wayland_display_new_full (WaylandDisplayCapabilities capabilities, wl_display_roundtrip (display->display); + display->gbm_device = create_gbm_device (display); + return display; } diff --git a/src/tests/wayland-test-clients/wayland-test-client-utils.h b/src/tests/wayland-test-clients/wayland-test-client-utils.h index 1c58fa3ee..96fd47d7b 100644 --- a/src/tests/wayland-test-clients/wayland-test-client-utils.h +++ b/src/tests/wayland-test-clients/wayland-test-client-utils.h @@ -1,5 +1,7 @@ #pragma once +#include +#include #include #include #include @@ -37,6 +39,8 @@ typedef struct _WaylandDisplay uint32_t sync_event_serial_next; GHashTable *properties; + + struct gbm_device *gbm_device; } WaylandDisplay; #define WAYLAND_TYPE_DISPLAY (wayland_display_get_type ())