types/wlr_buffer: create custom wlr_buffer from wl_resource
This commit is contained in:
parent
646a25667e
commit
0778151f94
|
@ -181,6 +181,18 @@ void wlr_buffer_register_resource_interface(
|
||||||
*iface_ptr = iface;
|
*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) {
|
struct wlr_buffer *wlr_buffer_from_resource(struct wl_resource *resource) {
|
||||||
assert(resource && wlr_resource_is_buffer(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);
|
wlr_drm_buffer_from_resource(resource);
|
||||||
buffer = wlr_buffer_lock(&drm_buffer->base);
|
buffer = wlr_buffer_lock(&drm_buffer->base);
|
||||||
} else {
|
} else {
|
||||||
wlr_log(WLR_ERROR, "Unknown buffer type");
|
const struct wlr_buffer_resource_interface *iface =
|
||||||
return NULL;
|
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;
|
return buffer;
|
||||||
|
|
Loading…
Reference in New Issue