diff --git a/src/common/guac_surface.c b/src/common/guac_surface.c index e19c0a17..e30fbbd0 100644 --- a/src/common/guac_surface.c +++ b/src/common/guac_surface.c @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -64,6 +65,13 @@ */ #define GUAC_SURFACE_NEGLIGIBLE_INCREASE 4 +/** + * If combining an update because it appears to be follow a fill pattern, + * the combined cost must not exceed + * GUAC_SURFACE_FILL_PATTERN_FACTOR * (total uncombined cost). + */ +#define GUAC_SURFACE_FILL_PATTERN_FACTOR 3 + /* Define cairo_format_stride_for_width() if missing */ #ifndef HAVE_CAIRO_FORMAT_STRIDE_FOR_WIDTH #define cairo_format_stride_for_width(format, width) (width*4) @@ -178,8 +186,10 @@ static int __guac_common_should_combine(guac_common_surface* surface, int x, int return 1; /* Combine if we anticipate further updates, as this update follows a common fill pattern */ - if (x == surface->dirty_x && y == surface->dirty_y + surface->dirty_height) - return 1; + if (x == surface->dirty_x && y == surface->dirty_y + surface->dirty_height) { + if (combined_cost <= (dirty_cost + update_cost) * GUAC_SURFACE_FILL_PATTERN_FACTOR) + return 1; + } }