From 4f88b2655e0d2f953970ecd40bcecfb95e4c6799 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Sat, 15 Jan 2022 17:36:02 +0000 Subject: [PATCH] weston_buffer: Change y_inverted to explicit origin enum y_inverted meant that the buffer's origin was (0,0), and non-inverted meant that the buffer's origin was (0,height). In practice, every buffer was 'inverted' into our natural co-ordinate space that we use everywhere. Switch to using an explicit origin enum to make this more clear. Signed-off-by: Daniel Stone --- include/libweston/libweston.h | 5 ++++- libweston/compositor.c | 8 +++++--- libweston/renderer-gl/gl-renderer.c | 14 +++++++++----- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index 4be9f8d4..3576426f 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -1191,7 +1191,10 @@ struct weston_buffer { int32_t width, height; uint32_t busy_count; - int y_inverted; + enum { + ORIGIN_TOP_LEFT, /* buffer content starts at (0,0) */ + ORIGIN_BOTTOM_LEFT, /* buffer content starts at (0, height) */ + } buffer_origin; void *backend_private; const struct pixel_format_info *pixel_format; diff --git a/libweston/compositor.c b/libweston/compositor.c index 4e276b4e..51e55ef2 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -2415,7 +2415,7 @@ weston_buffer_from_resource(struct weston_compositor *ec, buffer->shm_buffer = shm; buffer->width = wl_shm_buffer_get_width(shm); buffer->height = wl_shm_buffer_get_height(shm); - buffer->y_inverted = true; + buffer->buffer_origin = ORIGIN_TOP_LEFT; /* wl_shm might create a buffer with an unknown format, so check * and reject */ buffer->pixel_format = @@ -2435,8 +2435,10 @@ weston_buffer_from_resource(struct weston_compositor *ec, * unknown format */ assert(buffer->pixel_format); buffer->format_modifier = dmabuf->attributes.modifier[0]; - buffer->y_inverted = - !(dmabuf->attributes.flags & ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT); + if (dmabuf->attributes.flags & ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT) + buffer->buffer_origin = ORIGIN_BOTTOM_LEFT; + else + buffer->buffer_origin = ORIGIN_TOP_LEFT; } else { /* Only taken for legacy EGL buffers */ if (!ec->renderer->fill_buffer_info || diff --git a/libweston/renderer-gl/gl-renderer.c b/libweston/renderer-gl/gl-renderer.c index a87ac466..bf4435b6 100644 --- a/libweston/renderer-gl/gl-renderer.c +++ b/libweston/renderer-gl/gl-renderer.c @@ -2160,6 +2160,7 @@ gl_renderer_fill_buffer_info(struct weston_compositor *ec, struct gl_renderer *gr = get_renderer(ec); EGLint format; uint32_t fourcc; + EGLint y_inverted; bool ret = true; buffer->legacy_buffer = (struct wl_buffer *)buffer->resource; @@ -2201,9 +2202,12 @@ gl_renderer_fill_buffer_info(struct weston_compositor *ec, /* Assume scanout co-ordinate space i.e. (0,0) is top-left * if the query fails */ - buffer->y_inverted = true; - gr->query_buffer(gr->egl_display, buffer->legacy_buffer, - EGL_WAYLAND_Y_INVERTED_WL, &buffer->y_inverted); + ret = gr->query_buffer(gr->egl_display, buffer->legacy_buffer, + EGL_WAYLAND_Y_INVERTED_WL, &y_inverted); + if (!ret || y_inverted) + buffer->buffer_origin = ORIGIN_TOP_LEFT; + else + buffer->buffer_origin = ORIGIN_BOTTOM_LEFT; return true; } @@ -2281,7 +2285,7 @@ gl_renderer_attach_egl(struct weston_surface *es, struct weston_buffer *buffer, gs->pitch = buffer->width; gs->height = buffer->height; gs->buffer_type = BUFFER_TYPE_EGL; - gs->y_inverted = buffer->y_inverted; + gs->y_inverted = (buffer->buffer_origin == ORIGIN_TOP_LEFT); } static void @@ -2873,7 +2877,7 @@ gl_renderer_attach_dmabuf(struct weston_surface *surface, gs->pitch = buffer->width; gs->height = buffer->height; gs->buffer_type = BUFFER_TYPE_EGL; - gs->y_inverted = buffer->y_inverted; + gs->y_inverted = (buffer->buffer_origin == ORIGIN_TOP_LEFT); gs->direct_display = dmabuf->direct_display; surface->is_opaque = dmabuf_is_opaque(dmabuf);