From e4933ab445c70b9ac3c0026718b29a18be171ed5 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 8 Jun 2018 20:06:13 +0100 Subject: Introduce wlr_buffer --- include/wlr/types/wlr_buffer.h | 36 ++++++++++++++++++++++++++++++++++++ include/wlr/types/wlr_surface.h | 1 + 2 files changed, 37 insertions(+) create mode 100644 include/wlr/types/wlr_buffer.h (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_buffer.h b/include/wlr/types/wlr_buffer.h new file mode 100644 index 00000000..28567f26 --- /dev/null +++ b/include/wlr/types/wlr_buffer.h @@ -0,0 +1,36 @@ +#ifndef WLR_TYPES_WLR_BUFFER_H +#define WLR_TYPES_WLR_BUFFER_H + +#include +#include + +struct wlr_buffer { + struct wl_resource *resource; + struct wlr_texture *texture; + bool released; + size_t n_refs; + + struct wl_listener resource_destroy; +}; + +struct wlr_renderer; + +// Checks if a resource is a wl_buffer. +bool wlr_resource_is_buffer(struct wl_resource *resource); +// Returns the buffer size. +bool wlr_buffer_get_resource_size(struct wl_resource *resource, + struct wlr_renderer *renderer, int *width, int *height); + +// Uploads the texture to the GPU and references it. +struct wlr_buffer *wlr_buffer_create(struct wlr_renderer *renderer, + struct wl_resource *resource); +// References and unreferences the buffer. +void wlr_buffer_ref(struct wlr_buffer *buffer); +void wlr_buffer_unref(struct wlr_buffer *buffer); +// Tries to update the texture in the provided buffer. This destroys `buffer` +// and returns a new buffer. +// Fails if `buffer->n_refs` > 1 or if the texture isn't mutable. +struct wlr_buffer *wlr_buffer_apply_damage(struct wlr_buffer *buffer, + struct wl_resource *resource, pixman_region32_t *damage); + +#endif diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h index 526e4e2c..64503e78 100644 --- a/include/wlr/types/wlr_surface.h +++ b/include/wlr/types/wlr_surface.h @@ -69,6 +69,7 @@ struct wlr_subsurface { struct wlr_surface { struct wl_resource *resource; struct wlr_renderer *renderer; + struct wlr_buffer *buffer; struct wlr_texture *texture; struct wlr_surface_state *current, *pending; const char *role; // the lifetime-bound role or null -- cgit v1.2.3 From 7d24af43e5f2fc04b41c5697101a44d67a384a12 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 8 Jun 2018 20:28:57 +0100 Subject: buffer: improve docs --- include/wlr/types/wlr_buffer.h | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_buffer.h b/include/wlr/types/wlr_buffer.h index 28567f26..c57d79ed 100644 --- a/include/wlr/types/wlr_buffer.h +++ b/include/wlr/types/wlr_buffer.h @@ -4,9 +4,12 @@ #include #include +/** + * A client buffer. + */ struct wlr_buffer { - struct wl_resource *resource; - struct wlr_texture *texture; + struct wl_resource *resource; // can be NULL + struct wlr_texture *texture; // can be NULL bool released; size_t n_refs; @@ -15,21 +18,38 @@ struct wlr_buffer { struct wlr_renderer; -// Checks if a resource is a wl_buffer. +/** + * Check if a resource is a wl_buffer resource. + */ bool wlr_resource_is_buffer(struct wl_resource *resource); -// Returns the buffer size. +/** + * Get the size of a wl_buffer resource. + */ bool wlr_buffer_get_resource_size(struct wl_resource *resource, struct wlr_renderer *renderer, int *width, int *height); -// Uploads the texture to the GPU and references it. +/** + * Upload a buffer to the GPU and reference it. + */ struct wlr_buffer *wlr_buffer_create(struct wlr_renderer *renderer, struct wl_resource *resource); -// References and unreferences the buffer. +/** + * Reference the buffer. + */ void wlr_buffer_ref(struct wlr_buffer *buffer); +/** + * Unreference the buffer. After this call, `buffer` may not be accessed + * anymore. + */ void wlr_buffer_unref(struct wlr_buffer *buffer); -// Tries to update the texture in the provided buffer. This destroys `buffer` -// and returns a new buffer. -// Fails if `buffer->n_refs` > 1 or if the texture isn't mutable. +/** + * Try to update the buffer's content. On success, returns the updated buffer + * and destroys the provided `buffer`. On error, `buffer` is intact and NULL is + * returned. + * + * Fails if there's more than one reference to the buffer or if the texture + * isn't mutable. + */ struct wlr_buffer *wlr_buffer_apply_damage(struct wlr_buffer *buffer, struct wl_resource *resource, pixman_region32_t *damage); -- cgit v1.2.3 From 38d415dd2047114badd6a9f65dab6fe0b5b8e5d0 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 11 Jun 2018 08:13:35 +0100 Subject: buffer: make wlr_buffer_ref return the buffer --- include/wlr/types/wlr_buffer.h | 2 +- types/wlr_buffer.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_buffer.h b/include/wlr/types/wlr_buffer.h index c57d79ed..fc348a1c 100644 --- a/include/wlr/types/wlr_buffer.h +++ b/include/wlr/types/wlr_buffer.h @@ -36,7 +36,7 @@ struct wlr_buffer *wlr_buffer_create(struct wlr_renderer *renderer, /** * Reference the buffer. */ -void wlr_buffer_ref(struct wlr_buffer *buffer); +struct wlr_buffer *wlr_buffer_ref(struct wlr_buffer *buffer); /** * Unreference the buffer. After this call, `buffer` may not be accessed * anymore. diff --git a/types/wlr_buffer.c b/types/wlr_buffer.c index e062df4c..82a359f0 100644 --- a/types/wlr_buffer.c +++ b/types/wlr_buffer.c @@ -105,8 +105,9 @@ struct wlr_buffer *wlr_buffer_create(struct wlr_renderer *renderer, return buffer; } -void wlr_buffer_ref(struct wlr_buffer *buffer) { +struct wlr_buffer *wlr_buffer_ref(struct wlr_buffer *buffer) { buffer->n_refs++; + return buffer; } void wlr_buffer_unref(struct wlr_buffer *buffer) { -- cgit v1.2.3