diff --git a/src/common/guac_surface.c b/src/common/guac_surface.c index 123f400d..33290108 100644 --- a/src/common/guac_surface.c +++ b/src/common/guac_surface.c @@ -122,6 +122,10 @@ static void __guac_common_clip_rect(guac_common_surface* surface, int orig_x = rect->x; int orig_y = rect->y; + /* Skip clipping if no clipping rectangle applied */ + if (!surface->clipped) + return; + guac_common_rect_constrain(rect, &surface->clip_rect); /* Update source X/Y if given */ @@ -727,9 +731,9 @@ void guac_common_surface_resize(guac_common_surface* surface, int w, int h) { /* Free old data */ free(old_buffer); - /* Clip dirty rect */ + /* Resize dirty rect to fit new surface dimensions */ if (surface->dirty) { - guac_common_rect_constrain(&surface->dirty_rect, &surface->clip_rect); + __guac_common_bound_rect(surface, &surface->dirty_rect, NULL, NULL); if (surface->dirty_rect.width <= 0 || surface->dirty_rect.height <= 0) surface->dirty = 0; } @@ -923,13 +927,19 @@ void guac_common_surface_clip(guac_common_surface* surface, int x, int y, int w, guac_common_rect clip; + /* Init clipping rectangle if clipping not already applied */ + if (!surface->clipped) { + guac_common_rect_init(&surface->clip_rect, 0, 0, surface->width, surface->height); + surface->clipped = 1; + } + guac_common_rect_init(&clip, x, y, w, h); guac_common_rect_constrain(&surface->clip_rect, &clip); } void guac_common_surface_reset_clip(guac_common_surface* surface) { - guac_common_rect_init(&surface->clip_rect, 0, 0, surface->width, surface->height); + surface->clipped = 0; } /** diff --git a/src/common/guac_surface.h b/src/common/guac_surface.h index 4e43d227..b5ba89f2 100644 --- a/src/common/guac_surface.h +++ b/src/common/guac_surface.h @@ -105,6 +105,12 @@ typedef struct guac_common_surface { */ int realized; + /** + * Whether drawing operations are currently clipped by the clipping + * rectangle. + */ + int clipped; + /** * The clipping rectangle. */