From 021aaef824283644a02938e04d4c1958cdb0a389 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 5 Feb 2020 09:49:23 +0100 Subject: [PATCH] GtkIconPaintable: Always recolor when snapshotting. It never makes sense to paint a texture that needs recoloring. If you call the regular snapshot on a symbolic texture we just use the default recoloring colors. To support this we also change gtk_css_style_snapshot_icon_paintable() to call gtk_icon_paintable_snapshot_with_colors() for IconPaintables so that we get the correct colors, and we make it not emit the color matrix. Since we now rely on the icon to do the recoloring we also drop the recolor argument in gtk_icon_paintable_snapshot_with_colors() as its not needed anymore. --- gtk/gtkiconhelper.c | 12 ++++------- gtk/gtkicontheme.c | 22 +++---------------- gtk/gtkrender.c | 3 +-- gtk/gtkrendericon.c | 43 ++++++++++++++------------------------ gtk/gtkrendericonprivate.h | 3 +-- 5 files changed, 25 insertions(+), 58 deletions(-) diff --git a/gtk/gtkiconhelper.c b/gtk/gtkiconhelper.c index 21e6def09a..0c8e960d53 100644 --- a/gtk/gtkiconhelper.c +++ b/gtk/gtkiconhelper.c @@ -223,8 +223,7 @@ gtk_icon_helper_paintable_snapshot (GdkPaintable *paintable, gtk_css_style_snapshot_icon_paintable (style, snapshot, self->paintable, - w, h, - self->texture_is_symbolic); + w, h); gtk_snapshot_restore (snapshot); } else @@ -232,8 +231,7 @@ gtk_icon_helper_paintable_snapshot (GdkPaintable *paintable, gtk_css_style_snapshot_icon_paintable (style, snapshot, self->paintable, - w, h, - self->texture_is_symbolic); + w, h); } @@ -280,8 +278,7 @@ gtk_icon_helper_paintable_snapshot (GdkPaintable *paintable, gtk_css_style_snapshot_icon_paintable (style, snapshot, self->paintable, - w, h, - self->texture_is_symbolic); + w, h); gtk_snapshot_restore (snapshot); } else @@ -289,8 +286,7 @@ gtk_icon_helper_paintable_snapshot (GdkPaintable *paintable, gtk_css_style_snapshot_icon_paintable (style, snapshot, self->paintable, - w, h, - self->texture_is_symbolic); + w, h); } } break; diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c index 4d2ac88497..9cf4b29068 100644 --- a/gtk/gtkicontheme.c +++ b/gtk/gtkicontheme.c @@ -3598,25 +3598,9 @@ icon_paintable_snapshot (GdkPaintable *paintable, double height) { GtkIconPaintable *icon = GTK_ICON_PAINTABLE (paintable); - GdkTexture *texture; - texture = gtk_icon_paintable_download_texture (icon, NULL); - if (texture) - { - if (icon->desired_scale != 1) - { - gtk_snapshot_save (snapshot); - gtk_snapshot_scale (snapshot, 1.0 / icon->desired_scale, 1.0 / icon->desired_scale); - } - - gtk_snapshot_append_texture (snapshot, texture, - &GRAPHENE_RECT_INIT (0, 0, width * icon->desired_scale, height * icon->desired_scale)); - - if (icon->desired_scale != 1) - gtk_snapshot_restore (snapshot); - - g_object_unref (texture); - } + gtk_icon_paintable_snapshot_with_colors (icon, snapshot, width, height, + NULL, NULL, NULL, NULL); } /** @@ -3754,7 +3738,7 @@ gtk_icon_paintable_new_for_file (GFile *file, static GtkIconPaintable * gtk_icon_paintable_new_for_pixbuf (GtkIconTheme *icon_theme, - GdkPixbuf *pixbuf) + GdkPixbuf *pixbuf) { GtkIconPaintable *icon; gint width, height, max; diff --git a/gtk/gtkrender.c b/gtk/gtkrender.c index 840aaa0742..c11e377aaf 100644 --- a/gtk/gtkrender.c +++ b/gtk/gtkrender.c @@ -519,8 +519,7 @@ gtk_render_icon (GtkStyleContext *context, snapshot, GDK_PAINTABLE (texture), gdk_texture_get_width (texture), - gdk_texture_get_height (texture), - FALSE); + gdk_texture_get_height (texture)); node = gtk_snapshot_free_to_node (snapshot); if (node == NULL) return; diff --git a/gtk/gtkrendericon.c b/gtk/gtkrendericon.c index 7ba2fa83e3..ddb889642c 100644 --- a/gtk/gtkrendericon.c +++ b/gtk/gtkrendericon.c @@ -93,11 +93,12 @@ gtk_css_style_snapshot_icon_paintable (GtkCssStyle *style, GtkSnapshot *snapshot, GdkPaintable *paintable, double width, - double height, - gboolean recolor) + double height) { GskTransform *transform; gboolean has_shadow; + gboolean is_icon_paintable; + GdkRGBA fg, sc, wc, ec; g_return_if_fail (GTK_IS_CSS_STYLE (style)); g_return_if_fail (snapshot != NULL); @@ -111,31 +112,19 @@ gtk_css_style_snapshot_icon_paintable (GtkCssStyle *style, has_shadow = gtk_css_shadow_value_push_snapshot (style->icon->icon_shadow, snapshot); - if (recolor) - { - graphene_matrix_t color_matrix; - graphene_vec4_t color_offset; - GdkRGBA fg, sc, wc, ec; + is_icon_paintable = GTK_IS_ICON_PAINTABLE (paintable); + if (is_icon_paintable) + gtk_icon_theme_lookup_symbolic_colors (style, &fg, &sc, &wc, &ec); - gtk_icon_theme_lookup_symbolic_colors (style, &fg, &sc, &wc, &ec); - - if (fg.alpha == 0.0f) - goto transparent; - - graphene_matrix_init_from_float (&color_matrix, (float[16]) { - sc.red - fg.red, sc.green - fg.green, sc.blue - fg.blue, 0, - wc.red - fg.red, wc.green - fg.green, wc.blue - fg.blue, 0, - ec.red - fg.red, ec.green - fg.green, ec.blue - fg.blue, 0, - 0, 0, 0, fg.alpha - }); - graphene_vec4_init (&color_offset, fg.red, fg.green, fg.blue, 0); - - gtk_snapshot_push_color_matrix (snapshot, &color_matrix, &color_offset); - } + if (fg.alpha == 0.0f) + goto transparent; if (transform == NULL) { - gdk_paintable_snapshot (paintable, snapshot, width, height); + if (is_icon_paintable) + gtk_icon_paintable_snapshot_with_colors (GTK_ICON_PAINTABLE (paintable), snapshot, width, height, &fg, &sc, &wc, &ec); + else + gdk_paintable_snapshot (paintable, snapshot, width, height); } else { @@ -146,14 +135,14 @@ gtk_css_style_snapshot_icon_paintable (GtkCssStyle *style, gtk_snapshot_transform (snapshot, transform); gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (- width / 2.0, - height / 2.0)); - gdk_paintable_snapshot (paintable, snapshot, width, height); + if (is_icon_paintable) + gtk_icon_paintable_snapshot_with_colors (GTK_ICON_PAINTABLE (paintable), snapshot, width, height, &fg, &sc, &wc, &ec); + else + gdk_paintable_snapshot (paintable, snapshot, width, height); gtk_snapshot_restore (snapshot); } - if (recolor) - gtk_snapshot_pop (snapshot); - transparent: if (has_shadow) gtk_snapshot_pop (snapshot); diff --git a/gtk/gtkrendericonprivate.h b/gtk/gtkrendericonprivate.h index c37be85618..a327af5099 100644 --- a/gtk/gtkrendericonprivate.h +++ b/gtk/gtkrendericonprivate.h @@ -38,8 +38,7 @@ void gtk_css_style_snapshot_icon_paintable (GtkCssStyle *style, GtkSnapshot *snapshot, GdkPaintable *paintable, double width, - double height, - gboolean recolor); + double height); void gtk_css_style_render_icon_get_extents (GtkCssStyle *style, GdkRectangle *extents,