Skip to content

Commit

Permalink
GUACAMOLE-377: Prefer GUAC_COMP_OVER to GUAC_COMP_SRC for performance…
Browse files Browse the repository at this point in the history
…-critical operations (~3x faster).
  • Loading branch information
mike-jumper committed Aug 29, 2024
1 parent 7a56740 commit 31cfbb3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
29 changes: 25 additions & 4 deletions src/libguac/display-worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "guacamole/display.h"
#include "guacamole/fifo.h"
#include "guacamole/layer.h"
#include "guacamole/protocol-types.h"
#include "guacamole/protocol.h"
#include "guacamole/rect.h"
#include "guacamole/rwlock.h"
Expand Down Expand Up @@ -446,23 +447,43 @@ void* guac_display_worker_thread(void* data) {
/* Allow connected clients to move forward with rendering */
guac_client_end_multiple_frames(client, display->last_frame.frames);

/* Commit any changed contents to client-side backing buffer */
/* While connected clients moves forward with rendering,
* commit any changed contents to client-side backing buffer */
guac_display_layer* current = display->last_frame.layers;
while (current != NULL) {

/* Save a copy of the changed region if the layer has
* been modified since the last frame */
guac_rect* dirty = &current->last_frame.dirty;
if (!guac_rect_is_empty(dirty)) {
guac_protocol_send_copy(client->socket, current->layer,
0, 0, current->last_frame.width, current->last_frame.height,
GUAC_COMP_SRC, current->last_frame_buffer, 0, 0);

int x = dirty->left;
int y = dirty->top;
int width = guac_rect_width(dirty);
int height = guac_rect_height(dirty);

/* Ensure destination region is cleared out first if the alpha channel need be considered,
* as GUAC_COMP_OVER is significantly faster than GUAC_COMP_SRC on the browser side */
if (!current->opaque) {
guac_protocol_send_rect(client->socket, current->last_frame_buffer, x, y, width, height);
guac_protocol_send_cfill(client->socket, GUAC_COMP_RATOP, current->last_frame_buffer,
0x00, 0x00, 0x00, 0x00);
}

guac_protocol_send_copy(client->socket,
current->layer, x, y, width, height,
GUAC_COMP_OVER, current->last_frame_buffer, x, y);

}

current = current->last_frame.next;

}

/* Include an additional frame boundary to allow the client to also move forward with committing
* changes to the backing buffer while the server is receiving and preparing the next frame */
guac_client_end_multiple_frames(client, 0);

/* This is now absolutely everything for the current frame,
* and it's safe to flush any outstanding data */
guac_socket_flush(client->socket);
Expand Down
2 changes: 1 addition & 1 deletion src/libguac/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void guac_display_dup(guac_display* display, guac_socket* socket) {
/* Resync copy of previous frame */
guac_protocol_send_copy(socket,
layer, 0, 0, width, height,
GUAC_COMP_SRC, current->last_frame_buffer, 0, 0);
GUAC_COMP_OVER, current->last_frame_buffer, 0, 0);

/* Resync any properties that are specific to non-buffer layers */
if (current->layer->index > 0) {
Expand Down

0 comments on commit 31cfbb3

Please sign in to comment.