[maemo-commits] [maemo-commits] r13757 - in projects/haf/trunk/sapwood: . src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Tue Sep 11 17:06:49 EEST 2007
Author: tko
Date: 2007-09-11 17:06:46 +0300 (Tue, 11 Sep 2007)
New Revision: 13757

Modified:
   projects/haf/trunk/sapwood/ChangeLog
   projects/haf/trunk/sapwood/src/sapwood-rc-style.c
   projects/haf/trunk/sapwood/src/sapwood-render.c
   projects/haf/trunk/sapwood/src/theme-pixbuf.h
Log:
Replace GCache of pixmaps with hash of refcounted ThemePixbufs.

2007-09-11  Tommi Komulainen  <tommi.komulainen at nokia.com>

	Replace GCache of pixmaps with hash of refcounted ThemePixbufs.

	Since we already have 1:1 mapping between ThemePixbuf and
	SapwoodPixmap caching the higher level object is more efficient.
	This also enables checking earlier whether two files are referenced
	with different border values (which is not supported by the server.)

	* src/theme-pixbuf.h (ThemePixbuf, theme_pixbuf_canonicalize): Updated
	bitfield and added the function.
	* src/sapwood-render.c (pixmap_cache, theme_pixbuf_copy,
	pixmap_cache_value_new): Removed
	(pixbuf_hash, theme_pixbuf_canonicalize, theme_pixbuf_ref): Added
	(theme_pixbuf_destroy, theme_pixbuf_set_filename,
	theme_pixbuf_get_pixmap): Adapted
	* src/sapwood-rc-style.c (theme_parse_image): Canonicalize


Modified: projects/haf/trunk/sapwood/ChangeLog
===================================================================
--- projects/haf/trunk/sapwood/ChangeLog	2007-09-11 13:59:39 UTC (rev 13756)
+++ projects/haf/trunk/sapwood/ChangeLog	2007-09-11 14:06:46 UTC (rev 13757)
@@ -1,5 +1,23 @@
 2007-09-11  Tommi Komulainen  <tommi.komulainen at nokia.com>
 
+	Replace GCache of pixmaps with hash of refcounted ThemePixbufs.
+
+	Since we already have 1:1 mapping between ThemePixbuf and
+	SapwoodPixmap caching the higher level object is more efficient.
+	This also enables checking earlier whether two files are referenced
+	with different border values (which is not supported by the server.)
+
+	* src/theme-pixbuf.h (ThemePixbuf, theme_pixbuf_canonicalize): Updated
+	bitfield and added the function.
+	* src/sapwood-render.c (pixmap_cache, theme_pixbuf_copy,
+	pixmap_cache_value_new): Removed
+	(pixbuf_hash, theme_pixbuf_canonicalize, theme_pixbuf_ref): Added
+	(theme_pixbuf_destroy, theme_pixbuf_set_filename,
+	theme_pixbuf_get_pixmap): Adapted
+	* src/sapwood-rc-style.c (theme_parse_image): Canonicalize
+
+2007-09-11  Tommi Komulainen  <tommi.komulainen at nokia.com>
+
 	* src/sapwood-server.c (process_buffer, cleanup_sock_removed): Add
 	reference counting to pixmaps. It is already possible for one client
 	to request the same pixmap multiple times, but the first release will

Modified: projects/haf/trunk/sapwood/src/sapwood-rc-style.c
===================================================================
--- projects/haf/trunk/sapwood/src/sapwood-rc-style.c	2007-09-11 13:59:39 UTC (rev 13756)
+++ projects/haf/trunk/sapwood/src/sapwood-rc-style.c	2007-09-11 14:06:46 UTC (rev 13757)
@@ -702,6 +702,8 @@
       theme_pixbuf_unref (image);							\
       image = NULL;									\
     }											\
+  else if (image)									\
+    image = theme_pixbuf_canonicalize (image);						\
 }G_STMT_END
 
   CHECK_IMAGE(data->background, "Background");

Modified: projects/haf/trunk/sapwood/src/sapwood-render.c
===================================================================
--- projects/haf/trunk/sapwood/src/sapwood-render.c	2007-09-11 13:59:39 UTC (rev 13756)
+++ projects/haf/trunk/sapwood/src/sapwood-render.c	2007-09-11 14:06:46 UTC (rev 13757)
@@ -37,7 +37,7 @@
 #define LOG(...)
 #endif
 
-static GCache *pixmap_cache = NULL;
+static GHashTable *pixbuf_hash = NULL;
 
 ThemePixbuf *
 theme_pixbuf_new (void)
@@ -57,22 +57,24 @@
   else if (theme_pb->refcnt > 1)
       g_warning ("[%p] destroy: refcnt > 1", theme_pb);
 
-  theme_pixbuf_set_filename (theme_pb, NULL);
+  if (theme_pb->shared)
+    {
+      g_hash_table_remove (pixbuf_hash, theme_pb);
+      if (theme_pb->pixmap)
+	sapwood_pixmap_free (theme_pb->pixmap);
+    }
+  if (theme_pb->basename)
+    g_free (theme_pb->basename);
   g_free (theme_pb);
 }
 
 static ThemePixbuf *
