From 9c2d7f56ce1fcaaa9d212c7260b03842de754ba7 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 11 Aug 2015 16:26:24 -0700 Subject: [PATCH] GUAC-240: Add function for streaming PNG images via img instruction. Use for surface. --- src/common/guac_surface.c | 3 ++- src/libguac/client.c | 22 ++++++++++++++++++++++ src/libguac/guacamole/client.h | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/common/guac_surface.c b/src/common/guac_surface.c index 3ef36666..8780c052 100644 --- a/src/common/guac_surface.c +++ b/src/common/guac_surface.c @@ -969,7 +969,8 @@ static void __guac_common_surface_flush_to_png(guac_common_surface* surface) { surface->stride); /* Send PNG for rect */ - guac_protocol_send_png(socket, GUAC_COMP_OVER, layer, surface->dirty_rect.x, surface->dirty_rect.y, rect); + guac_client_stream_png(surface->client, socket, GUAC_COMP_OVER, + layer, surface->dirty_rect.x, surface->dirty_rect.y, rect); cairo_surface_destroy(rect); surface->realized = 1; diff --git a/src/libguac/client.c b/src/libguac/client.c index 2bb9004d..ca1c30fe 100644 --- a/src/libguac/client.c +++ b/src/libguac/client.c @@ -24,6 +24,7 @@ #include "client.h" #include "client-handlers.h" +#include "encode-png.h" #include "error.h" #include "instruction.h" #include "layer.h" @@ -375,3 +376,24 @@ void guac_client_abort(guac_client* client, guac_protocol_status status, } +void guac_client_stream_png(guac_client* client, guac_socket* socket, + guac_composite_mode mode, const guac_layer* layer, int x, int y, + cairo_surface_t* surface) { + + /* Allocate new stream for image */ + guac_stream* stream = guac_client_alloc_stream(client); + + /* Declare stream as containing image data */ + guac_protocol_send_img(socket, stream, mode, layer, "image/png", x, y); + + /* Write PNG data */ + guac_png_write(socket, stream, surface); + + /* Terminate stream */ + guac_protocol_send_end(socket, stream); + + /* Free allocated stream */ + guac_client_free_stream(client, stream); + +} + diff --git a/src/libguac/guacamole/client.h b/src/libguac/guacamole/client.h index 6d0cc85a..b8773c10 100644 --- a/src/libguac/guacamole/client.h +++ b/src/libguac/guacamole/client.h @@ -40,6 +40,7 @@ #include "stream-types.h" #include "timestamp-types.h" +#include #include struct guac_client_info { @@ -627,6 +628,39 @@ guac_object* guac_client_alloc_object(guac_client* client); */ void guac_client_free_object(guac_client* client, guac_object* object); +/** + * Streams the image data of the given surface over an image stream ("img" + * instruction) as PNG-encoded data. The image stream will be automatically + * allocated and freed. + * + * @param client + * The Guacamole client from which the image stream should be allocated. + * + * @param socket + * The socket over which instructions associated with the image stream + * should be sent. + * + * @param mode + * The composite mode to use when rendering the image over the given layer. + * + * @param layer + * The destination layer. + * + * @param x + * The X coordinate of the upper-left corner of the destination rectangle + * within the given layer. + * + * @param y + * The Y coordinate of the upper-left corner of the destination rectangle + * within the given layer. + * + * @param surface + * A Cairo surface containing the image data to be streamed. + */ +void guac_client_stream_png(guac_client* client, guac_socket* socket, + guac_composite_mode mode, const guac_layer* layer, int x, int y, + cairo_surface_t* surface); + /** * The default Guacamole client layer, layer 0. */