2014-04-29 22:45:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Glyptodon LLC
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __GUAC_COMMON_SURFACE_H
|
|
|
|
#define __GUAC_COMMON_SURFACE_H
|
|
|
|
|
|
|
|
#include "config.h"
|
2014-05-12 08:39:52 +00:00
|
|
|
#include "guac_rect.h"
|
2014-04-29 22:45:16 +00:00
|
|
|
|
2014-04-29 23:06:44 +00:00
|
|
|
#include <cairo/cairo.h>
|
2014-04-29 22:45:16 +00:00
|
|
|
#include <guacamole/layer.h>
|
|
|
|
#include <guacamole/protocol.h>
|
|
|
|
#include <guacamole/socket.h>
|
|
|
|
|
2014-05-09 22:39:00 +00:00
|
|
|
/**
|
|
|
|
* The maximum number of updates to allow within the PNG queue.
|
|
|
|
*/
|
|
|
|
#define GUAC_COMMON_SURFACE_QUEUE_SIZE 256
|
|
|
|
|
|
|
|
/**
|
2014-05-12 08:39:52 +00:00
|
|
|
* Representation of a PNG update, having a rectangle of image data (stored
|
|
|
|
* elsewhere) and a flushed/not-flushed state.
|
2014-05-09 22:39:00 +00:00
|
|
|
*/
|
|
|
|
typedef struct guac_common_surface_png_rect {
|
|
|
|
|
2014-05-10 01:45:10 +00:00
|
|
|
/**
|
|
|
|
* Whether this rectangle has been flushed.
|
|
|
|
*/
|
|
|
|
int flushed;
|
|
|
|
|
2014-05-09 22:39:00 +00:00
|
|
|
/**
|
2014-05-12 08:39:52 +00:00
|
|
|
* The rectangle containing the PNG update.
|
2014-05-09 22:39:00 +00:00
|
|
|
*/
|
2014-05-12 08:39:52 +00:00
|
|
|
guac_common_rect rect;
|
2014-05-09 22:39:00 +00:00
|
|
|
|
|
|
|
} guac_common_surface_png_rect;
|
|
|
|
|
2014-04-29 22:45:16 +00:00
|
|
|
/**
|
|
|
|
* Surface which backs a Guacamole buffer or layer, automatically
|
|
|
|
* combining updates when possible.
|
|
|
|
*/
|
|
|
|
typedef struct guac_common_surface {
|
|
|
|
|
2014-04-29 23:06:44 +00:00
|
|
|
/**
|
|
|
|
* The layer this surface will draw to.
|
|
|
|
*/
|
|
|
|
const guac_layer* layer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The socket to send instructions on when flushing.
|
|
|
|
*/
|
|
|
|
guac_socket* socket;
|
|
|
|
|
2014-04-29 22:45:16 +00:00
|
|
|
/**
|
|
|
|
* The width of this layer, in pixels.
|
|
|
|
*/
|
|
|
|
int width;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The height of this layer, in pixels.
|
|
|
|
*/
|
|
|
|
int height;
|
|
|
|
|
|
|
|
/**
|
2014-04-29 23:06:44 +00:00
|
|
|
* The size of each image row, in bytes.
|
2014-04-29 22:45:16 +00:00
|
|
|
*/
|
2014-04-29 23:06:44 +00:00
|
|
|
int stride;
|
2014-04-29 22:45:16 +00:00
|
|
|
|
|
|
|
/**
|
2014-04-29 23:06:44 +00:00
|
|
|
* The underlying buffer of the Cairo surface.
|
2014-04-29 22:45:16 +00:00
|
|
|
*/
|
2014-04-29 23:06:44 +00:00
|
|
|
unsigned char* buffer;
|
2014-04-29 22:45:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Non-zero if this surface is dirty and needs to be flushed, 0 otherwise.
|
|
|
|
*/
|
|
|
|
int dirty;
|
|
|
|
|
|
|
|
/**
|
2014-05-12 08:39:52 +00:00
|
|
|
* The dirty rectangle.
|
2014-04-29 22:45:16 +00:00
|
|
|
*/
|
2014-05-12 08:39:52 +00:00
|
|
|
guac_common_rect dirty_rect;
|
2014-04-29 22:45:16 +00:00
|
|
|
|
2014-05-01 19:23:37 +00:00
|
|
|
/**
|
|
|
|
* Whether the surface actually exists on the client.
|
|
|
|
*/
|
|
|
|
int realized;
|
|
|
|
|
2015-01-16 01:03:26 +00:00
|
|
|
/**
|
|
|
|
* Whether drawing operations are currently clipped by the clipping
|
|
|
|
* rectangle.
|
|
|
|
*/
|
|
|
|
int clipped;
|
|
|
|
|
2014-05-05 00:00:26 +00:00
|
|
|
/**
|
2014-11-10 18:26:00 +00:00
|
|
|
* The clipping rectangle.
|
2014-05-05 00:00:26 +00:00
|
|
|
*/
|
2014-11-10 18:26:00 +00:00
|
|
|
guac_common_rect clip_rect;
|
2014-05-05 00:00:26 +00:00
|
|
|
|
2014-05-09 22:39:00 +00:00
|
|
|
/**
|
|
|
|
* The number of updates in the PNG queue.
|
|
|
|
*/
|
|
|
|
int png_queue_length;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All queued PNG updates.
|
|
|
|
*/
|
|
|
|
guac_common_surface_png_rect png_queue[GUAC_COMMON_SURFACE_QUEUE_SIZE];
|
|
|
|
|
2014-04-29 22:45:16 +00:00
|
|
|
} guac_common_surface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates a new guac_common_surface, assigning it to the given layer.
|
|
|
|
*
|
|
|
|
* @param socket The socket to send instructions on when flushing.
|
|
|
|
* @param layer The layer to associate with the new surface.
|
|
|
|
* @param w The width of the surface.
|
|
|
|
* @param h The height of the surface.
|
|
|
|
* @return A newly-allocated guac_common_surface.
|
|
|
|
*/
|
|
|
|
guac_common_surface* guac_common_surface_alloc(guac_socket* socket, const guac_layer* layer, int w, int h);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Frees the given guac_common_surface. Beware that this will NOT free any
|
|
|
|
* associated layers, which must be freed manually.
|
|
|
|
*
|
|
|
|
* @param surface The surface to free.
|
|
|
|
*/
|
|
|
|
void guac_common_surface_free(guac_common_surface* surface);
|
|
|
|
|
2014-05-01 18:27:10 +00:00
|
|
|
/**
|
|
|
|
* Resizes the given surface to the given size.
|
|
|
|
*
|
|
|
|
* @param surface The surface to resize.
|
|
|
|
* @param w The width of the surface.
|
|
|
|
* @param h The height of the surface.
|
|
|
|
*/
|
|
|
|
void guac_common_surface_resize(guac_common_surface* surface, int w, int h);
|
|
|
|
|
2014-04-29 22:45:16 +00:00
|
|
|
/**
|
|
|
|
* Draws the given data to the given guac_common_surface.
|
|
|
|
*
|
|
|
|
* @param surface The surface to draw to.
|
|
|
|
* @param x The X coordinate of the draw location.
|
|
|
|
* @param y The Y coordinate of the draw location.
|
2014-04-30 02:15:21 +00:00
|
|
|
* @param src The Cairo surface to retrieve data from.
|
2014-04-29 22:45:16 +00:00
|
|
|
*/
|
2014-04-30 02:15:21 +00:00
|
|
|
void guac_common_surface_draw(guac_common_surface* surface, int x, int y, cairo_surface_t* src);
|
2014-04-29 22:45:16 +00:00
|
|
|
|
2014-05-05 07:27:48 +00:00
|
|
|
/**
|
|
|
|
* Paints to the given guac_common_surface using the given data as a stencil,
|
|
|
|
* filling opaque regions with the specified color, and leaving transparent
|
|
|
|
* regions untouched.
|
|
|
|
*
|
|
|
|
* @param surface The surface to draw to.
|
|
|
|
* @param x The X coordinate of the draw location.
|
|
|
|
* @param y The Y coordinate of the draw location.
|
|
|
|
* @param src The Cairo surface to retrieve data from.
|
|
|
|
* @param red The red component of the fill color.
|
|
|
|
* @param green The green component of the fill color.
|
|
|
|
* @param blue The blue component of the fill color.
|
|
|
|
*/
|
|
|
|
void guac_common_surface_paint(guac_common_surface* surface, int x, int y, cairo_surface_t* src,
|
|
|
|
int red, int green, int blue);
|
|
|
|
|
2014-04-29 22:45:16 +00:00
|
|
|
/**
|
|
|
|
* Copies a rectangle of data between two surfaces.
|
|
|
|
*
|
|
|
|
* @param src The source surface.
|
|
|
|
* @param sx The X coordinate of the upper-left corner of the source rect.
|
|
|
|
* @param sy The Y coordinate of the upper-left corner of the source rect.
|
|
|
|
* @param w The width of the source rect.
|
|
|
|
* @param h The height of the source rect.
|
|
|
|
* @param dst The destination surface.
|
|
|
|
* @param dx The X coordinate of the upper-left corner of the destination rect.
|
|
|
|
* @param dy The Y coordinate of the upper-left corner of the destination rect.
|
|
|
|
*/
|
|
|
|
void guac_common_surface_copy(guac_common_surface* src, int sx, int sy, int w, int h,
|
|
|
|
guac_common_surface* dst, int dx, int dy);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transfers a rectangle of data between two surfaces.
|
|
|
|
*
|
|
|
|
* @param src The source surface.
|
|
|
|
* @param sx The X coordinate of the upper-left corner of the source rect.
|
|
|
|
* @param sy The Y coordinate of the upper-left corner of the source rect.
|
|
|
|
* @param w The width of the source rect.
|
|
|
|
* @param h The height of the source rect.
|
2014-04-30 02:15:21 +00:00
|
|
|
* @param op The transfer function.
|
2014-04-29 22:45:16 +00:00
|
|
|
* @param dst The destination surface.
|
|
|
|
* @param dx The X coordinate of the upper-left corner of the destination rect.
|
|
|
|
* @param dy The Y coordinate of the upper-left corner of the destination rect.
|
|
|
|
*/
|
2014-04-30 02:15:21 +00:00
|
|
|
void guac_common_surface_transfer(guac_common_surface* src, int sx, int sy, int w, int h,
|
|
|
|
guac_transfer_function op, guac_common_surface* dst, int dx, int dy);
|
2014-04-29 22:45:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws a solid color rectangle at the given coordinates on the given surface.
|
|
|
|
*
|
|
|
|
* @param surface The surface to draw upon.
|
|
|
|
* @param x The X coordinate of the upper-left corner of the rectangle.
|
|
|
|
* @param y The Y coordinate of the upper-left corner of the rectangle.
|
|
|
|
* @param w The width of the rectangle.
|
|
|
|
* @param h The height of the rectangle.
|
|
|
|
* @param red The red component of the color of the rectangle.
|
|
|
|
* @param green The green component of the color of the rectangle.
|
|
|
|
* @param blue The blue component of the color of the rectangle.
|
|
|
|
*/
|
|
|
|
void guac_common_surface_rect(guac_common_surface* surface,
|
|
|
|
int x, int y, int w, int h,
|
|
|
|
int red, int green, int blue);
|
|
|
|
|
2014-05-05 00:00:26 +00:00
|
|
|
/**
|
|
|
|
* Given the coordinates and dimensions of a rectangle, clips all future
|
|
|
|
* operations within that rectangle.
|
|
|
|
*
|
|
|
|
* @param surface The surface whose clipping rectangle should be changed.
|
|
|
|
* @param x The X coordinate of the upper-left corner of the bounding rectangle.
|
|
|
|
* @param y The Y coordinate of the upper-left corner of the bounding rectangle.
|
|
|
|
* @param w The width of the bounding rectangle.
|
|
|
|
* @param h The height of the bounding rectangle.
|
|
|
|
*/
|
|
|
|
void guac_common_surface_clip(guac_common_surface* surface, int x, int y, int w, int h);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets the clipping rectangle, allowing drawing operations throughout the
|
|
|
|
* entire surface.
|
|
|
|
*
|
|
|
|
* @param surface The surface whose clipping rectangle should be reset.
|
|
|
|
*/
|
|
|
|
void guac_common_surface_reset_clip(guac_common_surface* surface);
|
|
|
|
|
2014-04-29 22:45:16 +00:00
|
|
|
/**
|
|
|
|
* Flushes the given surface, drawing any pending operations on the remote
|
|
|
|
* display.
|
|
|
|
*
|
|
|
|
* @param surface The surface to flush.
|
|
|
|
*/
|
|
|
|
void guac_common_surface_flush(guac_common_surface* surface);
|
|
|
|
|
2014-05-09 22:39:00 +00:00
|
|
|
/**
|
|
|
|
* Schedules a deferred flush of the given surface. This will not immediately
|
|
|
|
* flush the surface to the client. Instead, the result of the flush is
|
|
|
|
* added to a queue which is reinspected and combined (if possible) with other
|
|
|
|
* deferred flushes during the call to guac_common_surface_flush().
|
|
|
|
*
|
|
|
|
* @param surface The surface to flush.
|
|
|
|
*/
|
|
|
|
void guac_common_surface_flush_deferred(guac_common_surface* surface);
|
|
|
|
|
2014-04-29 22:45:16 +00:00
|
|
|
#endif
|
|
|
|
|