From f84f7c771061696b52e39b2d3d994de9db1dbd65 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 11 Nov 2022 15:54:54 +0100 Subject: [PATCH] wl-drm: use resource interface Instead of hardcoding builtin resource types in wlr_buffer_from_resource(), use the modular resource interface. --- types/buffer/resource.c | 32 +++++++++++--------------------- types/wlr_drm.c | 13 +++++++++++++ 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/types/buffer/resource.c b/types/buffer/resource.c index 4e16fd83..2f1dc73c 100644 --- a/types/buffer/resource.c +++ b/types/buffer/resource.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include "types/wlr_buffer.h" @@ -47,27 +46,18 @@ static const struct wlr_buffer_resource_interface *get_buffer_resource_iface( struct wlr_buffer *wlr_buffer_from_resource(struct wl_resource *resource) { assert(resource && wlr_resource_is_buffer(resource)); - struct wlr_buffer *buffer; - if (wlr_drm_buffer_is_resource(resource)) { - struct wlr_drm_buffer *drm_buffer = - wlr_drm_buffer_from_resource(resource); - buffer = wlr_buffer_lock(&drm_buffer->base); - } else { - const struct wlr_buffer_resource_interface *iface = - get_buffer_resource_iface(resource); - if (!iface) { - wlr_log(WLR_ERROR, "Unknown buffer type"); - return NULL; - } - - struct wlr_buffer *custom_buffer = iface->from_resource(resource); - if (!custom_buffer) { - wlr_log(WLR_ERROR, "Failed to create %s buffer", iface->name); - return NULL; - } + const struct wlr_buffer_resource_interface *iface = + get_buffer_resource_iface(resource); + if (!iface) { + wlr_log(WLR_ERROR, "Unknown buffer type"); + return NULL; + } - buffer = wlr_buffer_lock(custom_buffer); + struct wlr_buffer *buffer = iface->from_resource(resource); + if (!buffer) { + wlr_log(WLR_ERROR, "Failed to create %s buffer", iface->name); + return NULL; } - return buffer; + return wlr_buffer_lock(buffer); } diff --git a/types/wlr_drm.c b/types/wlr_drm.c index 32eea1c7..13fe4512 100644 --- a/types/wlr_drm.c +++ b/types/wlr_drm.c @@ -170,6 +170,17 @@ static void drm_bind(struct wl_client *client, void *data, } } +static struct wlr_buffer *buffer_from_resource(struct wl_resource *resource) { + struct wlr_drm_buffer *buffer = wlr_drm_buffer_from_resource(resource); + return &buffer->base; +} + +static const struct wlr_buffer_resource_interface buffer_resource_interface = { + .name = "wlr_drm_buffer", + .is_instance = wlr_drm_buffer_is_resource, + .from_resource = buffer_from_resource, +}; + static void drm_destroy(struct wlr_drm *drm) { wl_signal_emit_mutable(&drm->events.destroy, NULL); @@ -243,5 +254,7 @@ struct wlr_drm *wlr_drm_create(struct wl_display *display, drm->renderer_destroy.notify = handle_renderer_destroy; wl_signal_add(&renderer->events.destroy, &drm->renderer_destroy); + wlr_buffer_register_resource_interface(&buffer_resource_interface); + return drm; }