diff options
author | eri <eri@inventati.org> | 2023-10-19 17:39:01 +0200 |
---|---|---|
committer | eri <eri@inventati.org> | 2023-10-19 18:19:27 +0200 |
commit | 8ccbe45143eff1705c0516bcdb02376d7d627198 (patch) | |
tree | 8ef830368ac02d082dda62aef530db5974a1ae45 | |
parent | 5adf325333602d5b1e7ccdeb122633bbc8040ace (diff) |
buffer: convert to try_from
References: wlroots/wlroots#884
-rw-r--r-- | include/wlr/types/wlr_buffer.h | 6 | ||||
-rw-r--r-- | types/buffer/resource.c | 10 | ||||
-rw-r--r-- | types/wlr_compositor.c | 2 | ||||
-rw-r--r-- | types/wlr_screencopy_v1.c | 2 |
4 files changed, 7 insertions, 13 deletions
diff --git a/include/wlr/types/wlr_buffer.h b/include/wlr/types/wlr_buffer.h index 7c362922..de3aeec3 100644 --- a/include/wlr/types/wlr_buffer.h +++ b/include/wlr/types/wlr_buffer.h @@ -103,7 +103,7 @@ bool wlr_buffer_get_shm(struct wlr_buffer *buffer, * * The provided struct wl_resource must be a wl_buffer. */ -struct wlr_buffer *wlr_buffer_from_resource(struct wl_resource *resource); +struct wlr_buffer *wlr_buffer_try_from_resource(struct wl_resource *resource); /** * Buffer data pointer access flags. @@ -160,9 +160,5 @@ struct wlr_client_buffer { * buffer, returns NULL. */ struct wlr_client_buffer *wlr_client_buffer_get(struct wlr_buffer *buffer); -/** - * Check if a resource is a wl_buffer resource. - */ -bool wlr_resource_is_buffer(struct wl_resource *resource); #endif diff --git a/types/buffer/resource.c b/types/buffer/resource.c index 2f1dc73c..294bac19 100644 --- a/types/buffer/resource.c +++ b/types/buffer/resource.c @@ -5,10 +5,6 @@ #include <wlr/util/log.h> #include "types/wlr_buffer.h" -bool wlr_resource_is_buffer(struct wl_resource *resource) { - return strcmp(wl_resource_get_class(resource), wl_buffer_interface.name) == 0; -} - /* struct wlr_buffer_resource_interface */ static struct wl_array buffer_resource_interfaces = {0}; @@ -43,8 +39,10 @@ static const struct wlr_buffer_resource_interface *get_buffer_resource_iface( return NULL; } -struct wlr_buffer *wlr_buffer_from_resource(struct wl_resource *resource) { - assert(resource && wlr_resource_is_buffer(resource)); +struct wlr_buffer *wlr_buffer_try_from_resource(struct wl_resource *resource) { + if (strcmp(wl_resource_get_class(resource), wl_buffer_interface.name) != 0) { + return NULL; + } const struct wlr_buffer_resource_interface *iface = get_buffer_resource_iface(resource); diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c index d860b982..15cb5f82 100644 --- a/types/wlr_compositor.c +++ b/types/wlr_compositor.c @@ -61,7 +61,7 @@ static void surface_handle_attach(struct wl_client *client, struct wlr_buffer *buffer = NULL; if (buffer_resource != NULL) { - buffer = wlr_buffer_from_resource(buffer_resource); + buffer = wlr_buffer_try_from_resource(buffer_resource); if (buffer == NULL) { wl_resource_post_error(buffer_resource, 0, "unknown buffer type"); return; diff --git a/types/wlr_screencopy_v1.c b/types/wlr_screencopy_v1.c index 91f98484..d9856608 100644 --- a/types/wlr_screencopy_v1.c +++ b/types/wlr_screencopy_v1.c @@ -350,7 +350,7 @@ static void frame_handle_copy(struct wl_client *wl_client, return; } - struct wlr_buffer *buffer = wlr_buffer_from_resource(buffer_resource); + struct wlr_buffer *buffer = wlr_buffer_try_from_resource(buffer_resource); if (buffer == NULL) { wl_resource_post_error(frame->resource, ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER, |