diff --git a/include/neatvnc.h b/include/neatvnc.h index 30b8cd8..7e24399 100644 --- a/include/neatvnc.h +++ b/include/neatvnc.h @@ -112,6 +112,8 @@ typedef bool (*nvnc_auth_fn)(const char* username, const char* password, void* userdata); typedef void (*nvnc_cut_text_fn)(struct nvnc*, const char* text, uint32_t len); typedef void (*nvnc_fb_release_fn)(struct nvnc_fb*, void* context); +typedef struct nvnc_fb* (*nvnc_fb_alloc_fn)(uint16_t width, uint16_t height, + uint32_t format, uint16_t stride); typedef void (*nvnc_cleanup_fn)(void* userdata); typedef void (*nvnc_log_fn)(const struct nvnc_log_data*, const char* message); @@ -176,6 +178,8 @@ struct nvnc_fb_pool* nvnc_fb_pool_new(uint16_t width, uint16_t height, bool nvnc_fb_pool_resize(struct nvnc_fb_pool*, uint16_t width, uint16_t height, uint32_t fourcc_format, uint16_t stride); +void nvnc_fb_pool_set_alloc_fn(struct nvnc_fb_pool*, nvnc_fb_alloc_fn); + void nvnc_fb_pool_ref(struct nvnc_fb_pool*); void nvnc_fb_pool_unref(struct nvnc_fb_pool*); diff --git a/src/fb_pool.c b/src/fb_pool.c index fdfe704..c6da056 100644 --- a/src/fb_pool.c +++ b/src/fb_pool.c @@ -40,6 +40,8 @@ struct nvnc_fb_pool { uint16_t height; int32_t stride; uint32_t fourcc_format; + + nvnc_fb_alloc_fn alloc_fn; }; EXPORT @@ -57,6 +59,7 @@ struct nvnc_fb_pool* nvnc_fb_pool_new(uint16_t width, uint16_t height, self->height = height; self->stride = stride; self->fourcc_format = fourcc_format; + self->alloc_fn = nvnc_fb_new; return self; } @@ -119,7 +122,7 @@ static void nvnc_fb_pool__on_fb_release(struct nvnc_fb* fb, void* userdata) static struct nvnc_fb* nvnc_fb_pool__acquire_new(struct nvnc_fb_pool* self) { - struct nvnc_fb* fb = nvnc_fb_new(self->width, self->height, + struct nvnc_fb* fb = self->alloc_fn(self->width, self->height, self->fourcc_format, self->stride); if (!fb) return NULL; @@ -168,3 +171,9 @@ void nvnc_fb_pool_release(struct nvnc_fb_pool* self, struct nvnc_fb* fb) item->fb = fb; TAILQ_INSERT_TAIL(&self->fbs, item, link); } + +EXPORT +void nvnc_fb_pool_set_alloc_fn(struct nvnc_fb_pool* self, nvnc_fb_alloc_fn fn) +{ + self->alloc_fn = fn; +}