mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-04-28 06:30:46 +02:00
[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:
parent
fb3522f33a
commit
c601f30843
1 changed files with 30 additions and 0 deletions
30
src/cairo.c
30
src/cairo.c
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue