From 378b1e73d9f27e9b54ea01b10e588b361848d0cd Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 21 Sep 2009 03:10:53 +0100 Subject: [fallback] Special case single composite rectangle Avoid the overhead of region-from-traps extraction for the very frequent case of using a single (possibly clipped) rectangle with a pattern source. --- src/cairo-surface-fallback.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/cairo-surface-fallback.c b/src/cairo-surface-fallback.c index 35befa53..77ae0ede 100644 --- a/src/cairo-surface-fallback.c +++ b/src/cairo-surface-fallback.c @@ -715,6 +715,44 @@ _fill_rectangles (cairo_surface_t *dst, return status; } +/* fast-path for very common composite of a single rectangle */ +static cairo_status_t +_composite_rectangle (cairo_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *src, + cairo_traps_t *traps, + cairo_clip_t *clip) +{ + cairo_rectangle_int_t rect; + + if (clip != NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (traps->num_traps > 1 || ! traps->is_rectilinear || ! traps->maybe_region) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (! _cairo_fixed_is_integer (traps->traps[0].top) || + ! _cairo_fixed_is_integer (traps->traps[0].bottom) || + ! _cairo_fixed_is_integer (traps->traps[0].left.p1.x) || + ! _cairo_fixed_is_integer (traps->traps[0].right.p1.x)) + { + traps->maybe_region = FALSE; + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + rect.x = _cairo_fixed_integer_part (traps->traps[0].left.p1.x); + rect.y = _cairo_fixed_integer_part (traps->traps[0].top); + rect.width = _cairo_fixed_integer_part (traps->traps[0].right.p1.x) - rect.x; + rect.height = _cairo_fixed_integer_part (traps->traps[0].bottom) - rect.y; + + return _cairo_surface_composite (op, src, NULL, dst, + rect.x, rect.y, + 0, 0, + rect.x, rect.y, + rect.width, rect.height, + NULL); +} + /* Warning: This call modifies the coordinates of traps */ static cairo_status_t _clip_and_composite_trapezoids (const cairo_pattern_t *src, @@ -756,6 +794,10 @@ _clip_and_composite_trapezoids (const cairo_pattern_t *src, if (status != CAIRO_INT_STATUS_UNSUPPORTED) return status; + status = _composite_rectangle (dst, op, src, traps, clip); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + status = _cairo_traps_extract_region (traps, &trap_region); if (unlikely (_cairo_status_is_error (status))) return status; -- cgit v1.2.3