void guac_rdp_gdi_scrblt(rdpContext* context, SCRBLT_ORDER* scrblt) { guac_client* client = ((rdp_freerdp_context*) context)->client; guac_common_surface* current_surface = ((rdp_guac_client_data*) client->data)->current_surface; int x = scrblt->nLeftRect; int y = scrblt->nTopRect; int w = scrblt->nWidth; int h = scrblt->nHeight; int x_src = scrblt->nXSrc; int y_src = scrblt->nYSrc; rdp_guac_client_data* data = (rdp_guac_client_data*) client->data; /* Copy screen rect to current surface */ guac_common_surface_copy(data->default_surface, x_src, y_src, w, h, current_surface, x, y); }
void guac_rdp_bitmap_paint(rdpContext* context, rdpBitmap* bitmap) { guac_client* client = ((rdp_freerdp_context*) context)->client; rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data; guac_common_surface* surface = ((guac_rdp_bitmap*) bitmap)->surface; int width = bitmap->right - bitmap->left + 1; int height = bitmap->bottom - bitmap->top + 1; /* If not cached, cache if necessary */ if (surface == NULL && ((guac_rdp_bitmap*) bitmap)->used >= 1) guac_rdp_cache_bitmap(context, bitmap); /* If cached, retrieve from cache */ if (surface != NULL) guac_common_surface_copy(surface, 0, 0, width, height, client_data->default_surface, bitmap->left, bitmap->top); /* Otherwise, draw with stored image data */ else if (bitmap->data != NULL) { /* Create surface from image data */ cairo_surface_t* image = cairo_image_surface_create_for_data( bitmap->data, CAIRO_FORMAT_RGB24, width, height, 4*bitmap->width); /* Draw image on default surface */ guac_common_surface_draw(client_data->default_surface, bitmap->left, bitmap->top, image); /* Free surface */ cairo_surface_destroy(image); } /* Increment usage counter */ ((guac_rdp_bitmap*) bitmap)->used++; }
void guac_rdp_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt) { guac_client* client = ((rdp_freerdp_context*) context)->client; guac_common_surface* current_surface = ((rdp_guac_client_data*) client->data)->current_surface; guac_rdp_bitmap* bitmap = (guac_rdp_bitmap*) memblt->bitmap; int x = memblt->nLeftRect; int y = memblt->nTopRect; int w = memblt->nWidth; int h = memblt->nHeight; int x_src = memblt->nXSrc; int y_src = memblt->nYSrc; /* Make sure that the recieved bitmap is not NULL before processing */ if (bitmap == NULL) { guac_client_log(client, GUAC_LOG_INFO, "NULL bitmap found in memblt instruction."); return; } switch (memblt->bRop) { /* If blackness, send black rectangle */ case 0x00: guac_common_surface_rect(current_surface, x, y, w, h, 0, 0, 0); break; /* If NOP, do nothing */ case 0xAA: break; /* If operation is just SRC, simply copy */ case 0xCC: /* If not cached, cache if necessary */ if (bitmap->surface == NULL && bitmap->used >= 1) guac_rdp_cache_bitmap(context, memblt->bitmap); /* If not cached, send as PNG */ if (bitmap->surface == NULL) { if (memblt->bitmap->data != NULL) { /* Create surface from image data */ cairo_surface_t* surface = cairo_image_surface_create_for_data( memblt->bitmap->data + 4*(x_src + y_src*memblt->bitmap->width), CAIRO_FORMAT_RGB24, w, h, 4*memblt->bitmap->width); /* Send surface to buffer */ guac_common_surface_draw(current_surface, x, y, surface); /* Free surface */ cairo_surface_destroy(surface); } } /* Otherwise, copy */ else guac_common_surface_copy(bitmap->surface, x_src, y_src, w, h, current_surface, x, y); /* Increment usage counter */ ((guac_rdp_bitmap*) bitmap)->used++; break; /* If whiteness, send white rectangle */ case 0xFF: guac_common_surface_rect(current_surface, x, y, w, h, 0xFF, 0xFF, 0xFF); break; /* Otherwise, use transfer */ default: /* If not available as a surface, make available. */ if (bitmap->surface == NULL) guac_rdp_cache_bitmap(context, memblt->bitmap); guac_common_surface_transfer(bitmap->surface, x_src, y_src, w, h, guac_rdp_rop3_transfer_function(client, memblt->bRop), current_surface, x, y); /* Increment usage counter */ ((guac_rdp_bitmap*) bitmap)->used++; } }
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++; } } }