-theme_pixbuf_copy (ThemePixbuf *theme_pb)
+theme_pixbuf_ref (ThemePixbuf *theme_pb)
 {
-  ThemePixbuf *copy;
-
-  copy = g_memdup(theme_pb, sizeof(*theme_pb));
-  copy->refcnt = 1;
-  copy->dirname  = theme_pb->dirname;
-  copy->basename = g_strdup (theme_pb->basename);
-  copy->pixmap = NULL;
-
-  return copy;
+  theme_pb->refcnt++;
+  LOG ("[%p] ref: refcnt = %d", theme_pb, theme_pb->refcnt);
+  g_assert(theme_pb->refcnt != 0);
+  return theme_pb;
 }
 
 void
@@ -120,15 +122,37 @@
   return TRUE;
 }
 
+ThemePixbuf *
+theme_pixbuf_canonicalize (ThemePixbuf *theme_pb)
+{
+  ThemePixbuf *canon;
+
+  g_assert (theme_pb->pixmap == NULL);
+
+  if (!pixbuf_hash)
+    pixbuf_hash = g_hash_table_new (theme_pixbuf_hash, theme_pixbuf_equal);
+
+  canon = g_hash_table_lookup (pixbuf_hash, theme_pb);
+  if (!canon)
+    {
+      theme_pb->shared = 1;
+      g_hash_table_insert (pixbuf_hash, theme_pb, theme_pb);
+      canon = theme_pb;
+    }
+  else
+    {
+      theme_pixbuf_ref (canon);
+      theme_pixbuf_unref (theme_pb);
+    }
+
+  return canon;
+}
+
 void         
 theme_pixbuf_set_filename (ThemePixbuf *theme_pb,
 			   const char  *filename)
 {
-  if (theme_pb->pixmap)
-    {
-      g_cache_remove (pixmap_cache, theme_pb->pixmap);
-      theme_pb->pixmap = NULL;
-    }
+  g_assert (theme_pb->pixmap == NULL);
 
   if (theme_pb->basename)
     g_free (theme_pb->basename);
@@ -183,46 +207,28 @@
 }
 
 static SapwoodPixmap *
-pixmap_cache_value_new (ThemePixbuf *theme_pb)
-{
-  SapwoodPixmap *result;
-  char          *filename;
-  GError *err = NULL;
-
-  filename = g_build_filename (theme_pb->dirname, theme_pb->basename, NULL);
-  result = sapwood_pixmap_get_for_file (filename,
-						     theme_pb->border_left,
-						     theme_pb->border_right,
-						     theme_pb->border_top,
-						     theme_pb->border_bottom,
-						     &err);
-  if (!result)
-    {
-      g_warning ("sapwood-theme: Failed to load pixmap file %s: %s\n",
-		 filename, err->message);
-      g_error_free (err);
-    }
-
-  g_free (filename);
-
-  return result;
-}
-
-static SapwoodPixmap *
 theme_pixbuf_get_pixmap (ThemePixbuf *theme_pb)
 {
   if (!theme_pb->pixmap)
     {
-      if (!pixmap_cache)
-	pixmap_cache = g_cache_new ((GCacheNewFunc)pixmap_cache_value_new,
-				    (GCacheDestroyFunc)sapwood_pixmap_free,
-				    (GCacheDupFunc)theme_pixbuf_copy,
-				    (GCacheDestroyFunc)theme_pixbuf_unref,
-				    theme_pixbuf_hash, g_direct_hash, theme_pixbuf_equal);
+      char   *filename;
+      GError *err = NULL;
 
-      theme_pb->pixmap = g_cache_insert (pixmap_cache, theme_pb);
+      filename = g_build_filename (theme_pb->dirname, theme_pb->basename, NULL);
+      theme_pb->pixmap = sapwood_pixmap_get_for_file (filename,
+						      theme_pb->border_left,
+						      theme_pb->border_right,
+						      theme_pb->border_top,
+						      theme_pb->border_bottom,
+						      &err);
       if (!theme_pb->pixmap)
-	g_cache_remove (pixmap_cache, NULL);
+	{
+	  g_warning ("sapwood-theme: Failed to load pixmap file %s: %s\n",
+		     filename, err->message);
+	  g_error_free (err);
+	}
+
+      g_free (filename);
     }
   return theme_pb->pixmap;
 }

Modified: projects/haf/trunk/sapwood/src/theme-pixbuf.h
===================================================================
--- projects/haf/trunk/sapwood/src/theme-pixbuf.h	2007-09-11 13:59:39 UTC (rev 13756)
+++ projects/haf/trunk/sapwood/src/theme-pixbuf.h	2007-09-11 14:06:46 UTC (rev 13757)
@@ -143,7 +143,8 @@
   guint16     border_right;
   guint16     border_bottom;
   guint16     border_top;
-  guint       refcnt : 7;
+  guint       refcnt : 14;
+  guint       shared : 1;
   guint       stretch : 1;
 };
 
@@ -178,6 +179,7 @@
 
 ThemePixbuf *theme_pixbuf_new          (void) G_GNUC_INTERNAL;
 void         theme_pixbuf_unref        (ThemePixbuf  *theme_pb) G_GNUC_INTERNAL;
+ThemePixbuf *theme_pixbuf_canonicalize (ThemePixbuf  *theme_pb) G_GNUC_INTERNAL;
 void         theme_pixbuf_set_filename (ThemePixbuf  *theme_pb,
 					const char   *filename) G_GNUC_INTERNAL;
 gboolean     theme_pixbuf_get_geometry (ThemePixbuf  *theme_pb,


More information about the maemo-commits mailing list