Skip to content

Commit

Permalink
icon-info: hash/store icons using scale factor as well as size
Browse files Browse the repository at this point in the history
Otherwise we might pick up an icon at an invalid size for a given scale.

https://bugzilla.gnome.org/show_bug.cgi?id=776896

origin commit:
https://gitlab.gnome.org/GNOME/nautilus/commit/53cee1de
  • Loading branch information
llandwerlin-intel authored and raveit65 committed Apr 5, 2018
1 parent 70534c0 commit 4c377ba
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions libcaja-private/caja-icon-info.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -186,12 +186,14 @@ caja_icon_info_new_for_icon_info (GtkIconInfo *icon_info,
typedef struct typedef struct
{ {
GIcon *icon; GIcon *icon;
int scale;
int size; int size;
} LoadableIconKey; } LoadableIconKey;


typedef struct typedef struct
{ {
char *filename; char *filename;
int scale;
int size; int size;
} ThemedIconKey; } ThemedIconKey;


Expand Down Expand Up @@ -290,24 +292,28 @@ caja_icon_info_clear_caches (void)
static guint static guint
loadable_icon_key_hash (LoadableIconKey *key) loadable_icon_key_hash (LoadableIconKey *key)
{ {
return g_icon_hash (key->icon) ^ key->size; return g_icon_hash (key->icon) ^ key->scale ^ key->size;
} }


static gboolean static gboolean
loadable_icon_key_equal (const LoadableIconKey *a, loadable_icon_key_equal (const LoadableIconKey *a,
const LoadableIconKey *b) const LoadableIconKey *b)
{ {
return a->size == b->size && return a->size == b->size &&
a->scale == b->scale &&
g_icon_equal (a->icon, b->icon); g_icon_equal (a->icon, b->icon);
} }


static LoadableIconKey * static LoadableIconKey *
loadable_icon_key_new (GIcon *icon, int size) loadable_icon_key_new (GIcon *icon,
int scale,
int size)
{ {
LoadableIconKey *key; LoadableIconKey *key;


key = g_slice_new (LoadableIconKey); key = g_slice_new (LoadableIconKey);
key->icon = g_object_ref (icon); key->icon = g_object_ref (icon);
key->scale = scale;
key->size = size; key->size = size;


return key; return key;
Expand All @@ -331,16 +337,20 @@ themed_icon_key_equal (const ThemedIconKey *a,
const ThemedIconKey *b) const ThemedIconKey *b)
{ {
return a->size == b->size && return a->size == b->size &&
a->scale == b->scale &&
g_str_equal (a->filename, b->filename); g_str_equal (a->filename, b->filename);
} }


static ThemedIconKey * static ThemedIconKey *
themed_icon_key_new (const char *filename, int size) themed_icon_key_new (const char *filename,
int scale,
int size)
{ {
ThemedIconKey *key; ThemedIconKey *key;


key = g_slice_new (ThemedIconKey); key = g_slice_new (ThemedIconKey);
key->filename = g_strdup (filename); key->filename = g_strdup (filename);
key->scale = scale;
key->size = size; key->size = size;


return key; return key;
Expand Down Expand Up @@ -377,7 +387,8 @@ caja_icon_info_lookup (GIcon *icon,
} }


lookup_key.icon = icon; lookup_key.icon = icon;
lookup_key.size = size; lookup_key.scale = scale;
lookup_key.size = size * scale;


icon_info = g_hash_table_lookup (loadable_icon_cache, &lookup_key); icon_info = g_hash_table_lookup (loadable_icon_cache, &lookup_key);
if (icon_info) if (icon_info)
Expand All @@ -401,7 +412,7 @@ caja_icon_info_lookup (GIcon *icon,


icon_info = caja_icon_info_new_for_pixbuf (pixbuf, scale); icon_info = caja_icon_info_new_for_pixbuf (pixbuf, scale);


key = loadable_icon_key_new (icon, size); key = loadable_icon_key_new (icon, scale, size);
g_hash_table_insert (loadable_icon_cache, key, icon_info); g_hash_table_insert (loadable_icon_cache, key, icon_info);


return g_object_ref (icon_info); return g_object_ref (icon_info);
Expand Down Expand Up @@ -442,6 +453,7 @@ caja_icon_info_lookup (GIcon *icon,
} }


lookup_key.filename = (char *)filename; lookup_key.filename = (char *)filename;
lookup_key.scale = scale;
lookup_key.size = size; lookup_key.size = size;


icon_info = g_hash_table_lookup (themed_icon_cache, &lookup_key); icon_info = g_hash_table_lookup (themed_icon_cache, &lookup_key);
Expand All @@ -453,7 +465,7 @@ caja_icon_info_lookup (GIcon *icon,


icon_info = caja_icon_info_new_for_icon_info (gtkicon_info, scale); icon_info = caja_icon_info_new_for_icon_info (gtkicon_info, scale);


key = themed_icon_key_new (filename, size); key = themed_icon_key_new (filename, scale, size);
g_hash_table_insert (themed_icon_cache, key, icon_info); g_hash_table_insert (themed_icon_cache, key, icon_info);


g_object_unref (gtkicon_info); g_object_unref (gtkicon_info);
Expand Down

0 comments on commit 4c377ba

Please sign in to comment.