weston_buffer: Make use of weston_buffer->type

Rather than calling accessors (wl_shm_buffer_get etc) to figure out
which type our buffer is, just look in the structure.

Signed-off-by: Daniel Stone <daniels@collabora.com>
dev
Daniel Stone 3 years ago
parent 34cd0d114f
commit fef8bb275c
  1. 13
      libweston/backend-drm/fb.c
  2. 42
      libweston/compositor.c
  3. 5
      libweston/noop-renderer.c
  4. 6
      libweston/pixman-renderer.c
  5. 59
      libweston/renderer-gl/gl-renderer.c
  6. 2
      libweston/screenshooter.c

@ -522,7 +522,6 @@ drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev,
struct weston_buffer *buffer = ev->surface->buffer_ref.buffer;
struct drm_buffer_fb *buf_fb;
bool is_opaque = weston_view_is_opaque(ev, &ev->transform.boundingbox);
struct linux_dmabuf_buffer *dmabuf;
struct drm_fb *fb;
struct drm_plane *plane;
@ -550,20 +549,16 @@ drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev,
buf_fb->buffer_destroy_listener.notify = drm_fb_handle_buffer_destroy;
wl_signal_add(&buffer->destroy_signal, &buf_fb->buffer_destroy_listener);
if (wl_shm_buffer_get(buffer->resource))
goto unsuitable;
/* GBM is used for dmabuf import as well as from client wl_buffer. */
if (!b->gbm)
goto unsuitable;
dmabuf = linux_dmabuf_buffer_get(buffer->resource);
if (dmabuf) {
fb = drm_fb_get_from_dmabuf(dmabuf, b, is_opaque,
if (buffer->type == WESTON_BUFFER_DMABUF) {
fb = drm_fb_get_from_dmabuf(buffer->dmabuf, b, is_opaque,
&buf_fb->failure_reasons);
if (!fb)
goto unsuitable;
} else {
} else if (buffer->type == WESTON_BUFFER_RENDERER_OPAQUE) {
struct gbm_bo *bo;
bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_WL_BUFFER,
@ -576,6 +571,8 @@ drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev,
gbm_bo_destroy(bo);
goto unsuitable;
}
} else {
goto unsuitable;
}
/* Check if this buffer can ever go on any planes. If it can't, we have

@ -2584,7 +2584,7 @@ surface_flush_damage(struct weston_surface *surface)
{
struct weston_buffer *buffer = surface->buffer_ref.buffer;
if (buffer && wl_shm_buffer_get(buffer->resource))
if (buffer && buffer->type == WESTON_BUFFER_SHM)
surface->compositor->renderer->flush_damage(surface, buffer);
if (pixman_region32_not_empty(&surface->damage))
@ -3978,14 +3978,7 @@ surface_commit(struct wl_client *client, struct wl_resource *resource)
return;
}
/* We support fences for both wp_linux_dmabuf and opaque EGL
* buffers, as mandated by minor version 2 of the
* zwp_linux_explicit_synchronization_v1 protocol. Since
* renderers that support fences currently only support these
* two buffer types plus SHM buffers, we can just check for the
* SHM buffer case here.
*/
if (wl_shm_buffer_get(surface->pending.buffer->resource)) {
if (surface->pending.buffer->type == WESTON_BUFFER_SHM) {
fd_clear(&surface->pending.acquire_fence_fd);
wl_resource_post_error(surface->synchronization_resource,
ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_UNSUPPORTED_BUFFER,
@ -7473,30 +7466,30 @@ static void
debug_scene_view_print_buffer(FILE *fp, struct weston_view *view)
{
struct weston_buffer *buffer = view->surface->buffer_ref.buffer;
struct wl_shm_buffer *shm;
struct linux_dmabuf_buffer *dmabuf;
struct wl_shm_buffer *shm = buffer->shm_buffer;
struct linux_dmabuf_buffer *dmabuf = buffer->dmabuf;
const struct pixel_format_info *pixel_info = NULL;
uint32_t _format;
uint64_t modifier;
char *modifier_name;
if (!buffer) {
fprintf(fp, "\t\t[buffer not available]\n");
return;
}
shm = wl_shm_buffer_get(buffer->resource);
if (shm) {
uint32_t _format = wl_shm_buffer_get_format(shm);
switch (buffer->type) {
case WESTON_BUFFER_SHM:
_format = wl_shm_buffer_get_format(shm);
pixel_info = pixel_format_get_info_shm(_format);
fprintf(fp, "\t\tSHM buffer\n");
fprintf(fp, "\t\t\tformat: 0x%lx %s\n",
(unsigned long) _format,
pixel_info ? pixel_info->drm_format_name : "UNKNOWN");
return;
}
dmabuf = linux_dmabuf_buffer_get(buffer->resource);
if (dmabuf) {
uint64_t modifier = dmabuf->attributes.modifier[0];
char *modifier_name = pixel_format_get_modifier(modifier);
break;
case WESTON_BUFFER_DMABUF:
modifier = dmabuf->attributes.modifier[0];
modifier_name = pixel_format_get_modifier(modifier);
pixel_info = pixel_format_get_info(dmabuf->attributes.format);
fprintf(fp, "\t\tdmabuf buffer\n");
fprintf(fp, "\t\t\tformat: 0x%lx %s\n",
@ -7506,10 +7499,11 @@ debug_scene_view_print_buffer(FILE *fp, struct weston_view *view)
fprintf(fp, "\t\t\tmodifier: %s\n", modifier_name ? modifier_name :
"Failed to convert to a modifier name");
free(modifier_name);
return;
break;
default:
fprintf(fp, "\t\tEGL buffer\n");
break;
}
fprintf(fp, "\t\tEGL buffer\n");
}
static void

@ -63,13 +63,12 @@ noop_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
if (!buffer)
return;
shm_buffer = wl_shm_buffer_get(buffer->resource);
if (!shm_buffer) {
if (buffer->type != WESTON_BUFFER_SHM) {
weston_log("No-op renderer supports only SHM buffers\n");
return;
}
shm_buffer = buffer->shm_buffer;
data = wl_shm_buffer_get_data(shm_buffer);
stride = wl_shm_buffer_get_stride(shm_buffer);
width = wl_shm_buffer_get_width(shm_buffer);

@ -644,15 +644,15 @@ pixman_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
if (!buffer)
return;
shm_buffer = wl_shm_buffer_get(buffer->resource);
if (! shm_buffer) {
if (buffer->type != WESTON_BUFFER_SHM) {
weston_log("Pixman renderer supports only SHM buffers\n");
weston_buffer_reference(&ps->buffer_ref, NULL);
weston_buffer_release_reference(&ps->buffer_release_ref, NULL);
return;
}
shm_buffer = buffer->shm_buffer;
pixel_info = pixel_format_get_info_shm(wl_shm_buffer_get_format(shm_buffer));
if (!pixel_info || !pixman_format_supported_source(pixel_info->pixman_format)) {
weston_log("Unsupported SHM buffer format 0x%x\n",

@ -888,7 +888,7 @@ ensure_surface_buffer_is_ready(struct gl_renderer *gr,
assert(gr->has_native_fence_sync);
/* We should only get a fence for non-SHM buffers, since surface
* commit would have failed otherwise. */
assert(wl_shm_buffer_get(buffer->resource) == NULL);
assert(buffer->type != WESTON_BUFFER_SHM);
attribs[1] = dup(surface->acquire_fence_fd);
if (attribs[1] == -1) {
@ -2938,8 +2938,6 @@ gl_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
struct weston_compositor *ec = es->compositor;
struct gl_renderer *gr = get_renderer(ec);
struct gl_surface_state *gs = get_surface_state(es);
struct wl_shm_buffer *shm_buffer;
struct linux_dmabuf_buffer *dmabuf;
EGLint format;
int i;
@ -2962,30 +2960,38 @@ gl_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
return;
}
shm_buffer = wl_shm_buffer_get(buffer->resource);
if (shm_buffer)
gl_renderer_attach_shm(es, buffer, shm_buffer);
else if (gr->has_bind_display &&
gr->query_buffer(gr->egl_display, (void *)buffer->resource,
EGL_TEXTURE_FORMAT, &format))
gl_renderer_attach_egl(es, buffer, format);
else if ((dmabuf = linux_dmabuf_buffer_get(buffer->resource)))
gl_renderer_attach_dmabuf(es, buffer, dmabuf);
else {
weston_log("unhandled buffer type!\n");
if (gr->has_bind_display) {
weston_log("eglQueryWaylandBufferWL failed\n");
gl_renderer_print_egl_error_state();
switch (buffer->type) {
case WESTON_BUFFER_SHM:
gl_renderer_attach_shm(es, buffer, buffer->shm_buffer);
return;
case WESTON_BUFFER_DMABUF:
gl_renderer_attach_dmabuf(es, buffer, buffer->dmabuf);
return;
case WESTON_BUFFER_RENDERER_OPAQUE:
if (!gr->has_bind_display ||
!gr->query_buffer(gr->egl_display,
buffer->legacy_buffer,
EGL_TEXTURE_FORMAT, &format)) {
break;
}
weston_buffer_reference(&gs->buffer_ref, NULL);
weston_buffer_release_reference(&gs->buffer_release_ref, NULL);
gs->buffer_type = BUFFER_TYPE_NULL;
gs->y_inverted = true;
es->is_opaque = false;
weston_buffer_send_server_error(buffer,
"disconnecting due to unhandled buffer type");
gl_renderer_attach_egl(es, buffer, format);
return;
default:
break;
}
weston_log("unhandled buffer type!\n");
if (gr->has_bind_display) {
weston_log("eglQueryWaylandBufferWL failed\n");
gl_renderer_print_egl_error_state();
}
weston_buffer_reference(&gs->buffer_ref, NULL);
weston_buffer_release_reference(&gs->buffer_release_ref, NULL);
gs->buffer_type = BUFFER_TYPE_NULL;
gs->y_inverted = true;
es->is_opaque = false;
weston_buffer_send_server_error(buffer,
"disconnecting due to unhandled buffer type");
}
static void
@ -3232,8 +3238,7 @@ gl_renderer_create_surface(struct weston_surface *surface)
if (surface->buffer_ref.buffer) {
gl_renderer_attach(surface, surface->buffer_ref.buffer);
if (surface->buffer_ref.buffer->resource &&
wl_shm_buffer_get(surface->buffer_ref.buffer->resource)) {
if (surface->buffer_ref.buffer->type == WESTON_BUFFER_SHM) {
gl_renderer_flush_damage(surface,
surface->buffer_ref.buffer);
}

@ -181,7 +181,7 @@ weston_screenshooter_shoot(struct weston_output *output,
{
struct screenshooter_frame_listener *l;
if (!wl_shm_buffer_get(buffer->resource)) {
if (buffer->type != WESTON_BUFFER_SHM) {
done(data, WESTON_SCREENSHOOTER_BAD_BUFFER);
return -1;
}

Loading…
Cancel
Save