From fd6f47c93cab835e6301a61a3619e3a9dad9a4a4 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Thu, 29 Aug 2019 21:47:02 +0000 Subject: [PATCH] Clean some things up and add more interface functions --- bench/zrle-bench.c | 5 +++-- inc/neatvnc.h | 7 ++++++- inc/util.h | 6 ------ src/pngfb.c | 7 ++++++- src/server.c | 47 ++++++++++++++++++---------------------------- 5 files changed, 33 insertions(+), 39 deletions(-) diff --git a/bench/zrle-bench.c b/bench/zrle-bench.c index eead1f8..04d1f5c 100644 --- a/bench/zrle-bench.c +++ b/bench/zrle-bench.c @@ -2,18 +2,19 @@ #include "rfb-proto.h" #include "util.h" #include "vec.h" +#include "neatvnc.h" #include #include #include -int read_png_file(struct vnc_framebuffer* fb, const char *filename); +int read_png_file(struct nvnc_fb* fb, const char *filename); int run_benchmark(const char *image) { int rc = -1; - struct vnc_framebuffer fb; + struct nvnc_fb fb; rc = read_png_file(&fb, image); if (rc < 0) return -1; diff --git a/inc/neatvnc.h b/inc/neatvnc.h index 48d0f27..f970077 100644 --- a/inc/neatvnc.h +++ b/inc/neatvnc.h @@ -34,7 +34,12 @@ struct nvnc *nvnc_open(const char *addr, uint16_t port); void nvnc_close(struct nvnc *self); void nvnc_set_userdata(struct nvnc *self, void* userdata); -void* nvnc_get_userdata(struct nvnc *self); +void* nvnc_get_userdata(const struct nvnc *self); + +void nvnc_set_dimensions(struct nvnc *self, uint16_t width, uint16_t height, + uint32_t fourcc_format); + +void nvnc_set_name(struct nvnc *self, const char *name); void nvnc_set_key_fn(struct nvnc *self, nvnc_key_fn); void nvnc_set_pointer_fn(struct nvnc *self, nvnc_pointer_fn); diff --git a/inc/util.h b/inc/util.h index 2630c17..e845516 100644 --- a/inc/util.h +++ b/inc/util.h @@ -4,12 +4,6 @@ #include #include -struct vnc_framebuffer { - void *addr; - int width; - int height; -}; - struct vnc_write_request { uv_write_t request; uv_write_cb on_done; diff --git a/src/pngfb.c b/src/pngfb.c index 30ed359..b8aa591 100644 --- a/src/pngfb.c +++ b/src/pngfb.c @@ -1,12 +1,14 @@ #include "util.h" +#include "neatvnc.h" #include #include #include #include #include +#include -int read_png_file(struct vnc_framebuffer* fb, const char *filename) { +int read_png_file(struct nvnc_fb* fb, const char *filename) { int width, height; png_byte color_type; png_byte bit_depth; @@ -77,8 +79,11 @@ int read_png_file(struct vnc_framebuffer* fb, const char *filename) { png_destroy_read_struct(&png, &info, NULL); fb->addr = addr; + fb->size = sizeof(row_bytes * height); fb->width = width; fb->height = height; + fb->fourcc_format = DRM_FORMAT_ARGB8888; + fb->fourcc_modifier = DRM_FORMAT_MOD_LINEAR; return 0; } diff --git a/src/server.c b/src/server.c index 19f96f9..2a7c508 100644 --- a/src/server.c +++ b/src/server.c @@ -12,6 +12,7 @@ #include #include +#define DEFAULT_NAME "Neat VNC" #define READ_BUFFER_SIZE 4096 #define MSG_BUFFER_SIZE 4096 @@ -58,14 +59,13 @@ struct vnc_display { uint16_t width; uint16_t height; uint32_t pixfmt; /* fourcc pixel format */ - char *name; + char name[256]; }; struct nvnc { uv_tcp_t tcp_handle; struct vnc_client_list clients; struct vnc_display display; - struct vnc_framebuffer* fb; void *userdata; nvnc_key_fn key_fn; nvnc_pointer_fn pointer_fn; @@ -685,6 +685,8 @@ struct nvnc *nvnc_open(const char *address, uint16_t port) if (!self) return NULL; + strcpy(self->display.name, DEFAULT_NAME); + LIST_INIT(&self->clients); uv_tcp_init(uv_default_loop(), &self->tcp_handle); @@ -772,7 +774,7 @@ void nvnc_set_userdata(struct nvnc *self, void *userdata) } EXPORT -void* nvnc_get_userdata(struct nvnc *self) +void* nvnc_get_userdata(const struct nvnc *self) { return self->userdata; } @@ -795,31 +797,18 @@ void nvnc_set_fb_req_fn(struct nvnc *self, nvnc_fb_req_fn fn) self->fb_req_fn = fn; } -int read_png_file(struct vnc_framebuffer* fb, const char *filename); - -/* -int main(int argc, char *argv[]) +EXPORT +void nvnc_set_dimensions(struct nvnc *self, uint16_t width, uint16_t height, + uint32_t fourcc_format) { - if (!argv[1]) { - printf("Missing argument\n"); - return 1; - } - - struct vnc_framebuffer fb; - if (read_png_file(&fb, argv[1]) < 0) { - printf("Failed to read png file\n"); - return 1; - } - - struct vnc_server server = { 0 }; - server.fb = &fb; - server.display.pixfmt = DRM_FORMAT_XRGB8888; - server.display.width = fb.width; - server.display.height = fb.height; - server.display.name = argv[1]; - - vnc_server_init(&server, "127.0.0.1", 5900); - - uv_run(uv_default_loop(), UV_RUN_DEFAULT); + self->display.width = width; + self->display.height = height; + self->display.pixfmt = fourcc_format; +} + +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'; } -*/