[cairo] Early return if we attempt to set the same colour.

Profiling a silly video renderer that called set-source; rectangle; fill;
for each pixel, we can shave 5% off the cairo overhead by introducing an
early return if we attempt to reset the current colour.
This commit is contained in:
Chris Wilson 2009-01-01 16:55:08 +00:00
parent fb3522f33a
commit c601f30843

View file

@ -633,6 +633,30 @@ cairo_set_operator (cairo_t *cr, cairo_operator_t op)
}
slim_hidden_def (cairo_set_operator);
static cairo_bool_t
_current_source_matches_solid (cairo_t *cr,
double red,
double green,
double blue,
double alpha)
{
const cairo_pattern_t *current;
cairo_color_t color;
current = cr->gstate->source;
if (current->type != CAIRO_PATTERN_TYPE_SOLID)
return FALSE;
_cairo_restrict_value (&red, 0.0, 1.0);
_cairo_restrict_value (&green, 0.0, 1.0);
_cairo_restrict_value (&blue, 0.0, 1.0);
_cairo_restrict_value (&alpha, 0.0, 1.0);
_cairo_color_init_rgba (&color, red, green, blue, alpha);
return _cairo_color_equal (&color,
&((cairo_solid_pattern_t *) current)->color);
}
/**
* cairo_set_source_rgb
* @cr: a cairo context
@ -659,6 +683,9 @@ cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue)
if (cr->status)
return;
if (_current_source_matches_solid (cr, red, green, blue, 1.))
return;
/* push the current pattern to the freed lists */
cairo_set_source (cr, (cairo_pattern_t *) &_cairo_pattern_black);
@ -696,6 +723,9 @@ cairo_set_source_rgba (cairo_t *cr,
if (cr->status)
return;
if (_current_source_matches_solid (cr, red, green, blue, alpha))
return;
/* push the current pattern to the freed lists */
cairo_set_source (cr, (cairo_pattern_t *) &_cairo_pattern_black);