GUAC-236: Implement cfill and rect.

This commit is contained in:
Michael Jumper 2016-02-27 15:15:17 -08:00
parent 160453c3e9
commit ac78b7a7a5
4 changed files with 101 additions and 10 deletions

View File

@ -25,6 +25,7 @@
#include "log.h" #include "log.h"
#include <guacamole/client.h> #include <guacamole/client.h>
#include <guacamole/protocol.h>
#include <guacamole/timestamp.h> #include <guacamole/timestamp.h>
#include <stdlib.h> #include <stdlib.h>
@ -169,6 +170,63 @@ guacenc_buffer* guacenc_display_get_related_buffer(guacenc_display* display,
} }
cairo_operator_t guacenc_display_cairo_operator(guac_composite_mode mask) {
/* Translate Guacamole channel mask into Cairo operator */
switch (mask) {
/* Source */
case GUAC_COMP_SRC:
return CAIRO_OPERATOR_SOURCE;
/* Over */
case GUAC_COMP_OVER:
return CAIRO_OPERATOR_OVER;
/* In */
case GUAC_COMP_IN:
return CAIRO_OPERATOR_IN;
/* Out */
case GUAC_COMP_OUT:
return CAIRO_OPERATOR_OUT;
/* Atop */
case GUAC_COMP_ATOP:
return CAIRO_OPERATOR_ATOP;
/* Over (source/destination reversed) */
case GUAC_COMP_ROVER:
return CAIRO_OPERATOR_DEST_OVER;
/* In (source/destination reversed) */
case GUAC_COMP_RIN:
return CAIRO_OPERATOR_DEST_IN;
/* Out (source/destination reversed) */
case GUAC_COMP_ROUT:
return CAIRO_OPERATOR_DEST_OUT;
/* Atop (source/destination reversed) */
case GUAC_COMP_RATOP:
return CAIRO_OPERATOR_DEST_ATOP;
/* XOR */
case GUAC_COMP_XOR:
return CAIRO_OPERATOR_XOR;
/* Additive */
case GUAC_COMP_PLUS:
return CAIRO_OPERATOR_ADD;
/* If unrecognized, just default to CAIRO_OPERATOR_OVER */
default:
return CAIRO_OPERATOR_OVER;
}
}
guacenc_display* guacenc_display_alloc() { guacenc_display* guacenc_display_alloc() {
return (guacenc_display*) calloc(1, sizeof(guacenc_display)); return (guacenc_display*) calloc(1, sizeof(guacenc_display));
} }

View File

@ -28,6 +28,7 @@
#include "image-stream.h" #include "image-stream.h"
#include "layer.h" #include "layer.h"
#include <guacamole/protocol.h>
#include <guacamole/timestamp.h> #include <guacamole/timestamp.h>
/** /**
@ -204,5 +205,20 @@ int guacenc_display_free_buffer(guacenc_display* display,
guacenc_buffer* guacenc_display_get_related_buffer(guacenc_display* display, guacenc_buffer* guacenc_display_get_related_buffer(guacenc_display* display,
int index); int index);
/**
* Translates the given Guacamole protocol compositing mode (channel mask) to
* the corresponding Cairo composition operator. If no such operator exists,
* CAIRO_OPERATOR_OVER will be returned by default.
*
* @param mask
* The Guacamole protocol compositing mode (channel mask) to translate.
*
* @return
* The cairo_operator_t that corresponds to the given compositing mode
* (channel mask). CAIRO_OPERATOR_OVER will be returned by default if no
* such operator exists.
*/
cairo_operator_t guacenc_display_cairo_operator(guac_composite_mode mask);
#endif #endif

View File

@ -39,14 +39,23 @@ int guacenc_handle_cfill(guacenc_display* display, int argc, char** argv) {
/* Parse arguments */ /* Parse arguments */
int mask = atoi(argv[0]); int mask = atoi(argv[0]);
int index = atoi(argv[1]); int index = atoi(argv[1]);
int r = atoi(argv[2]); double r = atoi(argv[2]) / 255.0;
int g = atoi(argv[3]); double g = atoi(argv[3]) / 255.0;
int b = atoi(argv[4]); double b = atoi(argv[4]) / 255.0;
int a = atoi(argv[5]); double a = atoi(argv[5]) / 255.0;
/* Pull buffer of requested layer/buffer */
guacenc_buffer* buffer = guacenc_display_get_related_buffer(display, index);
if (buffer == NULL)
return 1;
/* Fill with RGBA color */
if (buffer->cairo != NULL) {
cairo_set_operator(buffer->cairo, guacenc_display_cairo_operator(mask));
cairo_set_source_rgba(buffer->cairo, r, g, b, a);
cairo_fill(buffer->cairo);
}
/* STUB */
guacenc_log(GUAC_LOG_DEBUG, "cfill: mask=0x%X layer=%i "
"rgba(%i, %i, %i, %i)", mask, index, r, g, b, a);
return 0; return 0;
} }

View File

@ -21,9 +21,11 @@
*/ */
#include "config.h" #include "config.h"
#include "buffer.h"
#include "display.h" #include "display.h"
#include "log.h" #include "log.h"
#include <cairo/cairo.h>
#include <guacamole/client.h> #include <guacamole/client.h>
#include <stdlib.h> #include <stdlib.h>
@ -43,9 +45,15 @@ int guacenc_handle_rect(guacenc_display* display, int argc, char** argv) {
int width = atoi(argv[3]); int width = atoi(argv[3]);
int height = atoi(argv[4]); int height = atoi(argv[4]);
/* STUB */ /* Pull buffer of requested layer/buffer */
guacenc_log(GUAC_LOG_DEBUG, "rect: layer=%i (%i, %i) %ix%i", guacenc_buffer* buffer = guacenc_display_get_related_buffer(display, index);
index, x, y, width, height); if (buffer == NULL)
return 1;
/* Set path to rectangle */
if (buffer->cairo != NULL)
cairo_rectangle(buffer->cairo, x, y, width, height);
return 0; return 0;
} }