mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-26 06:35:58 +01:00
types/wlr_buffer: create custom wlr_buffer from wl_resource
This commit is contained in:
parent
646a25667e
commit
0778151f94
1 changed files with 26 additions and 2 deletions
|
@ -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,10 +214,22 @@ 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 {
|
||||||
|
const struct wlr_buffer_resource_interface *iface =
|
||||||
|
get_buffer_resource_iface(resource);
|
||||||
|
if (!iface) {
|
||||||
wlr_log(WLR_ERROR, "Unknown buffer type");
|
wlr_log(WLR_ERROR, "Unknown buffer type");
|
||||||
return NULL;
|
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 a new issue