shell: Explicitly use solid weston_buffers

Rather than punching through to set the surface as a solid colour,
attach an actual weston_buffer to it instead.

This becomes the first user of attaching non-client-generated buffers
to a weston_surface. As a result, it is necessary to introduce a
function which will allow compositors and shells to attach a buffer to a
surface. weston_surface_attach_solid() is therefore introduced as a
special-purpose helper which will attach a solid buffer to a
weston_surface.

It is not intended as a general-purpose mechanism to allow compositors
to attach client-generated buffers to surfaces, as doing so would have
unknown effects on this core part of the compositor itself.

Signed-off-by: Daniel Stone <daniels@collabora.com>
dev
Daniel Stone 3 years ago
parent 82b646728c
commit 4d426ab6b1
  1. 5
      include/libweston/libweston.h
  2. 55
      libweston/compositor.c
  3. 28
      shell-utils/shell-utils.c
  4. 1
      shell-utils/shell-utils.h

@ -1776,6 +1776,11 @@ struct weston_buffer_reference *
weston_buffer_create_solid_rgba(struct weston_compositor *compositor,
float r, float g, float b, float a);
void
weston_surface_attach_solid(struct weston_surface *surface,
struct weston_buffer_reference *buffer_ref,
int w, int h);
void
weston_buffer_destroy_solid(struct weston_buffer_reference *buffer_ref);

@ -2595,40 +2595,65 @@ weston_buffer_create_solid_rgba(struct weston_compositor *compositor,
float r, float g, float b, float a)
{
struct weston_buffer_reference *ret = zalloc(sizeof(*ret));
struct weston_buffer *buffer;
if (!ret)
return NULL;
ret->buffer = zalloc(sizeof(*ret->buffer));
if (!ret->buffer) {
buffer = zalloc(sizeof(*buffer));
if (!buffer) {
free(ret);
return NULL;
}
wl_signal_init(&ret->buffer->destroy_signal);
ret->buffer->type = WESTON_BUFFER_SOLID;
ret->buffer->width = 1;
ret->buffer->height = 1;
ret->buffer->buffer_origin = ORIGIN_TOP_LEFT;
ret->buffer->solid.r = r;
ret->buffer->solid.g = g;
ret->buffer->solid.b = b;
ret->buffer->solid.a = a;
wl_signal_init(&buffer->destroy_signal);
buffer->type = WESTON_BUFFER_SOLID;
buffer->width = 1;
buffer->height = 1;
buffer->buffer_origin = ORIGIN_TOP_LEFT;
buffer->solid.r = r;
buffer->solid.g = g;
buffer->solid.b = b;
buffer->solid.a = a;
if (a == 1.0) {
ret->buffer->pixel_format =
buffer->pixel_format =
pixel_format_get_info_shm(WL_SHM_FORMAT_XRGB8888);
} else {
ret->buffer->pixel_format =
buffer->pixel_format =
pixel_format_get_info_shm(WL_SHM_FORMAT_ARGB8888);
}
ret->buffer->format_modifier = DRM_FORMAT_MOD_LINEAR;
buffer->format_modifier = DRM_FORMAT_MOD_LINEAR;
weston_buffer_reference(ret, ret->buffer, BUFFER_MAY_BE_ACCESSED);
weston_buffer_reference(ret, buffer, BUFFER_MAY_BE_ACCESSED);
return ret;
}
WL_EXPORT void
weston_surface_attach_solid(struct weston_surface *surface,
struct weston_buffer_reference *buffer_ref,
int w, int h)
{
struct weston_buffer *buffer = buffer_ref->buffer;
assert(buffer);
assert(buffer->type == WESTON_BUFFER_SOLID);
weston_buffer_reference(&surface->buffer_ref, buffer,
BUFFER_MAY_BE_ACCESSED);
surface->compositor->renderer->attach(surface, buffer);
weston_surface_set_size(surface, w, h);
pixman_region32_fini(&surface->opaque);
if (buffer->solid.a == 1.0) {
surface->is_opaque = true;
pixman_region32_init_rect(&surface->opaque, 0, 0, w, h);
} else {
pixman_region32_init(&surface->opaque);
}
}
WL_EXPORT void
weston_buffer_destroy_solid(struct weston_buffer_reference *buffer_ref)
{

@ -144,6 +144,7 @@ weston_curtain_create(struct weston_compositor *compositor,
{
struct weston_curtain *curtain;
struct weston_surface *surface = NULL;
struct weston_buffer_reference *buffer_ref;
struct weston_view *view;
curtain = zalloc(sizeof(*curtain));
@ -158,22 +159,23 @@ weston_curtain_create(struct weston_compositor *compositor,
if (view == NULL)
goto err_surface;
surface->committed = params->surface_committed;
surface->committed_private = params->surface_private;
buffer_ref = weston_buffer_create_solid_rgba(compositor,
params->r,
params->g,
params->b,
params->a);
if (buffer_ref == NULL)
goto err_view;
curtain->view = view;
curtain->buffer_ref = buffer_ref;
weston_surface_set_color(surface,
params->r, params->g, params->b, params->a);
weston_surface_set_label_func(surface, params->get_label);
surface->committed = params->surface_committed;
surface->committed_private = params->surface_private;
pixman_region32_fini(&surface->opaque);
if (params->a == 1.0) {
pixman_region32_init_rect(&surface->opaque, 0, 0,
params->width, params->height);
} else {
pixman_region32_init(&surface->opaque);
}
weston_surface_attach_solid(surface, buffer_ref, params->width,
params->height);
pixman_region32_fini(&surface->input);
if (params->capture_input) {
@ -183,11 +185,12 @@ weston_curtain_create(struct weston_compositor *compositor,
pixman_region32_init(&surface->input);
}
weston_surface_set_size(surface, params->width, params->height);
weston_view_set_position(view, params->x, params->y);
return curtain;
err_view:
weston_view_destroy(view);
err_surface:
weston_surface_destroy(surface);
err_curtain:
@ -204,5 +207,6 @@ weston_curtain_destroy(struct weston_curtain *curtain)
weston_view_destroy(curtain->view);
weston_surface_destroy(surface);
weston_buffer_destroy_solid(curtain->buffer_ref);
free(curtain);
}

@ -38,6 +38,7 @@ struct weston_curtain_params {
struct weston_curtain {
struct weston_view *view;
struct weston_buffer_reference *buffer_ref;
};
struct weston_output *

Loading…
Cancel
Save