Notify the user when an fb is released

fb-api-v3
Andri Yngvason 2021-08-29 14:41:57 +00:00
parent 031555c85d
commit d63feadeab
3 changed files with 28 additions and 2 deletions

View File

@ -79,6 +79,7 @@ struct nvnc_client {
struct pixman_region16 damage; struct pixman_region16 damage;
int n_pending_requests; int n_pending_requests;
bool is_updating; bool is_updating;
struct nvnc_fb* current_fb;
nvnc_client_fn cleanup_fn; nvnc_client_fn cleanup_fn;
z_stream z_stream; z_stream z_stream;
struct tight_encoder tight_encoder; struct tight_encoder tight_encoder;

View File

@ -17,6 +17,7 @@
#include "display.h" #include "display.h"
#include "neatvnc.h" #include "neatvnc.h"
#include "common.h" #include "common.h"
#include "fb.h"
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
@ -66,11 +67,14 @@ struct nvnc* nvnc_display_get_server(const struct nvnc_display* self)
EXPORT EXPORT
void nvnc_display_set_buffer(struct nvnc_display* self, struct nvnc_fb* fb) void nvnc_display_set_buffer(struct nvnc_display* self, struct nvnc_fb* fb)
{ {
if (self->buffer) if (self->buffer) {
nvnc_fb_release(self->buffer);
nvnc_fb_unref(self->buffer); nvnc_fb_unref(self->buffer);
}
self->buffer = fb; self->buffer = fb;
nvnc_fb_ref(fb); nvnc_fb_ref(fb);
nvnc_fb_hold(fb);
} }
EXPORT EXPORT

View File

@ -103,6 +103,11 @@ static void client_close(struct nvnc_client* client)
if (fn) if (fn)
fn(client); fn(client);
if (client->current_fb) {
nvnc_fb_release(client->current_fb);
nvnc_fb_unref(client->current_fb);
}
LIST_REMOVE(client, link); LIST_REMOVE(client, link);
stream_destroy(client->net_stream); stream_destroy(client->net_stream);
tight_encoder_destroy(&client->tight_encoder); tight_encoder_destroy(&client->tight_encoder);
@ -553,6 +558,9 @@ static void process_fb_update_requests(struct nvnc_client* client)
pixman_region_init(&client->damage); pixman_region_init(&client->damage);
client->is_updating = true; client->is_updating = true;
client->current_fb = fb;
nvnc_fb_hold(fb);
nvnc_fb_ref(fb);
int rc; int rc;
enum rfb_encodings encoding = choose_frame_encoding(client); enum rfb_encodings encoding = choose_frame_encoding(client);
@ -584,8 +592,13 @@ static void process_fb_update_requests(struct nvnc_client* client)
break; break;
} }
if (rc < 0) if (rc < 0) {
client->is_updating = false; client->is_updating = false;
assert(client->current_fb);
nvnc_fb_release(client->current_fb);
nvnc_fb_unref(client->current_fb);
client->current_fb = NULL;
}
} }
static int on_client_fb_update_request(struct nvnc_client* client) static int on_client_fb_update_request(struct nvnc_client* client)
@ -1234,6 +1247,10 @@ static void on_write_frame_done(void* userdata, enum stream_req_status status)
{ {
struct nvnc_client* client = userdata; struct nvnc_client* client = userdata;
client->is_updating = false; client->is_updating = false;
assert(client->current_fb);
nvnc_fb_release(client->current_fb);
nvnc_fb_unref(client->current_fb);
client->current_fb = NULL;
client_unref(client); client_unref(client);
} }
@ -1316,6 +1333,10 @@ static void finish_fb_update(struct nvnc_client* client, struct vec* frame)
DTRACE_PROBE1(neatvnc, send_fb_done, client); DTRACE_PROBE1(neatvnc, send_fb_done, client);
} else { } else {
client->is_updating = false; client->is_updating = false;
assert(client->current_fb);
nvnc_fb_release(client->current_fb);
nvnc_fb_unref(client->current_fb);
client->current_fb = NULL;
vec_destroy(frame); vec_destroy(frame);
client_unref(client); client_unref(client);
} }