compositor: introduce weston_buffer_reference
authorPekka Paalanen <ppaalanen@gmail.com>
Tue, 4 Dec 2012 13:58:12 +0000 (15:58 +0200)
committerKristian Høgsberg <krh@bitplanet.net>
Thu, 6 Dec 2012 21:07:43 +0000 (16:07 -0500)
commitde685b8843f9070507ccca631d08cb5fff93e622
tree503e012ccf56a0812f2032b856f539abc2dff03b
parentaecd3ec54ffacb766632fe53774a32d242b84aec
compositor: introduce weston_buffer_reference

The wl_buffer reference counting API has been inconsistent. You would
manually increment the refcount and register a destroy listener, as
opposed to calling weston_buffer_post_release(), which internally
decremented the refcount, and then removing a list item.

Replace both cases with a single function:
weston_buffer_reference(weston_buffer_reference *ref, wl_buffer *buffer)

Buffer is assigned to ref->buffer, while taking care of all the refcounting
and release posting. You take a reference by passing a non-NULL buffer, and
release a reference by passing NULL as buffer. The function uses an
internal wl_buffer destroy listener, so the pointer gets reset on
destruction automatically.

This is inspired by the pipe_resource_reference() of Mesa, and modified
by krh's suggestion to add struct weston_buffer_reference.

Additionally, when a surface gets destroyed, the associated wl_buffer
will send a release event. Often the buffer is already destroyed on
client side, so the event will be discarded by libwayland-client.

Compositor-drm.c is converted to use weston_buffer_reference.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
src/compositor-drm.c
src/compositor-rpi.c
src/compositor.c
src/compositor.h
src/gl-renderer.c
src/shell.c
src/tablet-shell.c