From 34cd0d114f23e75ddecaf7d60f904af0e99a17ad Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Fri, 14 Jan 2022 01:09:51 +0000 Subject: [PATCH] weston_buffer: Add type field Rather than open-coding various resource -> type accessors, just stick a type enum in the buffer struct. Signed-off-by: Daniel Stone --- include/libweston/libweston.h | 8 ++++++++ libweston/compositor.c | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index 974df395..5cb5c60a 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -1177,10 +1177,18 @@ struct weston_buffer { struct wl_signal destroy_signal; struct wl_listener destroy_listener; + enum { + WESTON_BUFFER_SHM, + WESTON_BUFFER_DMABUF, + WESTON_BUFFER_RENDERER_OPAQUE, + } type; + union { struct wl_shm_buffer *shm_buffer; + void *dmabuf; void *legacy_buffer; }; + int32_t width, height; uint32_t busy_count; int y_inverted; diff --git a/libweston/compositor.c b/libweston/compositor.c index e9188422..d24fd030 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -2410,11 +2410,14 @@ weston_buffer_from_resource(struct weston_compositor *ec, wl_resource_add_destroy_listener(resource, &buffer->destroy_listener); if ((shm = wl_shm_buffer_get(buffer->resource))) { + buffer->type = WESTON_BUFFER_SHM; buffer->shm_buffer = shm; buffer->width = wl_shm_buffer_get_width(shm); buffer->height = wl_shm_buffer_get_height(shm); buffer->y_inverted = true; } else if ((dmabuf = linux_dmabuf_buffer_get(buffer->resource))) { + buffer->type = WESTON_BUFFER_DMABUF; + buffer->dmabuf = dmabuf; buffer->width = dmabuf->attributes.width; buffer->height = dmabuf->attributes.height; buffer->y_inverted = @@ -2425,6 +2428,7 @@ weston_buffer_from_resource(struct weston_compositor *ec, !ec->renderer->fill_buffer_info(ec, buffer)) { goto fail; } + buffer->type = WESTON_BUFFER_RENDERER_OPAQUE; } return buffer;