• Pekka Paalanen's avatar
    compositor: introduce weston_buffer_reference · de685b88
    Pekka Paalanen authored
    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's avatarPekka Paalanen <ppaalanen@gmail.com>
    de685b88
compositor-drm.c 61.9 KB