diff --git a/src/protocols/vnc/client.c b/src/protocols/vnc/client.c index c13a50e3..090fcc84 100644 --- a/src/protocols/vnc/client.c +++ b/src/protocols/vnc/client.c @@ -218,18 +218,13 @@ int guac_client_init(guac_client* client, int argc, char** argv) { guac_client_data->hostname = strdup(argv[IDX_HOSTNAME]); guac_client_data->port = atoi(argv[IDX_PORT]); + guac_client_data->password = strdup(argv[IDX_PASSWORD]); /* NOTE: freed by libvncclient */ + guac_client_data->default_surface = NULL; - /* Set remote cursor flag */ + /* Set flags */ guac_client_data->remote_cursor = (strcmp(argv[IDX_CURSOR], "remote") == 0); - - /* Set red/blue swap flag */ guac_client_data->swap_red_blue = (strcmp(argv[IDX_SWAP_RED_BLUE], "true") == 0); - - /* Set read-only flag */ - guac_client_data->read_only = (strcmp(argv[IDX_READ_ONLY], "true") == 0); - - /* Freed after use by libvncclient */ - guac_client_data->password = strdup(argv[IDX_PASSWORD]); + guac_client_data->read_only = (strcmp(argv[IDX_READ_ONLY], "true") == 0); /* Parse color depth */ guac_client_data->color_depth = atoi(argv[IDX_COLOR_DEPTH]); @@ -372,10 +367,9 @@ int guac_client_init(guac_client* client, int argc, char** argv) { /* Send name */ guac_protocol_send_name(client->socket, rfb_client->desktopName); - /* Send size */ - guac_protocol_send_size(client->socket, - GUAC_DEFAULT_LAYER, rfb_client->width, rfb_client->height); - + /* Create default surface */ + guac_client_data->default_surface = guac_common_surface_alloc(client->socket, GUAC_DEFAULT_LAYER, + rfb_client->width, rfb_client->height); return 0; } diff --git a/src/protocols/vnc/client.h b/src/protocols/vnc/client.h index e6c4b231..d9971e7f 100644 --- a/src/protocols/vnc/client.h +++ b/src/protocols/vnc/client.h @@ -26,6 +26,7 @@ #include "config.h" #include "guac_clipboard.h" +#include "guac_surface.h" #include #include @@ -180,6 +181,11 @@ typedef struct vnc_guac_client_data { */ guac_common_clipboard* clipboard; + /** + * Default surface. + */ + guac_common_surface* default_surface; + } vnc_guac_client_data; #endif diff --git a/src/protocols/vnc/guac_handlers.c b/src/protocols/vnc/guac_handlers.c index f1bdd115..dfe921ee 100644 --- a/src/protocols/vnc/guac_handlers.c +++ b/src/protocols/vnc/guac_handlers.c @@ -25,6 +25,7 @@ #include "client.h" #include "clipboard.h" #include "guac_clipboard.h" +#include "guac_surface.h" #include #include @@ -41,7 +42,8 @@ int vnc_guac_client_handle_messages(guac_client* client) { - rfbClient* rfb_client = ((vnc_guac_client_data*) client->data)->rfb_client; + vnc_guac_client_data* guac_client_data = (vnc_guac_client_data*) client->data; + rfbClient* rfb_client = guac_client_data->rfb_client; /* Initially wait for messages */ int wait_result = WaitForMessage(rfb_client, 1000000); @@ -76,6 +78,7 @@ int vnc_guac_client_handle_messages(guac_client* client) { return 1; } + guac_common_surface_flush(guac_client_data->default_surface); return 0; } @@ -116,6 +119,9 @@ int vnc_guac_client_free_handler(guac_client* client) { /* Free clipboard */ guac_common_clipboard_free(guac_client_data->clipboard); + /* Free surface */ + guac_common_surface_free(guac_client_data->default_surface); + /* Free generic data struct */ free(client->data); diff --git a/src/protocols/vnc/vnc_handlers.c b/src/protocols/vnc/vnc_handlers.c index 368ab0bb..77c6ef50 100644 --- a/src/protocols/vnc/vnc_handlers.c +++ b/src/protocols/vnc/vnc_handlers.c @@ -24,6 +24,7 @@ #include "client.h" #include "guac_iconv.h" +#include "guac_surface.h" #include #include @@ -135,7 +136,6 @@ void guac_vnc_update(rfbClient* client, int x, int y, int w, int h) { guac_client* gc = rfbClientGetClientData(client, __GUAC_CLIENT); vnc_guac_client_data* guac_client_data = (vnc_guac_client_data*) gc->data; - guac_socket* socket = gc->socket; int dx, dy; @@ -216,7 +216,7 @@ void guac_vnc_update(rfbClient* client, int x, int y, int w, int h) { /* For now, only use default layer */ surface = cairo_image_surface_create_for_data(buffer, CAIRO_FORMAT_RGB24, w, h, stride); - guac_protocol_send_png(socket, GUAC_COMP_OVER, GUAC_DEFAULT_LAYER, x, y, surface); + guac_common_surface_draw(guac_client_data->default_surface, x, y, surface); /* Free surface */ cairo_surface_destroy(surface); @@ -227,12 +227,11 @@ void guac_vnc_update(rfbClient* client, int x, int y, int w, int h) { void guac_vnc_copyrect(rfbClient* client, int src_x, int src_y, int w, int h, int dest_x, int dest_y) { guac_client* gc = rfbClientGetClientData(client, __GUAC_CLIENT); - guac_socket* socket = gc->socket; + vnc_guac_client_data* guac_client_data = (vnc_guac_client_data*) gc->data; /* For now, only use default layer */ - guac_protocol_send_copy(socket, - GUAC_DEFAULT_LAYER, src_x, src_y, w, h, - GUAC_COMP_OVER, GUAC_DEFAULT_LAYER, dest_x, dest_y); + guac_common_surface_copy(guac_client_data->default_surface, src_x, src_y, w, h, + guac_client_data->default_surface, dest_x, dest_y); ((vnc_guac_client_data*) gc->data)->copy_rect_used = 1; @@ -286,9 +285,9 @@ rfbBool guac_vnc_malloc_framebuffer(rfbClient* rfb_client) { guac_client* gc = rfbClientGetClientData(rfb_client, __GUAC_CLIENT); vnc_guac_client_data* guac_client_data = (vnc_guac_client_data*) gc->data; - /* Send new size */ - guac_protocol_send_size(gc->socket, - GUAC_DEFAULT_LAYER, rfb_client->width, rfb_client->height); + /* Resize surface */ + if (guac_client_data->default_surface != NULL) + guac_common_surface_resize(guac_client_data->default_surface, rfb_client->width, rfb_client->height); /* Use original, wrapped proc */ return guac_client_data->rfb_MallocFrameBuffer(rfb_client);