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 <daniels@collabora.com>
dev
Daniel Stone 3 years ago
parent 6dcf3eac1f
commit 4f88b2655e
  1. 5
      include/libweston/libweston.h
  2. 8
      libweston/compositor.c
  3. 14
      libweston/renderer-gl/gl-renderer.c

@ -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;

@ -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 ||

@ -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);

Loading…
Cancel
Save