From 02a7ca80f9f9b62deff6c8ba4dc58fee0cebcaa6 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 14 Oct 2008 11:08:43 +0100 Subject: [PATCH] [pattern] Correctly optimize away fractional translations. As is so often the case, reading the commit log gives you fresh insight in the problem - often called confessional debugging... We can simplify the problem by ignoring attr->[xy]_offset, for the time being, and focus on computing the correct matrix. This is comparatively simple as all we need to do is perform the appropriate rounding on the translation vector. --- src/cairo-pattern.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c index 48aa56ba8..d83142a95 100644 --- a/src/cairo-pattern.c +++ b/src/cairo-pattern.c @@ -1757,10 +1757,10 @@ _cairo_pattern_analyze_filter (cairo_surface_pattern_t *pattern, } -static int +static double _pixman_nearest_sample (double d) { - return _cairo_lround (ceil (d - .5)); + return ceil (d - .5); } static cairo_int_status_t @@ -1800,17 +1800,19 @@ _cairo_pattern_acquire_surface_for_surface (cairo_surface_pattern_t *pattern, attr->matrix = pattern->base.matrix; attr->matrix.x0 = 0; attr->matrix.y0 = 0; - if (_cairo_matrix_is_identity (&attr->matrix)) { + if (_cairo_matrix_is_pixel_exact (&attr->matrix)) { /* The rounding here is rather peculiar as it needs to match the * rounding performed on the sample coordinate used by pixman. */ - attr->x_offset = tx = _pixman_nearest_sample (pattern->base.matrix.x0); - attr->y_offset = ty = _pixman_nearest_sample (pattern->base.matrix.y0); + attr->matrix.x0 = _pixman_nearest_sample (pattern->base.matrix.x0); + attr->matrix.y0 = _pixman_nearest_sample (pattern->base.matrix.y0); } else { - attr->matrix = pattern->base.matrix; - attr->x_offset = attr->y_offset = 0; - tx = ty = 0; + attr->matrix.x0 = pattern->base.matrix.x0; + attr->matrix.y0 = pattern->base.matrix.y0; } + + attr->x_offset = attr->y_offset = 0; + tx = ty = 0; } else {