From 8afc1ed68cfaab0c85dd3252f7680d0a6e9e511e Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 28 Feb 2020 12:32:43 +0100 Subject: Introduce wlr_client_buffer Split out the client/resource handling out of wlr_buffer by introducing wlr_client_buffer. Make wlr_buffer an interface so that compositors can create their own wlr_buffers (e.g. backed by GBM, like glider [1]). [1]: https://github.com/emersion/glider/blob/c66847dd1cf8ae5e68666ce7cb3be41427b38dc7/include/gbm_allocator.h#L7 --- include/wlr/types/wlr_buffer.h | 67 +++++++++++++++++++++++++++-------------- include/wlr/types/wlr_surface.h | 2 +- 2 files changed, 46 insertions(+), 23 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_buffer.h b/include/wlr/types/wlr_buffer.h index 86f8bccb..b46b69a0 100644 --- a/include/wlr/types/wlr_buffer.h +++ b/include/wlr/types/wlr_buffer.h @@ -13,14 +13,52 @@ #include #include +struct wlr_buffer; + +struct wlr_buffer_impl { + void (*destroy)(struct wlr_buffer *buffer); + bool (*get_dmabuf)(struct wlr_buffer *buffer, + struct wlr_dmabuf_attributes *attribs); +}; + +struct wlr_buffer { + const struct wlr_buffer_impl *impl; + + size_t n_refs; +}; + +void wlr_buffer_init(struct wlr_buffer *buffer, + const struct wlr_buffer_impl *impl); +/** + * Reference the buffer. + */ +struct wlr_buffer *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); +/** + * Reads the DMA-BUF attributes of the buffer. If this buffer isn't a DMA-BUF, + * returns false. + */ +bool wlr_buffer_get_dmabuf(struct wlr_buffer *buffer, + struct wlr_dmabuf_attributes *attribs); + /** * A client buffer. */ -struct wlr_buffer { +struct wlr_client_buffer { + struct wlr_buffer base; + /** * The buffer resource, if any. Will be NULL if the client destroys it. */ struct wl_resource *resource; + /** + * Whether a release event has been sent to the resource. + */ + bool resource_released; /** * The buffer's texture, if any. A buffer will not have a texture if the * client destroys the buffer before it has been released. @@ -41,23 +79,13 @@ bool wlr_resource_is_buffer(struct wl_resource *resource); /** * Get the size of a wl_buffer resource. */ -bool wlr_buffer_get_resource_size(struct wl_resource *resource, +bool wlr_resource_get_buffer_size(struct wl_resource *resource, struct wlr_renderer *renderer, int *width, int *height); - /** * Upload a buffer to the GPU and reference it. */ -struct wlr_buffer *wlr_buffer_create(struct wlr_renderer *renderer, - struct wl_resource *resource); -/** - * Reference the buffer. - */ -struct wlr_buffer *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); +struct wlr_client_buffer *wlr_client_buffer_create( + struct wlr_renderer *renderer, struct wl_resource *resource); /** * 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 @@ -66,13 +94,8 @@ void wlr_buffer_unref(struct wlr_buffer *buffer); * 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); -/** - * Reads the DMA-BUF attributes of the buffer. If this buffer isn't a DMA-BUF, - * returns false. - */ -bool wlr_buffer_get_dmabuf(struct wlr_buffer *buffer, - struct wlr_dmabuf_attributes *attribs); +struct wlr_client_buffer *wlr_client_buffer_apply_damage( + struct wlr_client_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 f62171d1..fa9fa6d5 100644 --- a/include/wlr/types/wlr_surface.h +++ b/include/wlr/types/wlr_surface.h @@ -59,7 +59,7 @@ struct wlr_surface { * have a buffer if it has never committed one, has committed a null buffer, * or something went wrong with uploading the buffer. */ - struct wlr_buffer *buffer; + struct wlr_client_buffer *buffer; /** * The buffer position, in surface-local units. */ -- cgit v1.2.3