diff options
author | Alexander Larsson <alexl@redhat.com> | 2020-01-29 18:10:13 +0100 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2020-01-30 10:53:43 +0100 |
commit | d1c6d78ebb1de39d448b0e8afab13ad495bcadb6 (patch) | |
tree | abd5cd315faadfac12e042188677f601dbbf331f /gtk/gtkiconhelper.c | |
parent | 6a8001fe7d2818d50fbf133b27c823726c28d97d (diff) | |
download | gtk+-d1c6d78ebb1de39d448b0e8afab13ad495bcadb6.tar.gz |
GtkImage: Preload icons during css validation
At the end of GtkImage css validation (during style-updated) when the
css properties (like the icon size) are valid we call _gtk_icon_helper_preload
which does an async icon theme lookup and load. This will happen on a thread
in parallel with the rest of the css machinery, and hopefully by the
time we need the icon it will be ready. If not we will block when we need
it, but during that blocking all the other icons will be loaded.
Testing widget-factory this changes the time of snapshot() from 31 to
25 msec, but on the other hand we also load a few more icons that we
didn't before causing the css validation phase to be about 8 msec slower.
This is because we're preloading all the images in the window, not only
the ones that are visible.
Unfortunately we still load a bunch of icons in snapshot(), from
GtkCssImageIconTheme, and ideally we should try to preload those also.
Diffstat (limited to 'gtk/gtkiconhelper.c')
-rw-r--r-- | gtk/gtkiconhelper.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/gtk/gtkiconhelper.c b/gtk/gtkiconhelper.c index b5a4983157..47b5b675b0 100644 --- a/gtk/gtkiconhelper.c +++ b/gtk/gtkiconhelper.c @@ -174,6 +174,54 @@ gtk_icon_helper_load_paintable (GtkIconHelper *self, return paintable; } +void +_gtk_icon_helper_preload (GtkIconHelper *self) +{ + GtkIconTheme *icon_theme; + GtkIconLookupFlags flags = 0; + int size, scale; + GtkCssStyle *style; + GIcon *gicon = NULL; + GIcon *free_gicon = NULL; + + switch (gtk_image_definition_get_storage_type (self->def)) + { + case GTK_IMAGE_ICON_NAME: + if (self->use_fallback) + free_gicon = g_themed_icon_new_with_default_fallbacks (gtk_image_definition_get_icon_name (self->def)); + else + free_gicon = g_themed_icon_new (gtk_image_definition_get_icon_name (self->def)); + gicon = free_gicon; + break; + case GTK_IMAGE_GICON: + gicon = gtk_image_definition_get_gicon (self->def) ; + break; + case GTK_IMAGE_EMPTY: + case GTK_IMAGE_PAINTABLE: + default: + break; + } + + if (gicon && G_IS_THEMED_ICON (gicon)) + { + style = gtk_css_node_get_style (self->node); + 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, + gtk_widget_get_direction (self->owner)); + size = gtk_icon_helper_get_size (self); + scale = gtk_widget_get_scale_factor (self->owner); + + gtk_icon_theme_choose_icon_async (icon_theme, + (const gchar **)g_themed_icon_get_names (G_THEMED_ICON (gicon)), + size, scale, + flags, NULL, NULL, NULL); + } + + if (free_gicon) + g_object_unref (free_gicon); +} + static void gtk_icon_helper_ensure_paintable (GtkIconHelper *self) { |