shm: replace 'locked' attribute with a ref-counter

The initial ref-count is either 1 or 0, depending on whether the
buffer is supposed to be released "immeidately" (meaning, as soon as
the compositor releases it).

Two new user facing functions have been added: shm_addref() and
shm_unref().

Our renderer now uses these two functions instead of manually setting
and clearing the 'locked' attribute.

shm_unref() will decrement the ref-counter, and destroy the buffer
when the counter reaches zero. Except if the buffer is currently
"busy" (compositor owned), in which case destruction is deferred to
the release event. The buffer is still removed from the list though.
This commit is contained in:
Daniel Eklöf 2021-07-16 16:47:57 +02:00
parent 69260dd960
commit 232fb20269
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 60 additions and 53 deletions

5
shm.h
View file

@ -10,8 +10,6 @@
struct damage;
struct buffer {
bool locked; /* Caller owned, shm wont destroy it */
int width;
int height;
int stride;
@ -23,6 +21,7 @@ struct buffer {
size_t pix_instances;
unsigned age;
struct damage *scroll_damage;
size_t scroll_damage_count;
pixman_region32_t dirty;
@ -74,6 +73,8 @@ bool shm_scroll(struct wl_shm *shm, struct buffer *buf, int rows,
int top_margin, int top_keep_rows,
int bottom_margin, int bottom_keep_rows);
void shm_addref(struct buffer *buf);
void shm_unref(struct buffer *buf);
void shm_purge(struct wl_shm *shm, unsigned long cookie);
struct terminal;