cssimagelinear: Don't call get_start_end if !repeating

This makes it clear that the !repeating case is easier.
This commit is contained in:
Timm Bäder 2019-12-30 09:51:49 +01:00
parent 59111d100f
commit c427c2b22a

View File

@ -31,7 +31,7 @@
G_DEFINE_TYPE (GtkCssImageLinear, _gtk_css_image_linear, GTK_TYPE_CSS_IMAGE)
static void
gtk_css_image_linear_get_start_end (GtkCssImageLinear *linear,
gtk_css_image_linear_get_repeating_start_end (GtkCssImageLinear *linear,
double length,
double *start,
double *end)
@ -40,8 +40,8 @@ gtk_css_image_linear_get_start_end (GtkCssImageLinear *linear,
double pos;
guint i;
if (linear->repeating)
{
g_assert (linear->repeating);
stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, 0);
if (stop->offset == NULL)
*start = 0;
@ -64,12 +64,6 @@ gtk_css_image_linear_get_start_end (GtkCssImageLinear *linear,
if (stop->offset == NULL)
*end = MAX (*end, 1.0);
}
else
{
*start = 0;
*end = 1;
}
}
static void
@ -188,19 +182,28 @@ gtk_css_image_linear_snapshot (GtkCssImage *image,
&x, &y,
&length);
gtk_css_image_linear_get_start_end (linear, length, &start, &end);
if (linear->repeating)
{
gtk_css_image_linear_get_repeating_start_end (linear, length, &start, &end);
if (start == end)
{
/* repeating gradients with all color stops sharing the same offset
* get the color of the last color stop */
GtkCssImageLinearColorStop *stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, linear->stops->len - 1);
GtkCssImageLinearColorStop *stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop,
linear->stops->len - 1);
gtk_snapshot_append_color (snapshot,
_gtk_css_rgba_value_get_rgba (stop->color),
&GRAPHENE_RECT_INIT (0, 0, width, height));
return;
}
}
else
{
start = 0;
end = 1;
}
offset = start;
last = -1;