[Mesa-dev] [PATCH RFC] dri2: add support for linux-dmabuf-unstable-v1 version 4
emersion
contact at emersion.fr
Tue Nov 20 21:17:42 UTC 2018
This only implements the "primary_device" part. This allows EGL to work without
relying on wl_drm anymore.
---
This simple patch implements version 4, which is still in review on
wayland-devel [1].
[1]: https://patchwork.freedesktop.org/series/52370/
src/egl/drivers/dri2/platform_wayland.c | 58 +++++++++++++++++++++++--
1 file changed, 55 insertions(+), 3 deletions(-)
diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
index dc16a69dfb..6a656df062 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -332,10 +332,10 @@ dri2_wl_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,
dri2_surf->dri_drawable = (*createNewDrawable)(dri2_dpy->dri_screen, config,
dri2_surf);
- if (dri2_surf->dri_drawable == NULL) {
+ if (dri2_surf->dri_drawable == NULL) {
_eglError(EGL_BAD_ALLOC, "createNewDrawable");
goto cleanup_surf_wrapper;
- }
+ }
dri2_surf->base.SwapInterval = dri2_dpy->default_swap_interval;
@@ -1119,6 +1119,10 @@ drm_handle_device(void *data, struct wl_drm *drm, const char *device)
struct dri2_egl_display *dri2_dpy = data;
drm_magic_t magic;
+ if (zwp_linux_dmabuf_v1_get_version(dri2_dpy->wl_dmabuf) >=
+ ZWP_LINUX_DMABUF_V1_GET_DEFAULT_HINTS_SINCE_VERSION)
+ return;
+
dri2_dpy->device_name = strdup(device);
if (!dri2_dpy->device_name)
return;
@@ -1207,6 +1211,46 @@ static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener = {
.modifier = dmabuf_handle_modifier,
};
+static void dmabuf_hints_handle_primary_device(void *data,
+ struct zwp_linux_dmabuf_hints_v1 *hints, int fd)
+{
+ struct dri2_egl_display *dri2_dpy = data;
+
+ dri2_dpy->fd = fd;
+ dri2_dpy->authenticated = true;
+
+ dri2_dpy->device_name = loader_get_device_name_for_fd(dri2_dpy->fd);
+ if (!dri2_dpy->device_name) {
+ _eglError(EGL_BAD_ALLOC, "wayland-egl: failed to get device name "
+ "for default GPU");
+ }
+
+ zwp_linux_dmabuf_hints_v1_destroy(hints);
+}
+
+static void dmabuf_hints_ignore_modifier(void *data,
+ struct zwp_linux_dmabuf_hints_v1 *hints, uint32_t format,
+ uint32_t modifier_hi, uint32_t modifier_lo)
+{
+}
+
+static void dmabuf_hints_ignore_tranch(void *data,
+ struct zwp_linux_dmabuf_hints_v1 *hints)
+{
+}
+
+static void dmabuf_hints_ignore_done(void *data,
+ struct zwp_linux_dmabuf_hints_v1 *hints)
+{
+}
+
+static const struct zwp_linux_dmabuf_hints_v1_listener dmabuf_hints_listener = {
+ .primary_device = dmabuf_hints_handle_primary_device,
+ .modifier = dmabuf_hints_ignore_modifier,
+ .tranch = dmabuf_hints_ignore_tranch,
+ .done = dmabuf_hints_ignore_done,
+};
+
static void
registry_handle_global_drm(void *data, struct wl_registry *registry,
uint32_t name, const char *interface,
@@ -1221,9 +1265,17 @@ registry_handle_global_drm(void *data, struct wl_registry *registry,
} else if (strcmp(interface, "zwp_linux_dmabuf_v1") == 0 && version >= 3) {
dri2_dpy->wl_dmabuf =
wl_registry_bind(registry, name, &zwp_linux_dmabuf_v1_interface,
- MIN2(version, 3));
+ MIN2(version, 4));
zwp_linux_dmabuf_v1_add_listener(dri2_dpy->wl_dmabuf, &dmabuf_listener,
dri2_dpy);
+
+ if (zwp_linux_dmabuf_v1_get_version(dri2_dpy->wl_dmabuf) >=
+ ZWP_LINUX_DMABUF_V1_GET_DEFAULT_HINTS_SINCE_VERSION) {
+ struct zwp_linux_dmabuf_hints_v1 *hints =
+ zwp_linux_dmabuf_v1_get_default_hints(dri2_dpy->wl_dmabuf);
+ zwp_linux_dmabuf_hints_v1_add_listener(hints, &dmabuf_hints_listener,
+ dri2_dpy);
+ }
}
}
--
2.19.1
More information about the mesa-dev
mailing list