[gtk/matthiasc/for-master] css: Load icons async



commit 596509be209ba96665ec3a8e746b9efb46ad8781
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jan 22 18:31:05 2020 -0500

    css: Load icons async
    
    We don't want to block and cause the first frame snapshot
    to take much too long. Icons will show up as they become
    available.

 gtk/gtkcssimageicontheme.c | 40 ++++++++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkcssimageicontheme.c b/gtk/gtkcssimageicontheme.c
index c2a21c41b9..76555c2d6c 100644
--- a/gtk/gtkcssimageicontheme.c
+++ b/gtk/gtkcssimageicontheme.c
@@ -38,6 +38,24 @@ gtk_css_image_icon_theme_get_aspect_ratio (GtkCssImage *image)
   return 1.0;
 }
 
+static void
+icon_loaded (GObject      *source,
+             GAsyncResult *result,
+             gpointer      data)
+{
+  GtkIconInfo *icon_info = GTK_ICON_INFO (source);
+  GtkCssImageIconTheme *icon_theme = data;
+
+  g_clear_object (&icon_theme->cached_texture);
+
+  icon_theme->cached_texture = GDK_TEXTURE (gtk_icon_info_load_icon_finish (icon_info, result, NULL));
+  
+  icon_theme->cached_symbolic = gtk_icon_info_is_symbolic (icon_info);
+  icon_theme->cached_size = gdk_texture_get_width (icon_theme->cached_texture);
+
+  g_object_unref (icon_theme);
+}
+
 static void
 gtk_css_image_icon_theme_snapshot (GtkCssImage *image,
                                    GtkSnapshot *snapshot,
@@ -54,13 +72,7 @@ gtk_css_image_icon_theme_snapshot (GtkCssImage *image,
   if (size <= 0)
     return;
 
-  if (size == icon_theme->cached_size &&
-      icon_theme->cached_texture != NULL)
-    {
-      texture = icon_theme->cached_texture;
-      symbolic = icon_theme->cached_symbolic;
-    }
-  else
+  if (size != icon_theme->cached_size || icon_theme->cached_texture != NULL)
     {
       GtkIconInfo *icon_info;
 
@@ -77,18 +89,14 @@ gtk_css_image_icon_theme_snapshot (GtkCssImage *image,
 
       g_assert (icon_info != NULL);
 
-      symbolic = gtk_icon_info_is_symbolic (icon_info);
-      texture = GDK_TEXTURE (gtk_icon_info_load_icon (icon_info, NULL));
+      gtk_icon_info_load_icon_async (icon_info, NULL, icon_loaded, g_object_ref (icon_theme));
 
-      g_clear_object (&icon_theme->cached_texture);
-
-      icon_theme->cached_size = size;
-      icon_theme->cached_texture = texture;
-      icon_theme->cached_symbolic = symbolic;
-
-      g_object_unref (icon_info);
+      return;
     }
 
+  texture = icon_theme->cached_texture;
+  symbolic = icon_theme->cached_symbolic;
+
   texture_width = (double) gdk_texture_get_width (texture) / icon_theme->scale;
   texture_height = (double) gdk_texture_get_height (texture) / icon_theme->scale;
 


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