From 195dadeb2add729735c32b9e394d7d1397cf065c Mon Sep 17 00:00:00 2001 From: Philipp Zabel Date: Mon, 3 Sep 2018 19:44:59 +0200 Subject: [PATCH] libweston: add weston_surface is_opaque property Add an is_opaque property that is set to true if the attached buffer does not have an alpha component, or if the solid color is non-transparent. Signed-off-by: Philipp Zabel --- libweston/compositor.c | 1 + libweston/compositor.h | 1 + libweston/gl-renderer.c | 29 +++++++++++++++++++++++++++++ libweston/pixman-renderer.c | 3 +++ 4 files changed, 34 insertions(+) diff --git a/libweston/compositor.c b/libweston/compositor.c index e867ec1e..0dcb1df3 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -532,6 +532,7 @@ weston_surface_set_color(struct weston_surface *surface, float red, float green, float blue, float alpha) { surface->compositor->renderer->surface_set_color(surface, red, green, blue, alpha); + surface->is_opaque = !(alpha < 1.0); } WL_EXPORT void diff --git a/libweston/compositor.h b/libweston/compositor.h index 49013e14..6a57b829 100644 --- a/libweston/compositor.h +++ b/libweston/compositor.h @@ -1481,6 +1481,7 @@ struct weston_surface { struct weston_timeline_object timeline; bool is_mapped; + bool is_opaque; /* An list of per seat pointer constraints. */ struct wl_list pointer_constraints; diff --git a/libweston/gl-renderer.c b/libweston/gl-renderer.c index 7a848cd1..95cbc22e 100644 --- a/libweston/gl-renderer.c +++ b/libweston/gl-renderer.c @@ -54,6 +54,7 @@ #include "vertex-clipping.h" #include "linux-dmabuf.h" #include "linux-dmabuf-unstable-v1-server-protocol.h" +#include "pixel-formats.h" #include "shared/helpers.h" #include "shared/platform.h" @@ -1570,18 +1571,21 @@ gl_renderer_attach_shm(struct weston_surface *es, struct weston_buffer *buffer, pitch = wl_shm_buffer_get_stride(shm_buffer) / 4; gl_format[0] = GL_BGRA_EXT; gl_pixel_type = GL_UNSIGNED_BYTE; + es->is_opaque = true; break; case WL_SHM_FORMAT_ARGB8888: gs->shader = &gr->texture_shader_rgba; pitch = wl_shm_buffer_get_stride(shm_buffer) / 4; gl_format[0] = GL_BGRA_EXT; gl_pixel_type = GL_UNSIGNED_BYTE; + es->is_opaque = false; break; case WL_SHM_FORMAT_RGB565: gs->shader = &gr->texture_shader_rgbx; pitch = wl_shm_buffer_get_stride(shm_buffer) / 2; gl_format[0] = GL_RGB; gl_pixel_type = GL_UNSIGNED_SHORT_5_6_5; + es->is_opaque = true; break; case WL_SHM_FORMAT_YUV420: gs->shader = &gr->texture_shader_y_u_v; @@ -1605,6 +1609,7 @@ gl_renderer_attach_shm(struct weston_surface *es, struct weston_buffer *buffer, gl_format[1] = GL_LUMINANCE; gl_format[2] = GL_LUMINANCE; } + es->is_opaque = true; break; case WL_SHM_FORMAT_NV12: pitch = wl_shm_buffer_get_stride(shm_buffer); @@ -1623,6 +1628,7 @@ gl_renderer_attach_shm(struct weston_surface *es, struct weston_buffer *buffer, gl_format[0] = GL_LUMINANCE; gl_format[1] = GL_LUMINANCE_ALPHA; } + es->is_opaque = true; break; case WL_SHM_FORMAT_YUYV: gs->shader = &gr->texture_shader_y_xuxv; @@ -1637,6 +1643,7 @@ gl_renderer_attach_shm(struct weston_surface *es, struct weston_buffer *buffer, else gl_format[0] = GL_LUMINANCE_ALPHA; gl_format[1] = GL_BGRA_EXT; + es->is_opaque = true; break; default: weston_log("warning: unknown shm buffer format: %08x\n", @@ -1695,8 +1702,11 @@ gl_renderer_attach_egl(struct weston_surface *es, struct weston_buffer *buffer, } gs->num_images = 0; gs->target = GL_TEXTURE_2D; + es->is_opaque = false; switch (format) { case EGL_TEXTURE_RGB: + es->is_opaque = true; + /* fallthrough */ case EGL_TEXTURE_RGBA: default: num_planes = 1; @@ -1710,14 +1720,17 @@ gl_renderer_attach_egl(struct weston_surface *es, struct weston_buffer *buffer, case EGL_TEXTURE_Y_UV_WL: num_planes = 2; gs->shader = &gr->texture_shader_y_uv; + es->is_opaque = true; break; case EGL_TEXTURE_Y_U_V_WL: num_planes = 3; gs->shader = &gr->texture_shader_y_u_v; + es->is_opaque = true; break; case EGL_TEXTURE_Y_XUXV_WL: num_planes = 2; gs->shader = &gr->texture_shader_y_xuxv; + es->is_opaque = true; break; } @@ -2233,6 +2246,19 @@ import_known_dmabuf(struct gl_renderer *gr, return true; } +static bool +dmabuf_is_opaque(struct linux_dmabuf_buffer *dmabuf) +{ + const struct pixel_format_info *info; + + info = pixel_format_get_info(dmabuf->attributes.format & + ~DRM_FORMAT_BIG_ENDIAN); + if (!info) + return false; + + return pixel_format_is_opaque(info); +} + static void gl_renderer_attach_dmabuf(struct weston_surface *surface, struct weston_buffer *buffer, @@ -2305,6 +2331,7 @@ gl_renderer_attach_dmabuf(struct weston_surface *surface, gs->height = buffer->height; gs->buffer_type = BUFFER_TYPE_EGL; gs->y_inverted = buffer->y_inverted; + surface->is_opaque = dmabuf_is_opaque(dmabuf); } static void @@ -2330,6 +2357,7 @@ gl_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer) gs->num_textures = 0; gs->buffer_type = BUFFER_TYPE_NULL; gs->y_inverted = 1; + es->is_opaque = false; return; } @@ -2348,6 +2376,7 @@ gl_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer) weston_buffer_reference(&gs->buffer_ref, NULL); gs->buffer_type = BUFFER_TYPE_NULL; gs->y_inverted = 1; + es->is_opaque = false; } } diff --git a/libweston/pixman-renderer.c b/libweston/pixman-renderer.c index 1ea275b4..a316766e 100644 --- a/libweston/pixman-renderer.c +++ b/libweston/pixman-renderer.c @@ -650,12 +650,15 @@ pixman_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer) switch (wl_shm_buffer_get_format(shm_buffer)) { case WL_SHM_FORMAT_XRGB8888: pixman_format = PIXMAN_x8r8g8b8; + es->is_opaque = true; break; case WL_SHM_FORMAT_ARGB8888: pixman_format = PIXMAN_a8r8g8b8; + es->is_opaque = false; break; case WL_SHM_FORMAT_RGB565: pixman_format = PIXMAN_r5g6b5; + es->is_opaque = true; break; default: weston_log("Unsupported SHM buffer format\n");