compositor: add early wl_buffer.release
A client can reliably avoid allocating a second buffer per surface, if
the compositor sends the wl_buffer.release event before the frame
callback. To enable clients' single-buffering, release the wl_buffer
early if possible. Otherwise clients will double-buffer.
Releasing early is not possible, if the backend needs the buffer for
migrating a surface to or from a non-primary weston_plane. In that case,
a new buffer must arrive, before the old can be released. Backends will
indicate this by setting weston_surface:keep_buffer to 1 in
assign_planes().
A proper buffer reference in the backends would be better than the
keep_buffer flag, but that would require a per-surface backend private.
The rpi and DRM backends are updated to set keep_buffer, other backends
do not support planes, so do not have to set it.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index da36cd3..11d9981 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -805,6 +805,16 @@
pixman_region32_init(&overlap);
primary = &c->base.primary_plane;
wl_list_for_each_safe(es, next, &c->base.surface_list, link) {
+ /* test whether this buffer can ever go into a plane:
+ * non-shm, or small enough to be a cursor
+ */
+ if ((es->buffer_ref.buffer &&
+ !wl_buffer_is_shm(es->buffer_ref.buffer)) ||
+ (es->geometry.width <= 64 && es->geometry.height <= 64))
+ es->keep_buffer = 1;
+ else
+ es->keep_buffer = 0;
+
pixman_region32_init(&surface_overlap);
pixman_region32_intersect(&surface_overlap, &overlap,
&es->transform.boundingbox);