types/wlr_buffer: create custom wlr_buffer from wl_resource
@@ -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,10 +214,22 @@ 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 {
+ 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;
}
