buffer: convert to try_from

References: wlroots/wlroots#884
This commit is contained in:
eri 2023-10-19 17:39:01 +02:00
parent 5adf325333
commit 8ccbe45143
No known key found for this signature in database
GPG key ID: B9A747F39941E2A3
4 changed files with 7 additions and 13 deletions

View file

@ -103,7 +103,7 @@ bool wlr_buffer_get_shm(struct wlr_buffer *buffer,
* *
* The provided struct wl_resource must be a wl_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. * Buffer data pointer access flags.
@ -160,9 +160,5 @@ struct wlr_client_buffer {
* buffer, returns NULL. * buffer, returns NULL.
*/ */
struct wlr_client_buffer *wlr_client_buffer_get(struct wlr_buffer *buffer); 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 #endif

View file

@ -5,10 +5,6 @@
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "types/wlr_buffer.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 */ /* struct wlr_buffer_resource_interface */
static struct wl_array buffer_resource_interfaces = {0}; 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; return NULL;
} }
struct wlr_buffer *wlr_buffer_from_resource(struct wl_resource *resource) { struct wlr_buffer *wlr_buffer_try_from_resource(struct wl_resource *resource) {
assert(resource && wlr_resource_is_buffer(resource)); if (strcmp(wl_resource_get_class(resource), wl_buffer_interface.name) != 0) {
return NULL;
}
const struct wlr_buffer_resource_interface *iface = const struct wlr_buffer_resource_interface *iface =
get_buffer_resource_iface(resource); get_buffer_resource_iface(resource);

View file

@ -61,7 +61,7 @@ static void surface_handle_attach(struct wl_client *client,
struct wlr_buffer *buffer = NULL; struct wlr_buffer *buffer = NULL;
if (buffer_resource != NULL) { if (buffer_resource != NULL) {
buffer = wlr_buffer_from_resource(buffer_resource); buffer = wlr_buffer_try_from_resource(buffer_resource);
if (buffer == NULL) { if (buffer == NULL) {
wl_resource_post_error(buffer_resource, 0, "unknown buffer type"); wl_resource_post_error(buffer_resource, 0, "unknown buffer type");
return; return;

View file

@ -350,7 +350,7 @@ static void frame_handle_copy(struct wl_client *wl_client,
return; 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) { if (buffer == NULL) {
wl_resource_post_error(frame->resource, wl_resource_post_error(frame->resource,
ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER, ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER,