summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2018-03-26 00:29:52 +0200
committerBenjamin Otte <otte@redhat.com>2018-03-26 00:31:12 +0200
commit8c43f22e3e2f1ea7b8acf98470482ae861011830 (patch)
tree8a85f347ef24511f1f25a5ff06baed15f2b12e29
parent438b4b6b5c496716ab5a1f6db90f8c77759c3728 (diff)
downloadgtk+-8c43f22e3e2f1ea7b8acf98470482ae861011830.tar.gz
colorscale: Draw gradient using render nodes
Don't use Cairo when it's not needed.
-rw-r--r--gtk/gtkcolorscale.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/gtk/gtkcolorscale.c b/gtk/gtkcolorscale.c
index aeb9e2e4d2..4f473084a4 100644
--- a/gtk/gtkcolorscale.c
+++ b/gtk/gtkcolorscale.c
@@ -110,6 +110,7 @@ gtk_color_scale_snapshot_trough (GtkColorScale *scale,
else if (scale->priv->type == GTK_COLOR_SCALE_ALPHA)
{
cairo_t *cr;
+ graphene_point_t start, end;
cr = gtk_snapshot_append_cairo (snapshot,
&GRAPHENE_RECT_INIT(x, y, width, height),
@@ -121,6 +122,13 @@ gtk_color_scale_snapshot_trough (GtkColorScale *scale,
{
cairo_translate (cr, width, 0);
cairo_scale (cr, -1, 1);
+ graphene_point_init (&start, x + width, y);
+ graphene_point_init (&end, x, y);
+ }
+ else
+ {
+ graphene_point_init (&start, x, y);
+ graphene_point_init (&end, x + width, y);
}
cairo_pattern_t *pattern;
@@ -137,16 +145,20 @@ gtk_color_scale_snapshot_trough (GtkColorScale *scale,
cairo_mask (cr, pattern);
cairo_pattern_destroy (pattern);
- color = &scale->priv->color;
-
- pattern = cairo_pattern_create_linear (0, 0, width, 0);
- cairo_pattern_add_color_stop_rgba (pattern, 0, color->red, color->green, color->blue, 0);
- cairo_pattern_add_color_stop_rgba (pattern, width, color->red, color->green, color->blue, 1);
- cairo_set_source (cr, pattern);
- cairo_paint (cr);
- cairo_pattern_destroy (pattern);
-
cairo_destroy (cr);
+
+ color = &scale->priv->color;
+
+ gtk_snapshot_append_linear_gradient (snapshot,
+ &GRAPHENE_RECT_INIT(x, y, width, height),
+ &start,
+ &end,
+ (GskColorStop[2]) {
+ { 0, { color->red, color->green, color->blue, 0 } },
+ { 1, { color->red, color->green, color->blue, 1 } },
+ },
+ 2,
+ "ColorAlphaGradient");
}
}