drm: convert to try_from

References: wlroots/wlroots#884
This commit is contained in:
eri 2023-10-19 18:04:59 +02:00
parent 8ccbe45143
commit c46d3da976
No known key found for this signature in database
GPG key ID: B9A747F39941E2A3
2 changed files with 11 additions and 9 deletions

View file

@ -45,9 +45,7 @@ struct wlr_drm {
struct wl_listener display_destroy; struct wl_listener display_destroy;
}; };
bool wlr_drm_buffer_is_resource(struct wl_resource *resource); struct wlr_drm_buffer *wlr_drm_buffer_try_from_resource(
struct wlr_drm_buffer *wlr_drm_buffer_from_resource(
struct wl_resource *resource); struct wl_resource *resource);
struct wlr_drm *wlr_drm_create(struct wl_display *display, struct wlr_drm *wlr_drm_create(struct wl_display *display,

View file

@ -55,19 +55,22 @@ static const struct wlr_buffer_impl buffer_impl = {
.get_dmabuf = buffer_get_dmabuf, .get_dmabuf = buffer_get_dmabuf,
}; };
bool wlr_drm_buffer_is_resource(struct wl_resource *resource) { static bool buffer_resource_is_instance(struct wl_resource *resource) {
return wl_resource_instance_of(resource, &wl_buffer_interface, return wl_resource_instance_of(resource, &wl_buffer_interface,
&wl_buffer_impl); &wl_buffer_impl);
} }
struct wlr_drm_buffer *wlr_drm_buffer_from_resource( struct wlr_drm_buffer *wlr_drm_buffer_try_from_resource(
struct wl_resource *resource) { struct wl_resource *resource) {
assert(wlr_drm_buffer_is_resource(resource)); if (!buffer_resource_is_instance(resource)) {
return NULL;
}
return wl_resource_get_user_data(resource); return wl_resource_get_user_data(resource);
} }
static void buffer_handle_resource_destroy(struct wl_resource *resource) { static void buffer_handle_resource_destroy(struct wl_resource *resource) {
struct wlr_drm_buffer *buffer = wlr_drm_buffer_from_resource(resource); struct wlr_drm_buffer *buffer = wlr_drm_buffer_try_from_resource(resource);
assert(buffer != NULL);
buffer->resource = NULL; buffer->resource = NULL;
wlr_buffer_drop(&buffer->base); wlr_buffer_drop(&buffer->base);
} }
@ -170,13 +173,14 @@ static void drm_bind(struct wl_client *client, void *data,
} }
static struct wlr_buffer *buffer_from_resource(struct wl_resource *resource) { static struct wlr_buffer *buffer_from_resource(struct wl_resource *resource) {
struct wlr_drm_buffer *buffer = wlr_drm_buffer_from_resource(resource); struct wlr_drm_buffer *buffer = wlr_drm_buffer_try_from_resource(resource);
assert(buffer != NULL);
return &buffer->base; return &buffer->base;
} }
static const struct wlr_buffer_resource_interface buffer_resource_interface = { static const struct wlr_buffer_resource_interface buffer_resource_interface = {
.name = "wlr_drm_buffer", .name = "wlr_drm_buffer",
.is_instance = wlr_drm_buffer_is_resource, .is_instance = buffer_resource_is_instance,
.from_resource = buffer_from_resource, .from_resource = buffer_from_resource,
}; };