summaryrefslogtreecommitdiff
path: root/gtk/gtkiconcache.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2005-11-04 15:43:40 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2005-11-04 15:43:40 +0000
commitb983d1c6a7833ce85fe53eee0d7b15bd03aad585 (patch)
tree093dd7272edec179393defc86c8ee11ca6c08f89 /gtk/gtkiconcache.c
parent99633ce5358189eec090d9a72655b777396762b0 (diff)
downloadgtk+-b983d1c6a7833ce85fe53eee0d7b15bd03aad585.tar.gz
Store builtin stock icons in an icon cache, instead of populating a hash
2005-11-04 Matthias Clasen <mclasen@redhat.com> Store builtin stock icons in an icon cache, instead of populating a hash table with pixbufs at startup, to save both memory and startup time. * gtk/stock-icons/*: Reorganize the icons in a directory structure suitable for gtk-update-icon-cache, and rename them to match the stock ids. * gtk/gtkiconcache.[hc]: Support non-mmapped icon caches, and add _gtk_icon_cache_has_icon_in_directory(). * gtk/updateiconcache.c: Support a --source <VARIABLE> argument to store the contents of the icon cache in a C header. * gtk/gtkbuiltincache.h: Generated private header which contains the icon cache for the builtin icons. * gtk/gtkicontheme.c: Create a GtkIconCache for the builtin icons, and use that in addition to the hash table whenever builtin icons are searched. * gtk/gtkiconfactory.c: Add GTK_ICON_SOURCE_STATIC_ICON_NAME and use it for static stock ids. (get_default_icons): Don't add the builtin icons to the icon theme, just register the stock ids. (render_fallback_image): Take the fallback image out of the builtin icon cache. * gtk/Makefile.am: Remove stock-icons from SUBDIRS and add the necessary machinery to rebuild gtkbuiltincache.h.
Diffstat (limited to 'gtk/gtkiconcache.c')
-rw-r--r--gtk/gtkiconcache.c78
1 files changed, 74 insertions, 4 deletions
diff --git a/gtk/gtkiconcache.c b/gtk/gtkiconcache.c
index d6f685065b..23fe31d6da 100644
--- a/gtk/gtkiconcache.c
+++ b/gtk/gtkiconcache.c
@@ -70,7 +70,8 @@ _gtk_icon_cache_unref (GtkIconCache *cache)
GTK_NOTE (ICONTHEME,
g_print ("unmapping icon cache\n"));
- g_mapped_file_free (cache->map);
+ if (cache->map)
+ g_mapped_file_free (cache->map);
g_free (cache);
}
}
@@ -146,13 +147,26 @@ _gtk_icon_cache_new_for_path (const gchar *path)
return cache;
}
-static int
+GtkIconCache *
+_gtk_icon_cache_new (const gchar *data)
+{
+ GtkIconCache *cache;
+
+ cache = g_new0 (GtkIconCache, 1);
+ cache->ref_count = 1;
+ cache->map = NULL;
+ cache->buffer = (gchar *)data;
+
+ return cache;
+}
+
+static gint
get_directory_index (GtkIconCache *cache,
const gchar *directory)
{
guint32 dir_list_offset;
- int n_dirs;
- int i;
+ gint n_dirs;
+ gint i;
dir_list_offset = GET_UINT32 (cache->buffer, 8);
@@ -327,6 +341,62 @@ _gtk_icon_cache_has_icon (GtkIconCache *cache,
return FALSE;
}
+gboolean
+_gtk_icon_cache_has_icon_in_directory (GtkIconCache *cache,
+ const gchar *icon_name,
+ const gchar *directory)
+{
+ guint32 hash_offset;
+ guint32 n_buckets;
+ guint32 chain_offset;
+ gint hash;
+ gboolean found_icon = FALSE;
+ gint directory_index;
+
+ directory_index = get_directory_index (cache, directory);
+
+ if (directory_index == -1)
+ return FALSE;
+
+ hash_offset = GET_UINT32 (cache->buffer, 4);
+ n_buckets = GET_UINT32 (cache->buffer, hash_offset);
+
+ hash = icon_name_hash (icon_name) % n_buckets;
+
+ chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * hash);
+ while (chain_offset != 0xffffffff)
+ {
+ guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4);
+ gchar *name = cache->buffer + name_offset;
+
+ if (strcmp (name, icon_name) == 0)
+ {
+ found_icon = TRUE;
+ break;
+ }
+
+ chain_offset = GET_UINT32 (cache->buffer, chain_offset);
+ }
+
+ if (found_icon)
+ {
+ guint32 image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8);
+ guint32 n_images = GET_UINT32 (cache->buffer, image_list_offset);
+ guint32 image_offset = image_list_offset + 4;
+ gint i;
+ for (i = 0; i < n_images; i++)
+ {
+ guint16 index = GET_UINT16 (cache->buffer, image_offset);
+
+ if (index == directory_index)
+ return TRUE;
+ image_offset += 8;
+ }
+ }
+
+ return FALSE;
+}
+
static void
pixbuf_destroy_cb (guchar *pixels,
gpointer data)