mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 04:45:58 +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 <string.h>
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
#include <wlr/interfaces/wlr_buffer.h>
|
#include <wlr/interfaces/wlr_buffer.h>
|
||||||
#include <wlr/types/wlr_drm.h>
|
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "types/wlr_buffer.h"
|
#include "types/wlr_buffer.h"
|
||||||
|
|
||||||
|
@ -47,12 +46,6 @@ static const struct wlr_buffer_resource_interface *get_buffer_resource_iface(
|
||||||
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));
|
||||||
|
|
||||||
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 =
|
const struct wlr_buffer_resource_interface *iface =
|
||||||
get_buffer_resource_iface(resource);
|
get_buffer_resource_iface(resource);
|
||||||
if (!iface) {
|
if (!iface) {
|
||||||
|
@ -60,14 +53,11 @@ struct wlr_buffer *wlr_buffer_from_resource(struct wl_resource *resource) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_buffer *custom_buffer = iface->from_resource(resource);
|
struct wlr_buffer *buffer = iface->from_resource(resource);
|
||||||
if (!custom_buffer) {
|
if (!buffer) {
|
||||||
wlr_log(WLR_ERROR, "Failed to create %s buffer", iface->name);
|
wlr_log(WLR_ERROR, "Failed to create %s buffer", iface->name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = wlr_buffer_lock(custom_buffer);
|
return wlr_buffer_lock(buffer);
|
||||||
}
|
|
||||||
|
|
||||||
return 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) {
|
static void drm_destroy(struct wlr_drm *drm) {
|
||||||
wl_signal_emit_mutable(&drm->events.destroy, NULL);
|
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;
|
drm->renderer_destroy.notify = handle_renderer_destroy;
|
||||||
wl_signal_add(&renderer->events.destroy, &drm->renderer_destroy);
|
wl_signal_add(&renderer->events.destroy, &drm->renderer_destroy);
|
||||||
|
|
||||||
|
wlr_buffer_register_resource_interface(&buffer_resource_interface);
|
||||||
|
|
||||||
return drm;
|
return drm;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue