gl-renderer: Ensure gl_buffer_state is present for direct-display

This patch makes sure we have a gl_buffer_state present when using
direct-display protocol extensions (which forbids any GL imports, and
assumes a direct path with the display unit to perform a KMS import).

Without this patch we would basically have no gl_buffer_state at repaint
time because we never manged to create one, as direct-display code path
will return much early.

Partially fixes gitlab.freedesktop.org/wayland/weston/-/issues/621.

Suggested-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
dev
Marius Vlad 3 years ago
parent 0c5860fafb
commit 7ceda8cbba
  1. 65
      libweston/renderer-gl/gl-renderer.c

@ -2726,6 +2726,49 @@ gl_renderer_import_dmabuf(struct weston_compositor *ec,
return true;
}
static struct gl_buffer_state *
ensure_renderer_gl_buffer_state(struct weston_surface *surface,
struct weston_buffer *buffer)
{
struct gl_renderer *gr = get_renderer(surface->compositor);
struct gl_surface_state *gs = get_surface_state(surface);
struct gl_buffer_state *gb = buffer->renderer_private;
if (gb) {
gs->buffer = gb;
return gb;
}
gb = zalloc(sizeof(*gb));
gb->gr = gr;
pixman_region32_init(&gb->texture_damage);
buffer->renderer_private = gb;
gb->destroy_listener.notify = handle_buffer_destroy;
wl_signal_add(&buffer->destroy_signal, &gb->destroy_listener);
gs->buffer = gb;
return gb;
}
static void
attach_direct_display_censor_placeholder(struct weston_surface *surface,
struct weston_buffer *buffer)
{
struct gl_buffer_state *gb;
gb = ensure_renderer_gl_buffer_state(surface, buffer);
/* uses the same color as the content-protection placeholder */
gb->color[0] = 0.40f;
gb->color[1] = 0.0f;
gb->color[2] = 0.0f;
gb->color[3] = 1.0f;
gb->shader_variant = SHADER_VARIANT_SOLID;
}
static bool
gl_renderer_attach_dmabuf(struct weston_surface *surface,
struct weston_buffer *buffer)
@ -2737,8 +2780,10 @@ gl_renderer_attach_dmabuf(struct weston_surface *surface,
GLenum target;
int i;
if (buffer->direct_display)
if (buffer->direct_display) {
attach_direct_display_censor_placeholder(surface, buffer);
return true;
}
/* Thanks to linux-dmabuf being totally independent of libweston,
* the first time a dmabuf is attached, the gl_buffer_state will
@ -2841,21 +2886,9 @@ static bool
gl_renderer_attach_solid(struct weston_surface *surface,
struct weston_buffer *buffer)
{
struct gl_renderer *gr = get_renderer(surface->compositor);
struct gl_surface_state *gs = get_surface_state(surface);
struct gl_buffer_state *gb = buffer->renderer_private;
if (gb) {
gs->buffer = gb;
return true;
}
struct gl_buffer_state *gb;
gb = zalloc(sizeof(*gb));
gb->gr = gr;
pixman_region32_init(&gb->texture_damage);
buffer->renderer_private = gb;
gb->destroy_listener.notify = handle_buffer_destroy;
wl_signal_add(&buffer->destroy_signal, &gb->destroy_listener);
gb = ensure_renderer_gl_buffer_state(surface, buffer);
gb->color[0] = buffer->solid.r;
gb->color[1] = buffer->solid.g;
@ -2864,8 +2897,6 @@ gl_renderer_attach_solid(struct weston_surface *surface,
gb->shader_variant = SHADER_VARIANT_SOLID;
gs->buffer = gb;
return true;
}

Loading…
Cancel
Save