void guac_rdp_cache_bitmap(rdpContext* context, rdpBitmap* bitmap) { guac_client* client = ((rdp_freerdp_context*) context)->client; guac_socket* socket = client->socket; /* Allocate buffer */ guac_layer* buffer = guac_client_alloc_buffer(client); /* Cache image data if present */ if (bitmap->data != NULL) { /* Create surface from image data */ cairo_surface_t* surface = cairo_image_surface_create_for_data( bitmap->data, CAIRO_FORMAT_RGB24, bitmap->width, bitmap->height, 4*bitmap->width); /* Send surface to buffer */ guac_protocol_send_png(socket, GUAC_COMP_SRC, buffer, 0, 0, surface); /* Free surface */ cairo_surface_destroy(surface); } /* Store buffer reference in bitmap */ ((guac_rdp_bitmap*) bitmap)->layer = buffer; }
void guac_common_set_pointer_cursor(guac_client* client) { guac_socket* socket = client->socket; /* Draw to buffer */ guac_layer* cursor = guac_client_alloc_buffer(client); cairo_surface_t* graphic = cairo_image_surface_create_for_data( guac_common_pointer_cursor, guac_common_pointer_cursor_format, guac_common_pointer_cursor_width, guac_common_pointer_cursor_height, guac_common_pointer_cursor_stride); guac_protocol_send_png(socket, GUAC_COMP_SRC, cursor, 0, 0, graphic); cairo_surface_destroy(graphic); /* Set cursor */ guac_protocol_send_cursor(socket, 0, 0, cursor, 0, 0, guac_common_pointer_cursor_width, guac_common_pointer_cursor_height); /* Free buffer */ guac_client_free_buffer(client, cursor); guac_client_log(client, GUAC_LOG_DEBUG, "Client cursor image set to generic built-in pointer."); }
void guac_rdp_bitmap_paint(rdpContext* context, rdpBitmap* bitmap) { guac_client* client = ((rdp_freerdp_context*) context)->client; guac_socket* socket = client->socket; int width = bitmap->right - bitmap->left + 1; int height = bitmap->bottom - bitmap->top + 1; /* If not cached, cache if necessary */ if (((guac_rdp_bitmap*) bitmap)->layer == NULL && ((guac_rdp_bitmap*) bitmap)->used >= 1) guac_rdp_cache_bitmap(context, bitmap); /* If cached, retrieve from cache */ if (((guac_rdp_bitmap*) bitmap)->layer != NULL) guac_protocol_send_copy(socket, ((guac_rdp_bitmap*) bitmap)->layer, 0, 0, width, height, GUAC_COMP_OVER, GUAC_DEFAULT_LAYER, bitmap->left, bitmap->top); /* Otherwise, draw with stored image data */ else if (bitmap->data != NULL) { /* Create surface from image data */ cairo_surface_t* surface = cairo_image_surface_create_for_data( bitmap->data, CAIRO_FORMAT_RGB24, width, height, 4*bitmap->width); /* Send surface to buffer */ guac_protocol_send_png(socket, GUAC_COMP_OVER, GUAC_DEFAULT_LAYER, bitmap->left, bitmap->top, surface); /* Free surface */ cairo_surface_destroy(surface); } /* Increment usage counter */ ((guac_rdp_bitmap*) bitmap)->used++; }
void guac_rdp_pointer_new(rdpContext* context, rdpPointer* pointer) { guac_client* client = ((rdp_freerdp_context*) context)->client; guac_socket* socket = client->socket; /* Allocate data for image */ unsigned char* data = (unsigned char*) malloc(pointer->width * pointer->height * 4); /* Allocate layer */ guac_layer* buffer = guac_client_alloc_buffer(client); cairo_surface_t* surface; /* Convert to alpha cursor if mask data present */ if (pointer->andMaskData && pointer->xorMaskData) freerdp_alpha_cursor_convert(data, pointer->xorMaskData, pointer->andMaskData, pointer->width, pointer->height, pointer->xorBpp, ((rdp_freerdp_context*) context)->clrconv); /* Create surface from image data */ surface = cairo_image_surface_create_for_data( data, CAIRO_FORMAT_ARGB32, pointer->width, pointer->height, 4*pointer->width); /* Send surface to buffer */ guac_protocol_send_png(socket, GUAC_COMP_SRC, buffer, 0, 0, surface); /* Free surface */ cairo_surface_destroy(surface); free(data); /* Remember buffer */ ((guac_rdp_pointer*) pointer)->layer = buffer; }
void guac_rdp_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt) { guac_client* client = ((rdp_freerdp_context*) context)->client; const guac_layer* current_layer = ((rdp_guac_client_data*) client->data)->current_surface; guac_socket* socket = client->socket; 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; rdp_guac_client_data* data = (rdp_guac_client_data*) client->data; pthread_mutex_lock(&(data->update_lock)); /* Clip operation to bounds */ __guac_rdp_clip_rect(data, &x, &y, &w, &h); /* Update source coordinates */ x_src += x - memblt->nLeftRect; y_src += y - memblt->nTopRect; switch (memblt->bRop) { /* If blackness, send black rectangle */ case 0x00: guac_protocol_send_rect(client->socket, current_layer, x, y, w, h); guac_protocol_send_cfill(client->socket, GUAC_COMP_OVER, current_layer, 0x00, 0x00, 0x00, 0xFF); break; /* If NOP, do nothing */ case 0xAA: break; /* If operation is just SRC, simply copy */ case 0xCC: /* If not cached, cache if necessary */ if (((guac_rdp_bitmap*) bitmap)->layer == NULL && ((guac_rdp_bitmap*) bitmap)->used >= 1) guac_rdp_cache_bitmap(context, memblt->bitmap); /* If not cached, send as PNG */ if (bitmap->layer == 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_protocol_send_png(socket, GUAC_COMP_OVER, current_layer, x, y, surface); /* Free surface */ cairo_surface_destroy(surface); } } /* Otherwise, copy */ else guac_protocol_send_copy(socket, bitmap->layer, x_src, y_src, w, h, GUAC_COMP_OVER, current_layer, x, y); /* Increment usage counter */ ((guac_rdp_bitmap*) bitmap)->used++; break; /* If whiteness, send white rectangle */ case 0xFF: guac_protocol_send_rect(client->socket, current_layer, x, y, w, h); guac_protocol_send_cfill(client->socket, GUAC_COMP_OVER, current_layer, 0xFF, 0xFF, 0xFF, 0xFF); break; /* Otherwise, use transfer */ default: /* If not available as a surface, make available. */ if (bitmap->layer == NULL) guac_rdp_cache_bitmap(context, memblt->bitmap); guac_protocol_send_transfer(socket, bitmap->layer, x_src, y_src, w, h, guac_rdp_rop3_transfer_function(client, memblt->bRop), current_layer, x, y); /* Increment usage counter */ ((guac_rdp_bitmap*) bitmap)->used++; } pthread_mutex_unlock(&(data->update_lock)); }