GUAC-236: Add function for copying buffer state.

This commit is contained in:
Michael Jumper 2016-02-28 14:54:44 -08:00
parent 1d4e6ce924
commit 80b3d51a49
2 changed files with 48 additions and 0 deletions

View File

@ -25,6 +25,7 @@
#include <cairo/cairo.h>
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
@ -141,3 +142,33 @@ int guacenc_buffer_fit(guacenc_buffer* buffer, int x, int y) {
}
int guacenc_buffer_copy(guacenc_buffer* dst, guacenc_buffer* src) {
/* Resize destination to exactly fit source */
if (guacenc_buffer_resize(dst, src->width, src->height))
return 1;
/* Copy surface contents identically */
if (src->surface != NULL) {
/* Destination must be non-NULL as its size is that of the source */
assert(dst->cairo != NULL);
/* Reset state of destination */
cairo_t* cairo = dst->cairo;
cairo_reset_clip(cairo);
/* Overwrite destination with contents of source */
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
cairo_set_source_surface(cairo, src->surface, 0, 0);
cairo_paint(cairo);
/* Reset operator of destination to default */
cairo_set_operator(cairo, CAIRO_OPERATOR_OVER);
}
return 0;
}

View File

@ -136,5 +136,22 @@ int guacenc_buffer_resize(guacenc_buffer* buffer, int width, int height);
*/
int guacenc_buffer_fit(guacenc_buffer* buffer, int x, int y);
/**
* Copies the entire contents of the given source buffer to the destination
* buffer, ignoring the current contents of the destination. The destination
* buffer's contents are entirely replaced.
*
* @param dst
* The destination buffer whose contents should be replaced.
*
* @param src
* The source buffer whose contents should replace those of the destination
* buffer.
*
* @return
* Zero if the copy operation was successful, non-zero on failure.
*/
int guacenc_buffer_copy(guacenc_buffer* dst, guacenc_buffer* src);
#endif