GUAC-236: Flatten and render all layers upon sync.
This commit is contained in:
parent
79181567e5
commit
a24152df02
@ -30,6 +30,7 @@
|
|||||||
#include <guacamole/protocol.h>
|
#include <guacamole/protocol.h>
|
||||||
#include <guacamole/timestamp.h>
|
#include <guacamole/timestamp.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -93,20 +94,9 @@ int guacenc_display_sync(guacenc_display* display, guac_timestamp timestamp) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get buffer for display frame rendering */
|
|
||||||
guacenc_buffer* frame = display->frame;
|
|
||||||
|
|
||||||
/* Update timestamp of display */
|
/* Update timestamp of display */
|
||||||
display->last_sync = timestamp;
|
display->last_sync = timestamp;
|
||||||
|
|
||||||
/* Ensure frame is the same size as the default layer */
|
|
||||||
guacenc_buffer* def_layer = guacenc_display_get_related_buffer(display, 0);
|
|
||||||
guacenc_buffer_resize(frame, def_layer->width, def_layer->height);
|
|
||||||
|
|
||||||
/* Render all layers to frame */
|
|
||||||
cairo_t* cairo = frame->cairo;
|
|
||||||
if (cairo != NULL) {
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
guacenc_layer* render_order[GUACENC_DISPLAY_MAX_LAYERS];
|
guacenc_layer* render_order[GUACENC_DISPLAY_MAX_LAYERS];
|
||||||
|
|
||||||
@ -118,6 +108,23 @@ int guacenc_display_sync(guacenc_display* display, guac_timestamp timestamp) {
|
|||||||
qsort(render_order, GUACENC_DISPLAY_MAX_LAYERS, sizeof(guacenc_layer*),
|
qsort(render_order, GUACENC_DISPLAY_MAX_LAYERS, sizeof(guacenc_layer*),
|
||||||
guacenc_display_layer_comparator);
|
guacenc_display_layer_comparator);
|
||||||
|
|
||||||
|
/* Reset layer frame buffers */
|
||||||
|
for (i = 0; i < GUACENC_DISPLAY_MAX_LAYERS; i++) {
|
||||||
|
|
||||||
|
/* Pull current layer, ignoring unallocated layers */
|
||||||
|
guacenc_layer* layer = render_order[i];
|
||||||
|
if (layer == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* Get source buffer and destination frame buffer */
|
||||||
|
guacenc_buffer* buffer = layer->buffer;
|
||||||
|
guacenc_buffer* frame = layer->frame;
|
||||||
|
|
||||||
|
/* Reset frame contents */
|
||||||
|
guacenc_buffer_copy(frame, buffer);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* Render each layer, in order */
|
/* Render each layer, in order */
|
||||||
for (i = 0; i < GUACENC_DISPLAY_MAX_LAYERS; i++) {
|
for (i = 0; i < GUACENC_DISPLAY_MAX_LAYERS; i++) {
|
||||||
|
|
||||||
@ -130,33 +137,48 @@ int guacenc_display_sync(guacenc_display* display, guac_timestamp timestamp) {
|
|||||||
if (layer->opacity == 0)
|
if (layer->opacity == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Pull underlying buffer */
|
/* Ignore layers without a parent */
|
||||||
guacenc_buffer* buffer = layer->buffer;
|
int parent_index = layer->parent_index;
|
||||||
|
if (parent_index == GUACENC_LAYER_NO_PARENT)
|
||||||
/* Ignore layers with empty buffers */
|
|
||||||
if (buffer->surface == NULL)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* TODO: Determine actual location relative to parent layer */
|
/* Retrieve parent layer, ignoring layers with invalid parents */
|
||||||
int x = layer->x;
|
guacenc_layer* parent = guacenc_display_get_layer(display, parent_index);
|
||||||
int y = layer->y;
|
if (parent == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* Get source and destination frame buffer */
|
||||||
|
guacenc_buffer* src = layer->frame;
|
||||||
|
guacenc_buffer* dst = parent->frame;
|
||||||
|
|
||||||
|
/* Ignore layers with empty buffers */
|
||||||
|
cairo_surface_t* surface = src->surface;
|
||||||
|
if (surface == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* Ignore if parent has no pixels */
|
||||||
|
cairo_t* cairo = dst->cairo;
|
||||||
|
if (cairo == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
/* Render buffer to layer */
|
/* Render buffer to layer */
|
||||||
cairo_reset_clip(cairo);
|
cairo_reset_clip(cairo);
|
||||||
cairo_rectangle(cairo, x, y, buffer->width, buffer->height);
|
cairo_rectangle(cairo, layer->x, layer->y, src->width, src->height);
|
||||||
cairo_clip(cairo);
|
cairo_clip(cairo);
|
||||||
|
|
||||||
cairo_set_source_surface(cairo, buffer->surface, x, y);
|
cairo_set_source_surface(cairo, surface, layer->x, layer->y);
|
||||||
cairo_paint_with_alpha(cairo, layer->opacity / 255.0);
|
cairo_paint_with_alpha(cairo, layer->opacity / 255.0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/* Retrieve default layer (guaranteed to not be NULL) */
|
||||||
|
guacenc_layer* def_layer = guacenc_display_get_layer(display, 0);
|
||||||
|
assert(def_layer != NULL);
|
||||||
|
|
||||||
/* STUB: Write frame as PNG */
|
/* STUB: Write frame as PNG */
|
||||||
char filename[256];
|
char filename[256];
|
||||||
sprintf(filename, "frame-%" PRId64 ".png", timestamp);
|
sprintf(filename, "frame-%" PRId64 ".png", timestamp);
|
||||||
cairo_surface_t* surface = frame->surface;
|
cairo_surface_t* surface = def_layer->frame->surface;
|
||||||
if (surface != NULL)
|
if (surface != NULL)
|
||||||
cairo_surface_write_to_png(surface, filename);
|
cairo_surface_write_to_png(surface, filename);
|
||||||
|
|
||||||
@ -424,16 +446,7 @@ cairo_operator_t guacenc_display_cairo_operator(guac_composite_mode mask) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
guacenc_display* guacenc_display_alloc() {
|
guacenc_display* guacenc_display_alloc() {
|
||||||
|
return (guacenc_display*) calloc(1, sizeof(guacenc_display));
|
||||||
/* Allocate display */
|
|
||||||
guacenc_display* display =
|
|
||||||
(guacenc_display*) calloc(1, sizeof(guacenc_display));
|
|
||||||
|
|
||||||
/* Allocate buffer for frame rendering */
|
|
||||||
display->frame = guacenc_buffer_alloc();
|
|
||||||
|
|
||||||
return display;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int guacenc_display_free(guacenc_display* display) {
|
int guacenc_display_free(guacenc_display* display) {
|
||||||
@ -444,9 +457,6 @@ int guacenc_display_free(guacenc_display* display) {
|
|||||||
if (display == NULL)
|
if (display == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Free internal frame buffer */
|
|
||||||
guacenc_buffer_free(display->frame);
|
|
||||||
|
|
||||||
/* Free all buffers */
|
/* Free all buffers */
|
||||||
for (i = 0; i < GUACENC_DISPLAY_MAX_BUFFERS; i++)
|
for (i = 0; i < GUACENC_DISPLAY_MAX_BUFFERS; i++)
|
||||||
guacenc_buffer_free(display->buffers[i]);
|
guacenc_buffer_free(display->buffers[i]);
|
||||||
|
@ -84,12 +84,6 @@ typedef struct guacenc_display {
|
|||||||
*/
|
*/
|
||||||
guac_timestamp last_sync;
|
guac_timestamp last_sync;
|
||||||
|
|
||||||
/**
|
|
||||||
* The internal buffer used by the display to record the previous frame
|
|
||||||
* and to render additional frames.
|
|
||||||
*/
|
|
||||||
guacenc_buffer* frame;
|
|
||||||
|
|
||||||
} guacenc_display;
|
} guacenc_display;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user