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 <daniels@collabora.com>
dev
Daniel Stone 3 years ago
parent 1d5f8af82e
commit 34cd0d114f
  1. 8
      include/libweston/libweston.h
  2. 4
      libweston/compositor.c

@ -1177,10 +1177,18 @@ struct weston_buffer {
struct wl_signal destroy_signal; struct wl_signal destroy_signal;
struct wl_listener destroy_listener; struct wl_listener destroy_listener;
enum {
WESTON_BUFFER_SHM,
WESTON_BUFFER_DMABUF,
WESTON_BUFFER_RENDERER_OPAQUE,
} type;
union { union {
struct wl_shm_buffer *shm_buffer; struct wl_shm_buffer *shm_buffer;
void *dmabuf;
void *legacy_buffer; void *legacy_buffer;
}; };
int32_t width, height; int32_t width, height;
uint32_t busy_count; uint32_t busy_count;
int y_inverted; int y_inverted;

@ -2410,11 +2410,14 @@ weston_buffer_from_resource(struct weston_compositor *ec,
wl_resource_add_destroy_listener(resource, &buffer->destroy_listener); wl_resource_add_destroy_listener(resource, &buffer->destroy_listener);
if ((shm = wl_shm_buffer_get(buffer->resource))) { if ((shm = wl_shm_buffer_get(buffer->resource))) {
buffer->type = WESTON_BUFFER_SHM;
buffer->shm_buffer = shm; buffer->shm_buffer = shm;
buffer->width = wl_shm_buffer_get_width(shm); buffer->width = wl_shm_buffer_get_width(shm);
buffer->height = wl_shm_buffer_get_height(shm); buffer->height = wl_shm_buffer_get_height(shm);
buffer->y_inverted = true; buffer->y_inverted = true;
} else if ((dmabuf = linux_dmabuf_buffer_get(buffer->resource))) { } else if ((dmabuf = linux_dmabuf_buffer_get(buffer->resource))) {
buffer->type = WESTON_BUFFER_DMABUF;
buffer->dmabuf = dmabuf;
buffer->width = dmabuf->attributes.width; buffer->width = dmabuf->attributes.width;
buffer->height = dmabuf->attributes.height; buffer->height = dmabuf->attributes.height;
buffer->y_inverted = buffer->y_inverted =
@ -2425,6 +2428,7 @@ weston_buffer_from_resource(struct weston_compositor *ec,
!ec->renderer->fill_buffer_info(ec, buffer)) { !ec->renderer->fill_buffer_info(ec, buffer)) {
goto fail; goto fail;
} }
buffer->type = WESTON_BUFFER_RENDERER_OPAQUE;
} }
return buffer; return buffer;

Loading…
Cancel
Save