From 737dd311a04e0fc30bd7072dce045c3fa3dc895b Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 12 Apr 2020 16:08:33 +0000 Subject: [PATCH] Remove nvnc_set_dimensions() This information is now figured out based on the nvnc_fb passed into nvnc_set_buffer() --- examples/draw.c | 1 - examples/png-server.c | 5 ---- include/common.h | 9 +----- include/neatvnc.h | 3 -- src/server.c | 66 +++++++++++++++++++++++-------------------- 5 files changed, 37 insertions(+), 47 deletions(-) diff --git a/examples/draw.c b/examples/draw.c index 19e2817..591d952 100644 --- a/examples/draw.c +++ b/examples/draw.c @@ -139,7 +139,6 @@ int main(int argc, char* argv[]) struct nvnc* server = nvnc_open("127.0.0.1", 5900); - nvnc_set_dimensions(server, width, height, format); nvnc_set_name(server, "Draw"); nvnc_set_pointer_fn(server, on_pointer_event); nvnc_set_userdata(server, &draw); diff --git a/examples/png-server.c b/examples/png-server.c index 02d1242..d7357ed 100644 --- a/examples/png-server.c +++ b/examples/png-server.c @@ -49,11 +49,6 @@ int main(int argc, char* argv[]) struct nvnc* server = nvnc_open("127.0.0.1", 5900); - int width = nvnc_fb_get_width(fb); - int height = nvnc_fb_get_height(fb); - uint32_t fourcc_format = nvnc_fb_get_fourcc_format(fb); - - nvnc_set_dimensions(server, width, height, fourcc_format); nvnc_set_buffer(server, fb); nvnc_set_name(server, file); diff --git a/include/common.h b/include/common.h index cc2c23d..207f2e7 100644 --- a/include/common.h +++ b/include/common.h @@ -81,20 +81,13 @@ struct nvnc_client { LIST_HEAD(nvnc_client_list, nvnc_client); -struct vnc_display { - uint16_t width; - uint16_t height; - uint32_t pixfmt; /* fourcc pixel format */ - char name[256]; -}; - struct nvnc { struct nvnc_common common; int fd; struct aml_handler* poll_handle; struct aml_idle* dispatch_handler; struct nvnc_client_list clients; - struct vnc_display display; + char name[256]; void* userdata; nvnc_key_fn key_fn; nvnc_pointer_fn pointer_fn; diff --git a/include/neatvnc.h b/include/neatvnc.h index ffd3b72..389ebf3 100644 --- a/include/neatvnc.h +++ b/include/neatvnc.h @@ -57,9 +57,6 @@ void* nvnc_get_userdata(const void* self); struct nvnc* nvnc_get_server(const struct nvnc_client* client); -void nvnc_set_dimensions(struct nvnc* self, uint16_t width, uint16_t height, - uint32_t fourcc_format); - void nvnc_set_buffer(struct nvnc*, struct nvnc_fb*); void nvnc_set_name(struct nvnc* self, const char* name); diff --git a/src/server.c b/src/server.c index f73a779..368569e 100644 --- a/src/server.c +++ b/src/server.c @@ -348,28 +348,31 @@ static void disconnect_all_other_clients(struct nvnc_client* client) static void send_server_init_message(struct nvnc_client* client) { struct nvnc* server = client->server; - struct vnc_display* display = &server->display; - size_t name_len = strlen(display->name); + size_t name_len = strlen(server->name); size_t size = sizeof(struct rfb_server_init_msg) + name_len; + if (!server->buffer) { + log_debug("Tried to send init message, but not buffer has been set\n"); + goto close; + } + + uint16_t width = nvnc_fb_get_width(server->buffer); + uint16_t height = nvnc_fb_get_height(server->buffer); + uint32_t fourcc = nvnc_fb_get_fourcc_format(server->buffer); + struct rfb_server_init_msg* msg = calloc(1, size); - if (!msg) { - stream_close(client->net_stream); - client_unref(client); - return; - } + if (!msg) + goto close; - msg->width = htons(display->width), - msg->height = htons(display->height), msg->name_length = htonl(name_len), - memcpy(msg->name_string, display->name, name_len); + msg->width = htons(width); + msg->height = htons(height); + msg->name_length = htonl(name_len); + memcpy(msg->name_string, server->name, name_len); - int rc = rfb_pixfmt_from_fourcc(&msg->pixel_format, display->pixfmt); - if (rc < 0) { - stream_close(client->net_stream); - client_unref(client); - return; - } + int rc = rfb_pixfmt_from_fourcc(&msg->pixel_format, fourcc); + if (rc < 0) + goto pixfmt_failure; msg->pixel_format.red_max = htons(msg->pixel_format.red_max); msg->pixel_format.green_max = htons(msg->pixel_format.green_max); @@ -377,6 +380,14 @@ static void send_server_init_message(struct nvnc_client* client) struct rcbuf* payload = rcbuf_new(msg, size); stream_send(client->net_stream, payload, NULL, NULL); + + return; + +pixfmt_failure: + free(msg); +close: + stream_close(client->net_stream); + client_unref(client); } static int on_init_message(struct nvnc_client* client) @@ -834,7 +845,7 @@ struct nvnc* nvnc_open(const char* address, uint16_t port) if (!self) return NULL; - strcpy(self->display.name, DEFAULT_NAME); + strcpy(self->name, DEFAULT_NAME); LIST_INIT(&self->clients); @@ -1063,9 +1074,13 @@ void nvnc_damage_region(struct nvnc* self, const struct pixman_region16* damage) EXPORT void nvnc_damage_whole(struct nvnc* self) { + assert(self->buffer); + + uint16_t width = nvnc_fb_get_width(self->buffer); + uint16_t height = nvnc_fb_get_height(self->buffer); + struct pixman_region16 damage; - pixman_region_init_rect(&damage, 0, 0, self->display.width, - self->display.height); + pixman_region_init_rect(&damage, 0, 0, width, height); nvnc_damage_region(self, &damage); pixman_region_fini(&damage); } @@ -1120,15 +1135,6 @@ void nvnc_set_client_cleanup_fn(struct nvnc_client* self, nvnc_client_fn fn) self->cleanup_fn = fn; } -EXPORT -void nvnc_set_dimensions(struct nvnc* self, uint16_t width, uint16_t height, - uint32_t fourcc_format) -{ - self->display.width = width; - self->display.height = height; - self->display.pixfmt = fourcc_format; -} - EXPORT void nvnc_set_buffer(struct nvnc* self, struct nvnc_fb* fb) { @@ -1148,8 +1154,8 @@ struct nvnc* nvnc_get_server(const struct nvnc_client* client) EXPORT void nvnc_set_name(struct nvnc* self, const char* name) { - strncpy(self->display.name, name, sizeof(self->display.name)); - self->display.name[sizeof(self->display.name) - 1] = '\0'; + strncpy(self->name, name, sizeof(self->name)); + self->name[sizeof(self->name) - 1] = '\0'; } EXPORT