mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-01-06 07:20:16 +01:00
[pattern] Use a solid pattern for a uniform gradient.
If each color stop in a gradient is identical, replace the gradient surface with a simple solid surface. As seen in the wild.
This commit is contained in:
parent
25a4677200
commit
2d790daa95
1 changed files with 39 additions and 15 deletions
|
|
@ -2073,19 +2073,15 @@ _cairo_pattern_acquire_surface (const cairo_pattern_t *pattern,
|
||||||
|
|
||||||
if (src->n_stops)
|
if (src->n_stops)
|
||||||
{
|
{
|
||||||
cairo_color_t color;
|
_cairo_pattern_init_solid (&solid,
|
||||||
|
&src->stops->color,
|
||||||
_cairo_color_init_rgba (&color,
|
CAIRO_CONTENT_COLOR_ALPHA);
|
||||||
src->stops->color.red,
|
|
||||||
src->stops->color.green,
|
|
||||||
src->stops->color.blue,
|
|
||||||
src->stops->color.alpha);
|
|
||||||
|
|
||||||
_cairo_pattern_init_solid (&solid, &color, CAIRO_CONTENT_COLOR_ALPHA);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_cairo_pattern_init_solid (&solid, CAIRO_COLOR_TRANSPARENT, CAIRO_CONTENT_ALPHA);
|
_cairo_pattern_init_solid (&solid,
|
||||||
|
CAIRO_COLOR_TRANSPARENT,
|
||||||
|
CAIRO_CONTENT_ALPHA);
|
||||||
}
|
}
|
||||||
|
|
||||||
status = _cairo_pattern_acquire_surface_for_solid (&solid, dst,
|
status = _cairo_pattern_acquire_surface_for_solid (&solid, dst,
|
||||||
|
|
@ -2096,11 +2092,39 @@ _cairo_pattern_acquire_surface (const cairo_pattern_t *pattern,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
status = _cairo_pattern_acquire_surface_for_gradient (src, dst,
|
unsigned int i;
|
||||||
x, y,
|
|
||||||
width, height,
|
/* Is the gradient a uniform colour?
|
||||||
surface_out,
|
* Happens more often than you would believe.
|
||||||
attributes);
|
*/
|
||||||
|
for (i = 1; i < src->n_stops; i++) {
|
||||||
|
if (! _cairo_color_equal (&src->stops[0].color,
|
||||||
|
&src->stops[i].color))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i == src->n_stops) {
|
||||||
|
cairo_solid_pattern_t solid;
|
||||||
|
|
||||||
|
_cairo_pattern_init_solid (&solid,
|
||||||
|
&src->stops->color,
|
||||||
|
CAIRO_CONTENT_COLOR_ALPHA);
|
||||||
|
|
||||||
|
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;
|
} break;
|
||||||
case CAIRO_PATTERN_TYPE_SURFACE: {
|
case CAIRO_PATTERN_TYPE_SURFACE: {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue