From 5d6e04171c40bff6739400acb4c50b4fed0cf75b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 29 Apr 2014 16:06:44 -0700 Subject: [PATCH] GUAC-656: Implement alloc/free for surface. --- src/common/guac_surface.c | 25 ++++++++++++++++++++++--- src/common/guac_surface.h | 19 +++++++++++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/common/guac_surface.c b/src/common/guac_surface.c index b68877b8..3d56ea9b 100644 --- a/src/common/guac_surface.c +++ b/src/common/guac_surface.c @@ -23,17 +23,36 @@ #include "config.h" #include "guac_surface.h" +#include #include #include #include +#include + guac_common_surface* guac_common_surface_alloc(guac_socket* socket, const guac_layer* layer, int w, int h) { - /* STUB */ - return NULL; + + /* Init surface */ + guac_common_surface* surface = malloc(sizeof(guac_common_surface)); + surface->layer = layer; + surface->socket = socket; + surface->width = w; + surface->height = h; + surface->dirty = 0; + + /* Create corresponding Cairo surface */ + surface->stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, w); + surface->buffer = malloc(surface->stride * h); + surface->surface = cairo_image_surface_create_for_data(surface->buffer, CAIRO_FORMAT_RGB24, + w, h, surface->stride); + + return surface; } void guac_common_surface_free(guac_common_surface* surface) { - /* STUB */ + cairo_surface_destroy(surface->surface); + free(surface->buffer); + free(surface); } void guac_common_surface_draw(guac_common_surface* surface, cairo_surface_t* src, int x, int y) { diff --git a/src/common/guac_surface.h b/src/common/guac_surface.h index 5600d330..892fb612 100644 --- a/src/common/guac_surface.h +++ b/src/common/guac_surface.h @@ -25,6 +25,7 @@ #include "config.h" +#include #include #include #include @@ -35,6 +36,16 @@ */ typedef struct guac_common_surface { + /** + * The layer this surface will draw to. + */ + const guac_layer* layer; + + /** + * The socket to send instructions on when flushing. + */ + guac_socket* socket; + /** * The width of this layer, in pixels. */ @@ -46,14 +57,14 @@ typedef struct guac_common_surface { int height; /** - * The layer this surface will draw to. + * The size of each image row, in bytes. */ - guac_layer* layer; + int stride; /** - * The socket to send instructions on when flushing. + * The underlying buffer of the Cairo surface. */ - guac_socket* socket; + unsigned char* buffer; /** * The Cairo surface containins this Guacamole surface's current