From e5e764b4020371462006091bc3b873768ac42351 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 15 Feb 2014 19:43:35 -0800 Subject: [PATCH] texture-cache: require icon scale to load gicon To support HiDpi. https://bugzilla.gnome.org/show_bug.cgi?id=705410 --- src/shell-app.c | 10 ++++++++-- src/shell-window-tracker.c | 11 +++++++++-- src/st/st-icon.c | 25 +++++++++++++++++++++++-- src/st/st-texture-cache.c | 21 ++++++++++++--------- src/st/st-texture-cache.h | 3 ++- 5 files changed, 54 insertions(+), 16 deletions(-) diff --git a/src/shell-app.c b/src/shell-app.c index 537e355cf..3ec90e040 100644 --- a/src/shell-app.c +++ b/src/shell-app.c @@ -193,8 +193,14 @@ shell_app_create_icon_texture (ShellApp *app, int size) { GIcon *icon; + gint scale; ClutterActor *ret; + ShellGlobal *global; + StThemeContext *context; + global = shell_global_get (); + context = st_theme_context_get_for_stage (shell_global_get_stage (global)); + g_object_get (context, "scale-factor", &scale, NULL); ret = NULL; if (app->info == NULL) @@ -202,12 +208,12 @@ shell_app_create_icon_texture (ShellApp *app, icon = g_app_info_get_icon (G_APP_INFO (app->info)); if (icon != NULL) - ret = st_texture_cache_load_gicon (st_texture_cache_get_default (), NULL, icon, size); + ret = st_texture_cache_load_gicon (st_texture_cache_get_default (), NULL, icon, size, scale); if (ret == NULL) { icon = g_themed_icon_new ("application-x-executable"); - ret = st_texture_cache_load_gicon (st_texture_cache_get_default (), NULL, icon, size); + ret = st_texture_cache_load_gicon (st_texture_cache_get_default (), NULL, icon, size, scale); g_object_unref (icon); } diff --git a/src/shell-window-tracker.c b/src/shell-window-tracker.c index 0fb1ca6dd..3e0ea8332 100644 --- a/src/shell-window-tracker.c +++ b/src/shell-window-tracker.c @@ -848,18 +848,25 @@ shell_startup_sequence_create_icon (ShellStartupSequence *sequence, guint size) GIcon *themed; const char *icon_name; ClutterActor *texture; + gint scale; + ShellGlobal *global; + StThemeContext *context; + + global = shell_global_get (); + context = st_theme_context_get_for_stage (shell_global_get_stage (global)); + g_object_get (context, "scale-factor", &scale, NULL); icon_name = sn_startup_sequence_get_icon_name ((SnStartupSequence*)sequence); if (!icon_name) { texture = clutter_texture_new (); - clutter_actor_set_size (texture, size, size); + clutter_actor_set_size (texture, size * scale, size * scale); return texture; } themed = g_themed_icon_new (icon_name); texture = st_texture_cache_load_gicon (st_texture_cache_get_default (), - NULL, themed, size); + NULL, themed, size, scale); g_object_unref (G_OBJECT (themed)); return texture; } diff --git a/src/st/st-icon.c b/src/st/st-icon.c index fac474af9..3ea6d3812 100644 --- a/src/st/st-icon.c +++ b/src/st/st-icon.c @@ -29,6 +29,7 @@ #include "st-enum-types.h" #include "st-icon.h" #include "st-texture-cache.h" +#include "st-theme-context.h" #include "st-private.h" enum @@ -430,6 +431,9 @@ st_icon_update (StIcon *icon) StIconPrivate *priv = icon->priv; StThemeNode *theme_node; StTextureCache *cache; + gint scale; + ClutterActor *stage; + StThemeContext *context; if (priv->pending_texture) { @@ -443,13 +447,18 @@ st_icon_update (StIcon *icon) if (theme_node == NULL) return; + stage = clutter_actor_get_stage (CLUTTER_ACTOR (icon)); + context = st_theme_context_get_for_stage (CLUTTER_STAGE (stage)); + g_object_get (context, "scale-factor", &scale, NULL); + cache = st_texture_cache_get_default (); if (priv->gicon) { priv->pending_texture = st_texture_cache_load_gicon (cache, theme_node, priv->gicon, - priv->icon_size); + priv->icon_size, + scale); } if (priv->pending_texture) @@ -483,7 +492,19 @@ st_icon_update_icon_size (StIcon *icon) if (priv->prop_icon_size > 0) new_size = priv->prop_icon_size; else if (priv->theme_icon_size > 0) - new_size = priv->theme_icon_size; + { + gint scale; + ClutterActor *stage; + StThemeContext *context; + + /* The theme will give us an already-scaled size, so we + * undo it here, as priv->icon_size is in unscaled pixels. + */ + stage = clutter_actor_get_stage (CLUTTER_ACTOR (icon)); + context = st_theme_context_get_for_stage (CLUTTER_STAGE (stage)); + g_object_get (context, "scale-factor", &scale, NULL); + new_size = (gint) (priv->theme_icon_size / scale); + } else new_size = DEFAULT_ICON_SIZE; diff --git a/src/st/st-texture-cache.c b/src/st/st-texture-cache.c index 17cb0689d..f102f39a0 100644 --- a/src/st/st-texture-cache.c +++ b/src/st/st-texture-cache.c @@ -909,6 +909,7 @@ static ClutterActor * load_gicon_with_colors (StTextureCache *cache, GIcon *icon, gint size, + gint scale, StIconColors *colors) { AsyncTextureLoadData *request; @@ -922,7 +923,7 @@ load_gicon_with_colors (StTextureCache *cache, /* Do theme lookups in the main thread to avoid thread-unsafety */ theme = cache->priv->icon_theme; - info = gtk_icon_theme_lookup_by_gicon (theme, icon, size, GTK_ICON_LOOKUP_USE_BUILTIN); + info = gtk_icon_theme_lookup_by_gicon_for_scale (theme, icon, size, scale, GTK_ICON_LOOKUP_USE_BUILTIN); if (info == NULL) return NULL; @@ -936,8 +937,8 @@ load_gicon_with_colors (StTextureCache *cache, if (colors) { /* This raises some doubts about the practice of using string keys */ - key = g_strdup_printf (CACHE_PREFIX_ICON "%s,size=%d,colors=%2x%2x%2x%2x,%2x%2x%2x%2x,%2x%2x%2x%2x,%2x%2x%2x%2x", - gicon_string, size, + key = g_strdup_printf (CACHE_PREFIX_ICON "%s,size=%d,scale=%d,colors=%2x%2x%2x%2x,%2x%2x%2x%2x,%2x%2x%2x%2x,%2x%2x%2x%2x", + gicon_string, size, scale, colors->foreground.red, colors->foreground.blue, colors->foreground.green, colors->foreground.alpha, colors->warning.red, colors->warning.blue, colors->warning.green, colors->warning.alpha, colors->error.red, colors->error.blue, colors->error.green, colors->error.alpha, @@ -945,13 +946,13 @@ load_gicon_with_colors (StTextureCache *cache, } else { - key = g_strdup_printf (CACHE_PREFIX_ICON "%s,size=%d", - gicon_string, size); + key = g_strdup_printf (CACHE_PREFIX_ICON "%s,size=%d,scale=%d", + gicon_string, size, scale); } g_free (gicon_string); texture = (ClutterActor *) create_default_texture (); - clutter_actor_set_size (texture, size, size); + clutter_actor_set_size (texture, size * scale, size * scale); if (ensure_request (cache, key, policy, &request, texture)) { @@ -969,7 +970,7 @@ load_gicon_with_colors (StTextureCache *cache, request->policy = policy; request->colors = colors ? st_icon_colors_ref (colors) : NULL; request->icon_info = info; - request->width = request->height = size; + request->width = request->height = size * scale; request->enforced_square = TRUE; load_texture_async (cache, request); @@ -985,6 +986,7 @@ load_gicon_with_colors (StTextureCache *cache, * if the icon must not be recolored * @icon: the #GIcon to load * @size: Size of themed + * @scale: Scale factor of display * * This method returns a new #ClutterActor for a given #GIcon. If the * icon isn't loaded already, the texture will be filled @@ -996,9 +998,10 @@ ClutterActor * st_texture_cache_load_gicon (StTextureCache *cache, StThemeNode *theme_node, GIcon *icon, - gint size) + gint size, + gint scale) { - return load_gicon_with_colors (cache, icon, size, theme_node ? st_theme_node_get_icon_colors (theme_node) : NULL); + return load_gicon_with_colors (cache, icon, size, scale, theme_node ? st_theme_node_get_icon_colors (theme_node) : NULL); } static ClutterActor * diff --git a/src/st/st-texture-cache.h b/src/st/st-texture-cache.h index fa9746c49..c52f45ad3 100644 --- a/src/st/st-texture-cache.h +++ b/src/st/st-texture-cache.h @@ -83,7 +83,8 @@ ClutterActor *st_texture_cache_bind_pixbuf_property (StTextureCache *cache, ClutterActor *st_texture_cache_load_gicon (StTextureCache *cache, StThemeNode *theme_node, GIcon *icon, - gint size); + gint size, + gint scale); ClutterActor *st_texture_cache_load_uri_async (StTextureCache *cache, const gchar *uri,