mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-13 08:22:16 -04:00
Merge branch 'acquire-buffer' into 'master'
buffer: introduce wlr_buffer_acquire() See merge request wlroots/wlroots!4916
This commit is contained in:
commit
4713b40279
5 changed files with 32 additions and 6 deletions
|
|
@ -44,9 +44,11 @@ enum wlr_buffer_cap {
|
||||||
* A buffer containing pixel data.
|
* A buffer containing pixel data.
|
||||||
*
|
*
|
||||||
* A buffer has a single producer (the party who created the buffer) and
|
* A buffer has a single producer (the party who created the buffer) and
|
||||||
* multiple consumers (parties reading the buffer). When all consumers are done
|
* multiple consumers (parties reading the buffer). Initially, a buffer is
|
||||||
* with the buffer, it gets released and can be re-used by the producer. When
|
* released. When the consumer passes the buffer to a consumer, the buffer is
|
||||||
* the producer and all consumers are done with the buffer, it gets destroyed.
|
* acquired. When all consumers are done with the buffer, it gets released and
|
||||||
|
* can be re-used by the producer. When the producer and all consumers are done
|
||||||
|
* with the buffer, it gets destroyed.
|
||||||
*/
|
*/
|
||||||
struct wlr_buffer {
|
struct wlr_buffer {
|
||||||
const struct wlr_buffer_impl *impl;
|
const struct wlr_buffer_impl *impl;
|
||||||
|
|
@ -70,10 +72,20 @@ struct wlr_buffer {
|
||||||
* they are done with the buffer.
|
* they are done with the buffer.
|
||||||
*/
|
*/
|
||||||
void wlr_buffer_drop(struct wlr_buffer *buffer);
|
void wlr_buffer_drop(struct wlr_buffer *buffer);
|
||||||
|
/**
|
||||||
|
* Acquire the buffer. This function should be called by producers when they
|
||||||
|
* pass a released buffer to a consumer. The consumer is responsible for
|
||||||
|
* calling wlr_buffer_unlock() once they are done with the buffer.
|
||||||
|
*
|
||||||
|
* This function aborts if the buffer has already been acquired.
|
||||||
|
*/
|
||||||
|
struct wlr_buffer *wlr_buffer_acquire(struct wlr_buffer *buffer);
|
||||||
/**
|
/**
|
||||||
* Lock the buffer. This function should be called by consumers to make
|
* Lock the buffer. This function should be called by consumers to make
|
||||||
* sure the buffer can be safely read from. Once the consumer is done with the
|
* sure the buffer can be safely read from. Once the consumer is done with the
|
||||||
* buffer, they should call wlr_buffer_unlock().
|
* buffer, they should call wlr_buffer_unlock().
|
||||||
|
*
|
||||||
|
* This function aborts if the buffer hasn't been acquired.
|
||||||
*/
|
*/
|
||||||
struct wlr_buffer *wlr_buffer_lock(struct wlr_buffer *buffer);
|
struct wlr_buffer *wlr_buffer_lock(struct wlr_buffer *buffer);
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ static struct wlr_buffer *slot_acquire(struct wlr_swapchain *swapchain,
|
||||||
slot->release.notify = slot_handle_release;
|
slot->release.notify = slot_handle_release;
|
||||||
wl_signal_add(&slot->buffer->events.release, &slot->release);
|
wl_signal_add(&slot->buffer->events.release, &slot->release);
|
||||||
|
|
||||||
return wlr_buffer_lock(slot->buffer);
|
return wlr_buffer_acquire(slot->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_buffer *wlr_swapchain_acquire(struct wlr_swapchain *swapchain) {
|
struct wlr_buffer *wlr_swapchain_acquire(struct wlr_swapchain *swapchain) {
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,14 @@ void wlr_buffer_drop(struct wlr_buffer *buffer) {
|
||||||
buffer_consider_destroy(buffer);
|
buffer_consider_destroy(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct wlr_buffer *wlr_buffer_acquire(struct wlr_buffer *buffer) {
|
||||||
|
assert(buffer->n_locks == 0);
|
||||||
|
buffer->n_locks++;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
struct wlr_buffer *wlr_buffer_lock(struct wlr_buffer *buffer) {
|
struct wlr_buffer *wlr_buffer_lock(struct wlr_buffer *buffer) {
|
||||||
|
assert(buffer->n_locks > 0);
|
||||||
buffer->n_locks++;
|
buffer->n_locks++;
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ struct wlr_client_buffer *wlr_client_buffer_create(struct wlr_buffer *buffer,
|
||||||
client_buffer->renderer_destroy.notify = client_buffer_handle_renderer_destroy;
|
client_buffer->renderer_destroy.notify = client_buffer_handle_renderer_destroy;
|
||||||
|
|
||||||
// Ensure the buffer will be released before being destroyed
|
// Ensure the buffer will be released before being destroyed
|
||||||
wlr_buffer_lock(&client_buffer->base);
|
wlr_buffer_acquire(&client_buffer->base);
|
||||||
wlr_buffer_drop(&client_buffer->base);
|
wlr_buffer_drop(&client_buffer->base);
|
||||||
|
|
||||||
return client_buffer;
|
return client_buffer;
|
||||||
|
|
|
||||||
|
|
@ -57,5 +57,12 @@ struct wlr_buffer *wlr_buffer_try_from_resource(struct wl_resource *resource) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return wlr_buffer_lock(buffer);
|
// If the buffer is released, we want to acquire it. If the buffer is
|
||||||
|
// already acquired (e.g. because it has been attached to another surface),
|
||||||
|
// we want to lock it.
|
||||||
|
if (buffer->n_locks > 0) {
|
||||||
|
return wlr_buffer_lock(buffer);
|
||||||
|
} else {
|
||||||
|
return wlr_buffer_acquire(buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue