fb: Add hold/release logic

fb-api-v3
Andri Yngvason 2021-08-29 14:26:12 +00:00
parent d0cf1595af
commit 031555c85d
3 changed files with 27 additions and 0 deletions

View File

@ -24,6 +24,9 @@
struct nvnc_fb { struct nvnc_fb {
int ref; int ref;
int hold_count;
nvnc_fb_release_fn on_release;
void* userdata;
void* addr; void* addr;
enum nvnc_fb_flags flags; enum nvnc_fb_flags flags;
size_t size; size_t size;
@ -32,3 +35,6 @@ struct nvnc_fb {
uint32_t fourcc_format; uint32_t fourcc_format;
uint64_t fourcc_modifier; uint64_t fourcc_modifier;
}; };
void nvnc_fb_hold(struct nvnc_fb* fb);
void nvnc_fb_release(struct nvnc_fb* fb);

View File

@ -50,6 +50,7 @@ typedef bool (*nvnc_auth_fn)(const char* username, const char* password,
void* userdata); void* userdata);
typedef void (*nvnc_render_fn)(struct nvnc_display*, struct nvnc_fb*); 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_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[]; 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*); 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_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); void* nvnc_fb_get_addr(const struct nvnc_fb* fb);
uint16_t nvnc_fb_get_width(const struct nvnc_fb* fb); uint16_t nvnc_fb_get_width(const struct nvnc_fb* fb);

View File

@ -110,3 +110,21 @@ void nvnc_fb_unref(struct nvnc_fb* fb)
if (--fb->ref == 0) if (--fb->ref == 0)
nvnc__fb_free(fb); 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);
}