From 3186ce25ffe84ce7aef8912413076b65400dbab9 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 5 Apr 2012 22:55:46 -0700 Subject: [PATCH] Fix transparent glyphs --- include/client.h | 16 ++++++++++++++-- src/client.c | 8 ++++---- src/rdp_glyph.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/include/client.h b/include/client.h index 246834f..306dbce 100644 --- a/include/client.h +++ b/include/client.h @@ -55,12 +55,24 @@ typedef struct rdp_guac_client_data { int mouse_button_mask; /** - * Cairo surface which will receive all drawn glyphs. + * Cairo surface which will receive all TRANSPARENT glyphs. + */ + cairo_surface_t* trans_glyph_surface; + + /** + * Cairo surface which will receive all OPAQUE glyphs. + */ + cairo_surface_t* opaque_glyph_surface; + + /** + * The current Cairo surface which will receive all drawn glyphs, + * depending on whether we are currently drawing transparent or + * opaque glyphs. */ cairo_surface_t* glyph_surface; /** - * Cairo instance for drawing to glyph surface. + * Cairo instance for drawing to the current glyph surface. */ cairo_t* glyph_cairo; diff --git a/src/client.c b/src/client.c index e71d839..8a87d05 100644 --- a/src/client.c +++ b/src/client.c @@ -393,12 +393,12 @@ int guac_client_init(guac_client* client, int argc, char** argv) { guac_protocol_send_size(client->socket, GUAC_DEFAULT_LAYER, settings->width, settings->height); - /* Create glyph surface and cairo instance */ - guac_client_data->glyph_surface = cairo_image_surface_create( + /* Create glyph surfaces */ + guac_client_data->opaque_glyph_surface = cairo_image_surface_create( CAIRO_FORMAT_RGB24, settings->width, settings->height); - guac_client_data->glyph_cairo = cairo_create( - guac_client_data->glyph_surface); + guac_client_data->trans_glyph_surface = cairo_image_surface_create( + CAIRO_FORMAT_ARGB32, settings->width, settings->height); /* Success */ return 0; diff --git a/src/rdp_glyph.c b/src/rdp_glyph.c index c259725..3e939f6 100644 --- a/src/rdp_glyph.c +++ b/src/rdp_glyph.c @@ -139,6 +139,14 @@ void guac_rdp_glyph_begindraw(rdpContext* context, /* Fill background with color if specified */ if (width != 0 && height != 0) { + /* Prepare for opaque glyphs */ + guac_client_data->glyph_surface = + guac_client_data->opaque_glyph_surface; + + /* Create cairo instance */ + guac_client_data->glyph_cairo = cairo_create( + guac_client_data->glyph_surface); + /* Convert background color */ bgcolor = freerdp_color_convert_var(bgcolor, context->instance->settings->color_depth, 32, @@ -157,6 +165,29 @@ void guac_rdp_glyph_begindraw(rdpContext* context, } + /* Otherwise, prepare for transparent glyphs */ + else { + + /* Select transparent glyph surface */ + guac_client_data->glyph_surface = + guac_client_data->trans_glyph_surface; + + guac_client_data->glyph_cairo = cairo_create( + guac_client_data->glyph_surface); + + /* Clear surface */ + cairo_set_operator(guac_client_data->glyph_cairo, + CAIRO_OPERATOR_SOURCE); + + cairo_set_source_rgba(guac_client_data->glyph_cairo, 0, 0, 0, 0); + cairo_paint(guac_client_data->glyph_cairo); + + /* Restore operator */ + cairo_set_operator(guac_client_data->glyph_cairo, + CAIRO_OPERATOR_OVER); + + } + /* Prepare for glyph drawing */ cairo_set_source_rgb(guac_client_data->glyph_cairo, ( fgcolor & 0x0000FF ) / 255.0, @@ -193,5 +224,8 @@ void guac_rdp_glyph_enddraw(rdpContext* context, /* Destroy surface */ cairo_surface_destroy(surface); + /* Destroy cairo instance */ + cairo_destroy(guac_client_data->glyph_cairo); + } -- 1.7.10.4