diff options
author | Simon Zeni <simon@bl4ckb0ne.ca> | 2021-07-14 16:35:14 -0400 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2021-07-22 22:28:24 +0200 |
commit | 0778151f94c6c75678491d5d29af041cef628fca (patch) | |
tree | 2b87b28127428a74664f29f6516b6f06d56fa4f0 | |
parent | 646a25667eb4c51a1ea99a780a770a53f9d79991 (diff) |
types/wlr_buffer: create custom wlr_buffer from wl_resource
-rw-r--r-- | types/wlr_buffer.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/types/wlr_buffer.c b/types/wlr_buffer.c index dca4c81a..80646f47 100644 --- a/types/wlr_buffer.c +++ b/types/wlr_buffer.c @@ -181,6 +181,18 @@ void wlr_buffer_register_resource_interface( *iface_ptr = iface; } +static const struct wlr_buffer_resource_interface *get_buffer_resource_iface( + struct wl_resource *resource) { + struct wlr_buffer_resource_interface **iface_ptr; + wl_array_for_each(iface_ptr, &buffer_resource_interfaces) { + if ((*iface_ptr)->is_instance(resource)) { + return *iface_ptr; + } + } + + return NULL; +} + struct wlr_buffer *wlr_buffer_from_resource(struct wl_resource *resource) { assert(resource && wlr_resource_is_buffer(resource)); @@ -202,8 +214,20 @@ struct wlr_buffer *wlr_buffer_from_resource(struct wl_resource *resource) { wlr_drm_buffer_from_resource(resource); buffer = wlr_buffer_lock(&drm_buffer->base); } else { - wlr_log(WLR_ERROR, "Unknown buffer type"); - 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; + } + + 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; + } + + buffer = wlr_buffer_lock(custom_buffer); } return buffer; |