aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2022-11-11 15:43:48 +0100
committerSimon Zeni <simon@bl4ckb0ne.ca>2022-11-17 19:55:19 +0000
commit772066a17476bb4504b14e757d68deb9c62d0088 (patch)
treee8cdd70f61c85d7f55c04661f2353ef7ee52ccd1
parent236918d52e01d3b245454dafa4ce2875e78ad2bb (diff)
linux-dmabuf-v1: use resource interface
Instead of hardcoding builtin resource types in wlr_buffer_from_resource(), use the modular resource interface.
-rw-r--r--types/buffer/resource.c7
-rw-r--r--types/wlr_linux_dmabuf_v1.c14
2 files changed, 15 insertions, 6 deletions
diff --git a/types/buffer/resource.c b/types/buffer/resource.c
index 8d39b6b9..4e16fd83 100644
--- a/types/buffer/resource.c
+++ b/types/buffer/resource.c
@@ -3,7 +3,6 @@
#include <wayland-server.h>
#include <wlr/interfaces/wlr_buffer.h>
#include <wlr/types/wlr_drm.h>
-#include <wlr/types/wlr_linux_dmabuf_v1.h>
#include <wlr/util/log.h>
#include "types/wlr_buffer.h"
@@ -49,11 +48,7 @@ struct wlr_buffer *wlr_buffer_from_resource(struct wl_resource *resource) {
assert(resource && wlr_resource_is_buffer(resource));
struct wlr_buffer *buffer;
- if (wlr_dmabuf_v1_resource_is_buffer(resource)) {
- struct wlr_dmabuf_v1_buffer *dmabuf =
- wlr_dmabuf_v1_buffer_from_buffer_resource(resource);
- buffer = wlr_buffer_lock(&dmabuf->base);
- } else if (wlr_drm_buffer_is_resource(resource)) {
+ 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);
diff --git a/types/wlr_linux_dmabuf_v1.c b/types/wlr_linux_dmabuf_v1.c
index 7480b9e1..d6b2d8ef 100644
--- a/types/wlr_linux_dmabuf_v1.c
+++ b/types/wlr_linux_dmabuf_v1.c
@@ -885,6 +885,18 @@ static void linux_dmabuf_bind(struct wl_client *client, void *data,
}
}
+static struct wlr_buffer *buffer_from_resource(struct wl_resource *resource) {
+ struct wlr_dmabuf_v1_buffer *buffer =
+ wlr_dmabuf_v1_buffer_from_buffer_resource(resource);
+ return &buffer->base;
+}
+
+static const struct wlr_buffer_resource_interface buffer_resource_interface = {
+ .name = "wlr_dmabuf_v1_buffer",
+ .is_instance = wlr_dmabuf_v1_resource_is_buffer,
+ .from_resource = buffer_from_resource,
+};
+
static void linux_dmabuf_v1_destroy(struct wlr_linux_dmabuf_v1 *linux_dmabuf) {
wl_signal_emit_mutable(&linux_dmabuf->events.destroy, linux_dmabuf);
@@ -950,6 +962,8 @@ struct wlr_linux_dmabuf_v1 *wlr_linux_dmabuf_v1_create(struct wl_display *displa
linux_dmabuf->renderer_destroy.notify = handle_renderer_destroy;
wl_signal_add(&renderer->events.destroy, &linux_dmabuf->renderer_destroy);
+ wlr_buffer_register_resource_interface(&buffer_resource_interface);
+
return linux_dmabuf;
}