mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-22 01:49:48 +01:00
wl-drm: use resource interface
Instead of hardcoding builtin resource types in wlr_buffer_from_resource(), use the modular resource interface.
This commit is contained in:
parent
772066a174
commit
f84f7c7710
2 changed files with 25 additions and 22 deletions
|
@ -2,7 +2,6 @@
|
|||
#include <string.h>
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/interfaces/wlr_buffer.h>
|
||||
#include <wlr/types/wlr_drm.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "types/wlr_buffer.h"
|
||||
|
||||
|
@ -47,27 +46,18 @@ static const struct wlr_buffer_resource_interface *get_buffer_resource_iface(
|
|||
struct wlr_buffer *wlr_buffer_from_resource(struct wl_resource *resource) {
|
||||
assert(resource && wlr_resource_is_buffer(resource));
|
||||
|
||||
struct wlr_buffer *buffer;
|
||||
if (wlr_drm_buffer_is_resource(resource)) {
|
||||
struct wlr_drm_buffer *drm_buffer =
|
||||
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);
|
||||
const struct wlr_buffer_resource_interface *iface =
|
||||
get_buffer_resource_iface(resource);
|
||||
if (!iface) {
|
||||
wlr_log(WLR_ERROR, "Unknown buffer type");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
struct wlr_buffer *buffer = iface->from_resource(resource);
|
||||
if (!buffer) {
|
||||
wlr_log(WLR_ERROR, "Failed to create %s buffer", iface->name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return wlr_buffer_lock(buffer);
|
||||
}
|
||||
|
|
|
@ -170,6 +170,17 @@ static void drm_bind(struct wl_client *client, void *data,
|
|||
}
|
||||
}
|
||||
|
||||
static struct wlr_buffer *buffer_from_resource(struct wl_resource *resource) {
|
||||
struct wlr_drm_buffer *buffer = wlr_drm_buffer_from_resource(resource);
|
||||
return &buffer->base;
|
||||
}
|
||||
|
||||
static const struct wlr_buffer_resource_interface buffer_resource_interface = {
|
||||
.name = "wlr_drm_buffer",
|
||||
.is_instance = wlr_drm_buffer_is_resource,
|
||||
.from_resource = buffer_from_resource,
|
||||
};
|
||||
|
||||
static void drm_destroy(struct wlr_drm *drm) {
|
||||
wl_signal_emit_mutable(&drm->events.destroy, NULL);
|
||||
|
||||
|
@ -243,5 +254,7 @@ struct wlr_drm *wlr_drm_create(struct wl_display *display,
|
|||
drm->renderer_destroy.notify = handle_renderer_destroy;
|
||||
wl_signal_add(&renderer->events.destroy, &drm->renderer_destroy);
|
||||
|
||||
wlr_buffer_register_resource_interface(&buffer_resource_interface);
|
||||
|
||||
return drm;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue