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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "guac_surface.h"
|
|
|
|
|
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-04-29 23:06:44 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2014-04-29 22:45:16 +00:00
|
|
|
guac_common_surface* guac_common_surface_alloc(guac_socket* socket, const guac_layer* layer, int w, int h) {
|
2014-04-29 23:06:44 +00:00
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
2014-04-30 18:59:43 +00:00
|
|
|
guac_protocol_send_size(socket, layer, w, h);
|
2014-04-29 23:06:44 +00:00
|
|
|
return surface;
|
2014-04-29 22:45:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void guac_common_surface_free(guac_common_surface* surface) {
|
2014-04-30 18:59:43 +00:00
|
|
|
guac_protocol_send_dispose(surface->socket, surface->layer);
|
2014-04-29 23:06:44 +00:00
|
|
|
cairo_surface_destroy(surface->surface);
|
|
|
|
free(surface->buffer);
|
|
|
|
free(surface);
|
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) {
|
|
|
|
|
|
|
|
guac_socket* socket = surface->socket;
|
|
|
|
const guac_layer* layer = surface->layer;
|
|
|
|
|
2014-04-29 22:45:16 +00:00
|
|
|
/* STUB */
|
2014-04-30 02:15:21 +00:00
|
|
|
guac_protocol_send_png(socket, GUAC_COMP_OVER, layer, x, y, src);
|
|
|
|
|
2014-04-29 22:45:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2014-04-30 02:15:21 +00:00
|
|
|
|
|
|
|
guac_socket* socket = dst->socket;
|
|
|
|
const guac_layer* src_layer = src->layer;
|
|
|
|
const guac_layer* dst_layer = dst->layer;
|
|
|
|
|
2014-04-29 22:45:16 +00:00
|
|
|
/* STUB */
|
2014-04-30 02:15:21 +00:00
|
|
|
guac_protocol_send_copy(socket, src_layer, sx, sy, w, h, GUAC_COMP_OVER, dst_layer, dx, dy);
|
|
|
|
|
2014-04-29 22:45:16 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
guac_socket* socket = dst->socket;
|
|
|
|
const guac_layer* src_layer = src->layer;
|
|
|
|
const guac_layer* dst_layer = dst->layer;
|
|
|
|
|
2014-04-29 22:45:16 +00:00
|
|
|
/* STUB */
|
2014-04-30 02:15:21 +00:00
|
|
|
guac_protocol_send_transfer(socket, src_layer, sx, sy, w, h, op, dst_layer, dx, dy);
|
|
|
|
|
2014-04-29 22:45:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void guac_common_surface_resize(guac_common_surface* surface, int w, int h) {
|
2014-04-30 02:15:21 +00:00
|
|
|
|
|
|
|
guac_socket* socket = surface->socket;
|
|
|
|
const guac_layer* layer = surface->layer;
|
|
|
|
|
2014-04-29 22:45:16 +00:00
|
|
|
/* STUB */
|
2014-04-30 02:15:21 +00:00
|
|
|
guac_protocol_send_size(socket, layer, w, h);
|
|
|
|
|
2014-04-29 22:45:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void guac_common_surface_rect(guac_common_surface* surface,
|
|
|
|
int x, int y, int w, int h,
|
|
|
|
int red, int green, int blue) {
|
2014-04-30 02:15:21 +00:00
|
|
|
|
|
|
|
guac_socket* socket = surface->socket;
|
|
|
|
const guac_layer* layer = surface->layer;
|
|
|
|
|
2014-04-29 22:45:16 +00:00
|
|
|
/* STUB */
|
2014-04-30 02:15:21 +00:00
|
|
|
guac_protocol_send_rect(socket, layer, x, y, w, h);
|
|
|
|
guac_protocol_send_cfill(socket, GUAC_COMP_OVER, layer, red, green, blue, 0xFF);
|
2014-04-29 22:45:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void guac_common_surface_flush(guac_common_surface* surface) {
|
|
|
|
/* STUB */
|
|
|
|
}
|
|
|
|
|