forked from AuroraMiddleware/gtk
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.
This commit is contained in:
parent
6a8001fe7d
commit
d1c6d78ebb
@ -174,6 +174,54 @@ gtk_icon_helper_load_paintable (GtkIconHelper *self,
|
|||||||
return paintable;
|
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
|
static void
|
||||||
gtk_icon_helper_ensure_paintable (GtkIconHelper *self)
|
gtk_icon_helper_ensure_paintable (GtkIconHelper *self)
|
||||||
{
|
{
|
||||||
|
@ -48,6 +48,7 @@ void _gtk_icon_helper_set_icon_name (GtkIconHelper *self,
|
|||||||
const gchar *icon_name);
|
const gchar *icon_name);
|
||||||
void _gtk_icon_helper_set_paintable (GtkIconHelper *self,
|
void _gtk_icon_helper_set_paintable (GtkIconHelper *self,
|
||||||
GdkPaintable *paintable);
|
GdkPaintable *paintable);
|
||||||
|
void _gtk_icon_helper_preload (GtkIconHelper *self);
|
||||||
|
|
||||||
gboolean _gtk_icon_helper_set_pixel_size (GtkIconHelper *self,
|
gboolean _gtk_icon_helper_set_pixel_size (GtkIconHelper *self,
|
||||||
gint pixel_size);
|
gint pixel_size);
|
||||||
|
@ -1294,6 +1294,8 @@ gtk_image_style_updated (GtkWidget *widget)
|
|||||||
|
|
||||||
GTK_WIDGET_CLASS (gtk_image_parent_class)->style_updated (widget);
|
GTK_WIDGET_CLASS (gtk_image_parent_class)->style_updated (widget);
|
||||||
|
|
||||||
|
_gtk_icon_helper_preload (priv->icon_helper);
|
||||||
|
|
||||||
priv->baseline_align = 0.0;
|
priv->baseline_align = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user