Skip to content

Commit

Permalink
GUACAMOLE-377: Migrate VNC to default render loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-jumper committed Sep 28, 2024
1 parent baf98b8 commit 16d4547
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 31 deletions.
1 change: 1 addition & 0 deletions src/protocols/vnc/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ void guac_vnc_cursor(rfbClient* client, int x, int y, int w, int h, int vnc_bpp)

/* Draw operation is now complete */
guac_display_layer_close_raw(cursor_layer, context);
guac_display_render_thread_notify_modified(vnc_client->render_thread);

/* libvncclient does not free rcMask as it does rcSource */
if (client->rcMask != NULL) {
Expand Down
2 changes: 2 additions & 0 deletions src/protocols/vnc/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ void guac_vnc_update(rfbClient* client, int x, int y, int w, int h) {
vnc_client->copy_rect_used = 0;
}

guac_display_render_thread_notify_modified(vnc_client->render_thread);

}

void guac_vnc_copyrect(rfbClient* client, int src_x, int src_y, int w, int h, int dest_x, int dest_y) {
Expand Down
44 changes: 13 additions & 31 deletions src/protocols/vnc/vnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,44 +596,22 @@ void* guac_vnc_client_thread(void* data) {

guac_display_end_frame(vnc_client->display);

vnc_client->render_thread = guac_display_render_thread_create(vnc_client->display);

/* Handle messages from VNC server while client is running */
while (client->state == GUAC_CLIENT_RUNNING) {

/* Wait for data and construct a reasonable frame */
int wait_result = guac_vnc_wait_for_messages(rfb_client, GUAC_VNC_FRAME_START_TIMEOUT);
if (wait_result > 0) {

/* Read server messages until frame is built */
guac_timestamp frame_start = guac_timestamp_current();
do {

/* Handle any message received */
if (!guac_vnc_handle_messages(vnc_client)) {
guac_client_abort(client,
GUAC_PROTOCOL_STATUS_UPSTREAM_ERROR,
"Error handling message from VNC server.");
break;
}

int frame_duration = guac_timestamp_current() - frame_start;

/* Continue processing messages for up to a reasonable minimum
* framerate without an explicit frame boundary indicating that
* the frame is not yet complete */
if (frame_duration > GUAC_VNC_MAX_FRAME_DURATION)
break;

/* Do not exceed a reasonable maximum framerate without an
* explicit frame boundary terminating the frame early */
int allowed_wait = GUAC_VNC_MIN_FRAME_DURATION - frame_duration;
if (allowed_wait < 0)
allowed_wait = 0;

wait_result = guac_vnc_wait_for_messages(rfb_client, allowed_wait);

} while (wait_result > 0);

guac_display_end_frame(vnc_client->display);
/* Handle any message received */
if (!guac_vnc_handle_messages(vnc_client)) {
guac_client_abort(client,
GUAC_PROTOCOL_STATUS_UPSTREAM_ERROR,
"Error handling message from VNC server.");
break;
}

}

Expand All @@ -643,6 +621,10 @@ void* guac_vnc_client_thread(void* data) {

}

/* Stop render loop */
guac_display_render_thread_destroy(vnc_client->render_thread);
vnc_client->render_thread = NULL;

/* Kill client and finish connection */
guac_client_stop(client);
guac_client_log(client, GUAC_LOG_INFO, "Internal VNC client disconnected");
Expand Down
6 changes: 6 additions & 0 deletions src/protocols/vnc/vnc.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ typedef struct guac_vnc_client {
*/
guac_display_layer_raw_context* current_context;

/**
* The current instance of the guac_display render thread. If the thread
* has not yet been started, this will be NULL.
*/
guac_display_render_thread* render_thread;

/**
* Internal clipboard.
*/
Expand Down

0 comments on commit 16d4547

Please sign in to comment.