From 031555c85d8513a293bf4f329f1a87b576024b1f Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 29 Aug 2021 14:26:12 +0000 Subject: [PATCH] fb: Add hold/release logic --- include/fb.h | 6 ++++++ include/neatvnc.h | 3 +++ src/fb.c | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/include/fb.h b/include/fb.h index 4c56886..ddde05f 100644 --- a/include/fb.h +++ b/include/fb.h @@ -24,6 +24,9 @@ struct nvnc_fb { int ref; + int hold_count; + nvnc_fb_release_fn on_release; + void* userdata; void* addr; enum nvnc_fb_flags flags; size_t size; @@ -32,3 +35,6 @@ struct nvnc_fb { uint32_t fourcc_format; uint64_t fourcc_modifier; }; + +void nvnc_fb_hold(struct nvnc_fb* fb); +void nvnc_fb_release(struct nvnc_fb* fb); diff --git a/include/neatvnc.h b/include/neatvnc.h index 7a15233..92e2d79 100644 --- a/include/neatvnc.h +++ b/include/neatvnc.h @@ -50,6 +50,7 @@ typedef bool (*nvnc_auth_fn)(const char* username, const char* password, void* userdata); typedef void (*nvnc_render_fn)(struct nvnc_display*, struct nvnc_fb*); typedef void (*nvnc_cut_text_fn)(struct nvnc*, const char* text, uint32_t len); +typedef void (*nvnc_fb_release_fn)(struct nvnc_fb*, void* userdata); extern const char nvnc_version[]; @@ -87,6 +88,8 @@ void nvnc_fb_unref(struct nvnc_fb* fb); enum nvnc_fb_flags nvnc_fb_get_flags(const struct nvnc_fb*); void nvnc_fb_set_flags(struct nvnc_fb*, enum nvnc_fb_flags); +void nvnc_fb_set_release_fn(struct nvnc_fb* fb, nvnc_fb_release_fn fn, + void* userdata); void* nvnc_fb_get_addr(const struct nvnc_fb* fb); uint16_t nvnc_fb_get_width(const struct nvnc_fb* fb); diff --git a/src/fb.c b/src/fb.c index 9685ba0..c935a59 100644 --- a/src/fb.c +++ b/src/fb.c @@ -110,3 +110,21 @@ void nvnc_fb_unref(struct nvnc_fb* fb) if (--fb->ref == 0) nvnc__fb_free(fb); } + +EXPORT +void nvnc_fb_set_release_fn(struct nvnc_fb* fb, nvnc_fb_release_fn fn, void* userdata) +{ + fb->on_release = fn; + fb->userdata = userdata; +} + +void nvnc_fb_hold(struct nvnc_fb* fb) +{ + fb->hold_count++; +} + +void nvnc_fb_release(struct nvnc_fb* fb) +{ + if (--fb->hold_count == 0 && fb->on_release) + fb->on_release(fb, fb->userdata); +}