[cairo-commit] src/cairo-pattern.c

Chris Wilson ickle at kemper.freedesktop.org
Fri Jun 11 13:28:27 PDT 2010


 src/cairo-pattern.c |  110 ++++++++--------------------------------------------
 1 file changed, 17 insertions(+), 93 deletions(-)

New commits:
commit a049889c64131b170b66ed8906309f6adee80fa5
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Jun 11 21:26:26 2010 +0100

    pattern: Remove incorrect optimisations from _cairo_pattern_aquire_surface()
    
    Safe reduction of patterns is performed in gstate, so not only are the
    extra checks in _cairo_pattern_acquire_surface redundant there are also
    unsafe. Simply remove them.
    
    Fixes test/radial-gradient-extend [xlib-fallback]

diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index c94e076..56e3b04 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -2341,21 +2341,6 @@ _cairo_pattern_acquire_surface_for_surface (const cairo_surface_pattern_t   *pat
     return status;
 }
 
-static void
-_init_solid_for_color_stop (cairo_solid_pattern_t *solid,
-			    const cairo_color_stop_t *color)
-{
-    cairo_color_t premult;
-
-    /* Color stops aren't premultiplied, so fix that here */
-    _cairo_color_init_rgba (&premult,
-			    color->red,
-			    color->green,
-			    color->blue,
-			    color->alpha);
-    _cairo_pattern_init_solid (solid, &premult);
-}
-
 /**
  * _cairo_pattern_acquire_surface:
  * @pattern: a #cairo_pattern_t
@@ -2387,97 +2372,36 @@ _cairo_pattern_acquire_surface (const cairo_pattern_t	   *pattern,
 				cairo_surface_t		   **surface_out,
 				cairo_surface_attributes_t *attributes)
 {
-    cairo_status_t status;
-
     if (unlikely (pattern->status)) {
 	*surface_out = NULL;
 	return pattern->status;
     }
 
     switch (pattern->type) {
-    case CAIRO_PATTERN_TYPE_SOLID: {
-	cairo_solid_pattern_t *src = (cairo_solid_pattern_t *) pattern;
+    case CAIRO_PATTERN_TYPE_SOLID:
+	return _cairo_pattern_acquire_surface_for_solid ((cairo_solid_pattern_t *) pattern,
+							 dst, x, y, width, height,
+							 surface_out,
+							 attributes);
 
-	status = _cairo_pattern_acquire_surface_for_solid (src, dst,
-							   x, y, width, height,
-							   surface_out,
-							   attributes);
-	} break;
     case CAIRO_PATTERN_TYPE_LINEAR:
-    case CAIRO_PATTERN_TYPE_RADIAL: {
-	cairo_gradient_pattern_t *src = (cairo_gradient_pattern_t *) pattern;
-
-	/* XXX The gradient->solid conversion code should now be redundant. */
-
-	/* fast path for gradients with less than 2 color stops */
-	if (src->n_stops < 2)
-	{
-	    cairo_solid_pattern_t solid;
-
-	    if (src->n_stops) {
-		_init_solid_for_color_stop (&solid, &src->stops->color);
-	    } else {
-		_cairo_pattern_init_solid (&solid,
-					   CAIRO_COLOR_TRANSPARENT);
-	    }
-
-	    status = _cairo_pattern_acquire_surface_for_solid (&solid, dst,
-							       x, y,
-							       width, height,
-							       surface_out,
-							       attributes);
-	}
-	else
-	{
-	    unsigned int i;
-
-	    /* Is the gradient a uniform colour?
-	     * Happens more often than you would believe.
-	     */
-	    for (i = 1; i < src->n_stops; i++) {
-		if (! _cairo_color_stop_equal (&src->stops[0].color,
-					       &src->stops[i].color))
-		{
-		    break;
-		}
-	    }
-	    if (i == src->n_stops) {
-		cairo_solid_pattern_t solid;
+    case CAIRO_PATTERN_TYPE_RADIAL:
+	return _cairo_pattern_acquire_surface_for_gradient ((cairo_gradient_pattern_t *) pattern,
+							    dst, x, y, width, height,
+							    surface_out,
+							    attributes);
 
-		_init_solid_for_color_stop (&solid, &src->stops->color);
+    case CAIRO_PATTERN_TYPE_SURFACE:
+	return _cairo_pattern_acquire_surface_for_surface ((cairo_surface_pattern_t *) pattern,
+							   dst, x, y, width, height,
+							   flags,
+							   surface_out,
+							   attributes);
 
-		status =
-		    _cairo_pattern_acquire_surface_for_solid (&solid, dst,
-							      x, y,
-							      width, height,
-							      surface_out,
-							      attributes);
-	    } else {
-		status =
-		    _cairo_pattern_acquire_surface_for_gradient (src, dst,
-								 x, y,
-								 width, height,
-								 surface_out,
-								 attributes);
-	    }
-	}
-    } break;
-    case CAIRO_PATTERN_TYPE_SURFACE: {
-	cairo_surface_pattern_t *src = (cairo_surface_pattern_t *) pattern;
-
-	status = _cairo_pattern_acquire_surface_for_surface (src, dst,
-							     x, y,
-							     width, height,
-							     flags,
-							     surface_out,
-							     attributes);
-    } break;
     default:
 	ASSERT_NOT_REACHED;
-	status = _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH);
+	return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH);
     }
-
-    return status;
 }
 
 /**


More information about the cairo-commit mailing list