diff options
-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; |