[gtk: 37/40] GtkIconHelper: Preload icons for mapped widgets with higher priority
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk: 37/40] GtkIconHelper: Preload icons for mapped widgets with higher priority
- Date: Thu, 30 Jan 2020 17:34:15 +0000 (UTC)
commit b67d5822308a5dcd41423eb57acf41897df18d01
Author: Alexander Larsson <alexl redhat com>
Date: Thu Jan 30 15:41:24 2020 +0100
GtkIconHelper: Preload icons for mapped widgets with higher priority
We look at whether a widget will be mapped (the actual state is not
yet set, so we can't rely on that at css validation time) and use
that to set the i/o priority of the async task.
This means that its likely that widgets that will be displayed soon
are loaded before those that are not yet going to be needed.
gtk/gtkiconhelper.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkiconhelper.c b/gtk/gtkiconhelper.c
index a940b9f657..01ed8b4f41 100644
--- a/gtk/gtkiconhelper.c
+++ b/gtk/gtkiconhelper.c
@@ -175,6 +175,22 @@ gtk_icon_helper_load_paintable (GtkIconHelper *self,
return paintable;
}
+/* We are calling this from css-validate, and the mapped state is not yet set, so
+ * we have to calculate ahead of time if a widget will be mapped. */
+static gboolean
+will_be_mapped (GtkWidget *widget)
+{
+ while (widget)
+ {
+ if (!_gtk_widget_get_visible (widget) ||
+ !_gtk_widget_get_child_visible (widget))
+ return FALSE;
+ widget = _gtk_widget_get_parent (widget);
+ }
+
+ return TRUE;
+}
+
void
_gtk_icon_helper_preload (GtkIconHelper *self)
{
@@ -211,6 +227,7 @@ _gtk_icon_helper_preload (GtkIconHelper *self)
if (gicon && G_IS_THEMED_ICON (gicon))
{
+ int priority;
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));
@@ -219,10 +236,16 @@ _gtk_icon_helper_preload (GtkIconHelper *self)
size = gtk_icon_helper_get_size (self);
scale = gtk_widget_get_scale_factor (self->owner);
+ /* Icons for widgets are visible have higher priority so they are loaded first */
+ if (will_be_mapped (self->owner))
+ priority = G_PRIORITY_DEFAULT;
+ else
+ priority = G_PRIORITY_DEFAULT + 1;
+
gtk_icon_theme_choose_icon_async (icon_theme,
(const gchar **)g_themed_icon_get_names (G_THEMED_ICON (gicon)),
size, scale,
- flags, 0, NULL, NULL, NULL);
+ flags, priority, NULL, NULL, NULL);
}
if (free_gicon)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]