in src/terminal/display.c [566:689]
void __guac_terminal_display_flush_copy(guac_terminal_display* display) {
guac_terminal_operation* current = display->operations;
int row, col;
/* For each operation */
for (row=0; row<display->height; row++) {
for (col=0; col<display->width; col++) {
/* If operation is a copy operation */
if (current->type == GUAC_CHAR_COPY) {
/* The determined bounds of the rectangle of contiguous
* operations */
int detected_right = -1;
int detected_bottom = row;
/* The current row or column within a rectangle */
int rect_row, rect_col;
/* The dimensions of the rectangle as determined */
int rect_width, rect_height;
/* The expected row and column source for the next copy
* operation (if adjacent to current) */
int expected_row, expected_col;
/* Current row within a subrect */
guac_terminal_operation* rect_current_row;
/* Determine bounds of rectangle */
rect_current_row = current;
expected_row = current->row;
for (rect_row=row; rect_row<display->height; rect_row++) {
guac_terminal_operation* rect_current = rect_current_row;
expected_col = current->column;
/* Find width */
for (rect_col=col; rect_col<display->width; rect_col++) {
/* If not identical operation, stop */
if (rect_current->type != GUAC_CHAR_COPY
|| rect_current->row != expected_row
|| rect_current->column != expected_col)
break;
/* Next column */
rect_current++;
expected_col++;
}
/* If too small, cannot append row */
if (rect_col-1 < detected_right)
break;
/* As row has been accepted, update rect_row of rect */
detected_bottom = rect_row;
/* For now, only set rect_col bound if uninitialized */
if (detected_right == -1)
detected_right = rect_col - 1;
/* Next row */
rect_current_row += display->width;
expected_row++;
}
/* Calculate dimensions */
rect_width = detected_right - col + 1;
rect_height = detected_bottom - row + 1;
/* Mark rect as NOP (as it has been handled) */
rect_current_row = current;
expected_row = current->row;
for (rect_row=0; rect_row<rect_height; rect_row++) {
guac_terminal_operation* rect_current = rect_current_row;
expected_col = current->column;
for (rect_col=0; rect_col<rect_width; rect_col++) {
/* Mark copy operations as NOP */
if (rect_current->type == GUAC_CHAR_COPY
&& rect_current->row == expected_row
&& rect_current->column == expected_col)
rect_current->type = GUAC_CHAR_NOP;
/* Next column */
rect_current++;
expected_col++;
}
/* Next row */
rect_current_row += display->width;
expected_row++;
}
/* Send copy */
guac_common_surface_copy(
display->display_surface,
current->column * display->char_width,
current->row * display->char_height,
rect_width * display->char_width,
rect_height * display->char_height,
display->display_surface,
col * display->char_width,
row * display->char_height);
} /* end if copy operation */
/* Next operation */
current++;
}
}
}