buffer: add a release event

Consumers call wlr_buffer_lock. Once all consumers are done with the
buffer, only the producer should have a reference to the buffer. In this
case, we can release the buffer (and let the producer re-use it).
This commit is contained in:
Simon Ser 2020-02-28 13:25:05 +01:00
parent 1674ca725c
commit 6595db6409
6 changed files with 98 additions and 37 deletions

View file

@ -404,8 +404,8 @@ static bool drm_connector_commit_buffer(struct wlr_output *output) {
conn->pageflip_pending = true;
if (output->pending.buffer_type == WLR_OUTPUT_STATE_BUFFER_SCANOUT) {
wlr_buffer_unref(conn->pending_buffer);
conn->pending_buffer = wlr_buffer_ref(output->pending.buffer);
wlr_buffer_unlock(conn->pending_buffer);
conn->pending_buffer = wlr_buffer_lock(output->pending.buffer);
}
wlr_output_update_enabled(output, true);
@ -1539,7 +1539,7 @@ static void page_flip_handler(int fd, unsigned seq,
// Release the old buffer as it's not displayed anymore. The pending
// buffer becomes the current buffer.
wlr_buffer_unref(conn->current_buffer);
wlr_buffer_unlock(conn->current_buffer);
conn->current_buffer = conn->pending_buffer;
conn->pending_buffer = NULL;
@ -1660,8 +1660,8 @@ static void drm_connector_cleanup(struct wlr_drm_connector *conn) {
conn->output.needs_frame = false;
conn->output.frame_pending = false;
wlr_buffer_unref(conn->pending_buffer);
wlr_buffer_unref(conn->current_buffer);
wlr_buffer_unlock(conn->pending_buffer);
wlr_buffer_unlock(conn->current_buffer);
conn->pending_buffer = conn->current_buffer = NULL;
/* Fallthrough */

View file

@ -114,7 +114,7 @@ static void destroy_wl_buffer(struct wlr_wl_buffer *buffer) {
return;
}
wl_buffer_destroy(buffer->wl_buffer);
wlr_buffer_unref(buffer->buffer);
wlr_buffer_unlock(buffer->buffer);
free(buffer);
}
@ -173,7 +173,7 @@ static struct wlr_wl_buffer *create_wl_buffer(struct wlr_wl_backend *wl,
return NULL;
}
buffer->wl_buffer = wl_buffer;
buffer->buffer = wlr_buffer_ref(wlr_buffer);
buffer->buffer = wlr_buffer_lock(wlr_buffer);
wl_buffer_add_listener(wl_buffer, &buffer_listener, buffer);