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 weston_buffer *buffer = ev->surface->buffer_ref.buffer;
struct drm_buffer_fb *buf_fb; struct drm_buffer_fb *buf_fb;
bool is_opaque = weston_view_is_opaque(ev, &ev->transform.boundingbox); bool is_opaque = weston_view_is_opaque(ev, &ev->transform.boundingbox);
struct linux_dmabuf_buffer *dmabuf;
struct drm_fb *fb; struct drm_fb *fb;
struct drm_plane *plane; 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; buf_fb->buffer_destroy_listener.notify = drm_fb_handle_buffer_destroy;
wl_signal_add(&buffer->destroy_signal, &buf_fb->buffer_destroy_listener); 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. */ /* GBM is used for dmabuf import as well as from client wl_buffer. */
if (!b->gbm) if (!b->gbm)
goto unsuitable; goto unsuitable;
dmabuf = linux_dmabuf_buffer_get(buffer->resource); if (buffer->type == WESTON_BUFFER_DMABUF) {
if (dmabuf) { fb = drm_fb_get_from_dmabuf(buffer->dmabuf, b, is_opaque,
fb = drm_fb_get_from_dmabuf(dmabuf, b, is_opaque,
&buf_fb->failure_reasons); &buf_fb->failure_reasons);
if (!fb) if (!fb)
goto unsuitable; goto unsuitable;
} else { } else if (buffer->type == WESTON_BUFFER_RENDERER_OPAQUE) {
struct gbm_bo *bo; struct gbm_bo *bo;
bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_WL_BUFFER, 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); gbm_bo_destroy(bo);
goto unsuitable; goto unsuitable;
} }
} else {
goto unsuitable;
} }
/* Check if this buffer can ever go on any planes. If it can't, we have /* 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; 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); surface->compositor->renderer->flush_damage(surface, buffer);
if (pixman_region32_not_empty(&surface->damage)) if (pixman_region32_not_empty(&surface->damage))
@ -3978,14 +3978,7 @@ surface_commit(struct wl_client *client, struct wl_resource *resource)
return; return;
} }
/* We support fences for both wp_linux_dmabuf and opaque EGL if (surface->pending.buffer->type == WESTON_BUFFER_SHM) {
* 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)) {
fd_clear(&surface->pending.acquire_fence_fd); fd_clear(&surface->pending.acquire_fence_fd);
wl_resource_post_error(surface->synchronization_resource, wl_resource_post_error(surface->synchronization_resource,
ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_UNSUPPORTED_BUFFER, 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) debug_scene_view_print_buffer(FILE *fp, struct weston_view *view)
{ {
struct weston_buffer *buffer = view->surface->buffer_ref.buffer; struct weston_buffer *buffer = view->surface->buffer_ref.buffer;
struct wl_shm_buffer *shm; struct wl_shm_buffer *shm = buffer->shm_buffer;
struct linux_dmabuf_buffer *dmabuf; struct linux_dmabuf_buffer *dmabuf = buffer->dmabuf;
const struct pixel_format_info *pixel_info = NULL; const struct pixel_format_info *pixel_info = NULL;
uint32_t _format;
uint64_t modifier;
char *modifier_name;
if (!buffer) { if (!buffer) {
fprintf(fp, "\t\t[buffer not available]\n"); fprintf(fp, "\t\t[buffer not available]\n");
return; return;
} }
shm = wl_shm_buffer_get(buffer->resource); switch (buffer->type) {
if (shm) { case WESTON_BUFFER_SHM:
uint32_t _format = wl_shm_buffer_get_format(shm); _format = wl_shm_buffer_get_format(shm);
pixel_info = pixel_format_get_info_shm(_format); pixel_info = pixel_format_get_info_shm(_format);
fprintf(fp, "\t\tSHM buffer\n"); fprintf(fp, "\t\tSHM buffer\n");
fprintf(fp, "\t\t\tformat: 0x%lx %s\n", fprintf(fp, "\t\t\tformat: 0x%lx %s\n",
(unsigned long) _format, (unsigned long) _format,
pixel_info ? pixel_info->drm_format_name : "UNKNOWN"); pixel_info ? pixel_info->drm_format_name : "UNKNOWN");
return; break;
} case WESTON_BUFFER_DMABUF:
modifier = dmabuf->attributes.modifier[0];
dmabuf = linux_dmabuf_buffer_get(buffer->resource); modifier_name = pixel_format_get_modifier(modifier);
if (dmabuf) {
uint64_t modifier = dmabuf->attributes.modifier[0];
char *modifier_name = pixel_format_get_modifier(modifier);
pixel_info = pixel_format_get_info(dmabuf->attributes.format); pixel_info = pixel_format_get_info(dmabuf->attributes.format);
fprintf(fp, "\t\tdmabuf buffer\n"); fprintf(fp, "\t\tdmabuf buffer\n");
fprintf(fp, "\t\t\tformat: 0x%lx %s\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 : fprintf(fp, "\t\t\tmodifier: %s\n", modifier_name ? modifier_name :
"Failed to convert to a modifier name"); "Failed to convert to a modifier name");
free(modifier_name); free(modifier_name);
return; break;
default:
fprintf(fp, "\t\tEGL buffer\n");
break;
} }
fprintf(fp, "\t\tEGL buffer\n");
} }
static void static void

@ -63,13 +63,12 @@ noop_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
if (!buffer) if (!buffer)
return; return;
shm_buffer = wl_shm_buffer_get(buffer->resource); if (buffer->type != WESTON_BUFFER_SHM) {
if (!shm_buffer) {
weston_log("No-op renderer supports only SHM buffers\n"); weston_log("No-op renderer supports only SHM buffers\n");
return; return;
} }
shm_buffer = buffer->shm_buffer;
data = wl_shm_buffer_get_data(shm_buffer); data = wl_shm_buffer_get_data(shm_buffer);
stride = wl_shm_buffer_get_stride(shm_buffer); stride = wl_shm_buffer_get_stride(shm_buffer);
width = wl_shm_buffer_get_width(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) if (!buffer)
return; return;
shm_buffer = wl_shm_buffer_get(buffer->resource); if (buffer->type != WESTON_BUFFER_SHM) {
if (! shm_buffer) {
weston_log("Pixman renderer supports only SHM buffers\n"); weston_log("Pixman renderer supports only SHM buffers\n");
weston_buffer_reference(&ps->buffer_ref, NULL); weston_buffer_reference(&ps->buffer_ref, NULL);
weston_buffer_release_reference(&ps->buffer_release_ref, NULL); weston_buffer_release_reference(&ps->buffer_release_ref, NULL);
return; return;
} }
shm_buffer = buffer->shm_buffer;
pixel_info = pixel_format_get_info_shm(wl_shm_buffer_get_format(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)) { if (!pixel_info || !pixman_format_supported_source(pixel_info->pixman_format)) {
weston_log("Unsupported SHM buffer format 0x%x\n", 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); assert(gr->has_native_fence_sync);
/* We should only get a fence for non-SHM buffers, since surface /* We should only get a fence for non-SHM buffers, since surface
* commit would have failed otherwise. */ * 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); attribs[1] = dup(surface->acquire_fence_fd);
if (attribs[1] == -1) { 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 weston_compositor *ec = es->compositor;
struct gl_renderer *gr = get_renderer(ec); struct gl_renderer *gr = get_renderer(ec);
struct gl_surface_state *gs = get_surface_state(es); struct gl_surface_state *gs = get_surface_state(es);
struct wl_shm_buffer *shm_buffer;
struct linux_dmabuf_buffer *dmabuf;
EGLint format; EGLint format;
int i; int i;
@ -2962,30 +2960,38 @@ gl_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
return; return;
} }
shm_buffer = wl_shm_buffer_get(buffer->resource); switch (buffer->type) {
case WESTON_BUFFER_SHM:
if (shm_buffer) gl_renderer_attach_shm(es, buffer, buffer->shm_buffer);
gl_renderer_attach_shm(es, buffer, shm_buffer); return;
else if (gr->has_bind_display && case WESTON_BUFFER_DMABUF:
gr->query_buffer(gr->egl_display, (void *)buffer->resource, gl_renderer_attach_dmabuf(es, buffer, buffer->dmabuf);
EGL_TEXTURE_FORMAT, &format)) return;
gl_renderer_attach_egl(es, buffer, format); case WESTON_BUFFER_RENDERER_OPAQUE:
else if ((dmabuf = linux_dmabuf_buffer_get(buffer->resource))) if (!gr->has_bind_display ||
gl_renderer_attach_dmabuf(es, buffer, dmabuf); !gr->query_buffer(gr->egl_display,
else { buffer->legacy_buffer,
weston_log("unhandled buffer type!\n"); EGL_TEXTURE_FORMAT, &format)) {
if (gr->has_bind_display) { break;
weston_log("eglQueryWaylandBufferWL failed\n");
gl_renderer_print_egl_error_state();
} }
weston_buffer_reference(&gs->buffer_ref, NULL); gl_renderer_attach_egl(es, buffer, format);
weston_buffer_release_reference(&gs->buffer_release_ref, NULL); return;
gs->buffer_type = BUFFER_TYPE_NULL; default:
gs->y_inverted = true; break;
es->is_opaque = false; }
weston_buffer_send_server_error(buffer,
"disconnecting due to unhandled buffer type"); 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 static void
@ -3232,8 +3238,7 @@ gl_renderer_create_surface(struct weston_surface *surface)
if (surface->buffer_ref.buffer) { if (surface->buffer_ref.buffer) {
gl_renderer_attach(surface, surface->buffer_ref.buffer); gl_renderer_attach(surface, surface->buffer_ref.buffer);
if (surface->buffer_ref.buffer->resource && if (surface->buffer_ref.buffer->type == WESTON_BUFFER_SHM) {
wl_shm_buffer_get(surface->buffer_ref.buffer->resource)) {
gl_renderer_flush_damage(surface, gl_renderer_flush_damage(surface,
surface->buffer_ref.buffer); surface->buffer_ref.buffer);
} }

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

Loading…
Cancel
Save