aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2022-11-11 15:54:54 +0100
committerSimon Zeni <simon@bl4ckb0ne.ca>2022-11-17 19:55:19 +0000
commitf84f7c771061696b52e39b2d3d994de9db1dbd65 (patch)
treefd8a5b0c6a3b09873ee794cd914c81808d89eec2
parent772066a17476bb4504b14e757d68deb9c62d0088 (diff)
wl-drm: 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.c32
-rw-r--r--types/wlr_drm.c13
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 <string.h>
#include <wayland-server.h>
#include <wlr/interfaces/wlr_buffer.h>
-#include <wlr/types/wlr_drm.h>
#include <wlr/util/log.h>
#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;
}