diff options
author | Timm Bäder <mail@baedert.org> | 2019-09-25 17:07:45 +0200 |
---|---|---|
committer | Timm Bäder <mail@baedert.org> | 2019-09-25 17:51:52 +0200 |
commit | 78a376aa7f42198911dbe78c8889df8ab5f81455 (patch) | |
tree | 6d0783cf4eb26269e84d38af888724840bf33526 /gtk/gtksnapshot.c | |
parent | 43f2b47fc9196aca459bd3ff1d73f211718a8f7c (diff) | |
download | gtk+-78a376aa7f42198911dbe78c8889df8ab5f81455.tar.gz |
snapshot: Try to avoid some linear gradient nodes
Diffstat (limited to 'gtk/gtksnapshot.c')
-rw-r--r-- | gtk/gtksnapshot.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c index 46a8cecfdc..ab38d09f3c 100644 --- a/gtk/gtksnapshot.c +++ b/gtk/gtksnapshot.c @@ -1745,6 +1745,9 @@ gtk_snapshot_append_linear_gradient (GtkSnapshot *snapshot, graphene_point_t real_start_point; graphene_point_t real_end_point; float scale_x, scale_y, dx, dy; + const GdkRGBA *first_color; + gboolean need_gradient = FALSE; + int i; g_return_if_fail (snapshot != NULL); g_return_if_fail (start_point != NULL); @@ -1759,11 +1762,24 @@ gtk_snapshot_append_linear_gradient (GtkSnapshot *snapshot, real_end_point.x = scale_x * end_point->x + dx; real_end_point.y = scale_y * end_point->y + dy; - node = gsk_linear_gradient_node_new (&real_bounds, - &real_start_point, - &real_end_point, - stops, - n_stops); + first_color = &stops[0].color; + for (i = 0; i < n_stops; i ++) + { + if (!gdk_rgba_equal (first_color, &stops[i].color)) + { + need_gradient = TRUE; + break; + } + } + + if (need_gradient) + node = gsk_linear_gradient_node_new (&real_bounds, + &real_start_point, + &real_end_point, + stops, + n_stops); + else + node = gsk_color_node_new (first_color, &real_bounds); gtk_snapshot_append_node_internal (snapshot, node); } |