[gtk+/wip/matthiasc/icon-texture-cache: 2/2] icon helper: Use cached textures



commit e5813b34a6ecb783ef655c11e24d7b5019254f58
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Oct 23 07:53:09 2017 +0200

    icon helper: Use cached textures
    
    Use a cached texture for themed icons if we can.
    Currently, we only do this for non-symbolic icons.

 gtk/gtkiconhelper.c |   61 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkiconhelper.c b/gtk/gtkiconhelper.c
index 484c022..2b59206 100644
--- a/gtk/gtkiconhelper.c
+++ b/gtk/gtkiconhelper.c
@@ -458,6 +458,63 @@ gtk_icon_helper_ensure_surface (GtkIconHelper *self)
   self->rendered_surface = gtk_icon_helper_load_surface (self, scale);
 }
 
+static GskTexture *
+find_cached_texture (GtkIconHelper *self)
+{
+  GtkIconTheme *icon_theme;
+  int width, height;
+  GtkIconLookupFlags flags;
+  cairo_surface_t *surface;
+  GtkCssStyle *style;
+  GtkTextDirection dir;
+  int scale;
+  GIcon *gicon;
+  GtkIconInfo *info;
+  GskTexture *texture;
+
+  style = gtk_css_node_get_style (self->node);
+  dir = gtk_widget_get_direction (self->owner);
+  scale = gtk_widget_get_scale_factor (self->owner);
+
+  icon_theme = gtk_css_icon_theme_value_get_icon_theme (gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_ICON_THEME));
+  flags = get_icon_lookup_flags (self, style, dir);
+  ensure_icon_size (self, &width, &height);
+
+  switch (gtk_image_definition_get_storage_type (self->def))
+    {
+    case GTK_IMAGE_GICON:
+      gicon = g_object_ref (gtk_image_definition_get_gicon (self->def));
+      break;
+    case GTK_IMAGE_ICON_NAME:
+      if (self->use_fallback)
+        gicon = g_themed_icon_new_with_default_fallbacks (gtk_image_definition_get_icon_name (self->def));
+      else
+        gicon = g_themed_icon_new (gtk_image_definition_get_icon_name (self->def));
+      break;
+    default:
+      return NULL;
+    }
+
+  info = gtk_icon_theme_lookup_by_gicon_for_scale (icon_theme, gicon, MIN (width, height), scale, flags);
+  g_object_unref (gicon);
+
+  if (!info)
+    return NULL;
+
+  if (gtk_icon_info_is_symbolic (info))
+    {
+      // FIXME
+      g_object_unref (info);
+      return NULL;
+    }
+
+  texture = gtk_icon_info_load_texture (info);
+
+  g_object_unref (info);
+
+  return texture;
+}
+
 static void
 gtk_icon_helper_ensure_texture (GtkIconHelper *self)
 {
@@ -467,6 +524,10 @@ gtk_icon_helper_ensure_texture (GtkIconHelper *self)
   if (self->texture)
     return;
 
+  self->texture = find_cached_texture (self);
+  if (self->texture)
+    return;
+
   gtk_icon_helper_ensure_surface (self);
   if (self->rendered_surface == NULL)
     return;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]