[maemo-commits] [maemo-commits] r19167 - in projects/haf/trunk/gtk+: . gdk

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Thu Aug 20 19:02:17 EEST 2009
Author: berto
Date: 2009-08-20 19:02:06 +0300 (Thu, 20 Aug 2009)
New Revision: 19167

Modified:
   projects/haf/trunk/gtk+/ChangeLog
   projects/haf/trunk/gtk+/gdk/gdkcairo.c
Log:
2009-08-20  Alberto Garcia  <agarcia at igalia.com>

	* gdk/gdkcairo.c
	(gdk_cairo_set_source_pixbuf, +clear_surface_cache):
	Cache the cairo surface created from each GdkPixbuf to avoid
	having to repeat the same expensive computation once and again.
	Clear cache every ~150 ms.

	Fixes: NB#131815 (gdk_cairo_set_source_pixbuf() needs to be
	optimized)

Modified: projects/haf/trunk/gtk+/ChangeLog
===================================================================
--- projects/haf/trunk/gtk+/ChangeLog	2009-08-20 14:45:38 UTC (rev 19166)
+++ projects/haf/trunk/gtk+/ChangeLog	2009-08-20 16:02:06 UTC (rev 19167)
@@ -1,3 +1,14 @@
+2009-08-20  Alberto Garcia  <agarcia at igalia.com>
+
+	* gdk/gdkcairo.c
+	(gdk_cairo_set_source_pixbuf, +clear_surface_cache):
+	Cache the cairo surface created from each GdkPixbuf to avoid
+	having to repeat the same expensive computation once and again.
+	Clear cache every ~150 ms.
+
+	Fixes: NB#131815 (gdk_cairo_set_source_pixbuf() needs to be
+	optimized)
+
 2009-08-19  Sven Herzberg  <herzi at lanedo.com>
 
 	Revert the whole RGBA stuff

Modified: projects/haf/trunk/gtk+/gdk/gdkcairo.c
===================================================================
--- projects/haf/trunk/gtk+/gdk/gdkcairo.c	2009-08-20 14:45:38 UTC (rev 19166)
+++ projects/haf/trunk/gtk+/gdk/gdkcairo.c	2009-08-20 16:02:06 UTC (rev 19167)
@@ -128,6 +128,16 @@
 		     boxes[i].y2 - boxes[i].y1);
 }
 
+#ifdef MAEMO_CHANGES
+static gboolean
+clear_surface_cache (GHashTable **hashtable)
+{
+    g_hash_table_destroy (*hashtable);
+    *hashtable = NULL;
+    return FALSE;
+}
+#endif /* MAEMO_CHANGES */
+
 /**
  * gdk_cairo_set_source_pixbuf:
  * @cr: a #Cairo context
@@ -158,7 +168,27 @@
   cairo_surface_t *surface;
   static const cairo_user_data_key_t key;
   int j;
+#ifdef MAEMO_CHANGES
+  static GHashTable *surface_cache_table = NULL;
 
+  if (surface_cache_table == NULL)
+    {
+      surface_cache_table = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+                                                   g_object_unref, (GDestroyNotify) cairo_surface_destroy);
+      gdk_threads_add_timeout_full (GDK_PRIORITY_REDRAW + 1, 150, (GSourceFunc) clear_surface_cache,
+                                    &surface_cache_table, NULL);
+    }
+  else
+    {
+      surface = g_hash_table_lookup (surface_cache_table, pixbuf);
+      if (surface)
+        {
+          cairo_set_source_surface (cr, surface, pixbuf_x, pixbuf_y);
+          return;
+        }
+    }
+#endif /* MAEMO_CHANGES */
+
   if (n_channels == 3)
     format = CAIRO_FORMAT_RGB24;
   else
@@ -170,6 +200,11 @@
                                                  format,
                                                  width, height, cairo_stride);
 
+#ifdef MAEMO_CHANGES
+  g_hash_table_insert (surface_cache_table, g_object_ref (G_OBJECT (pixbuf)),
+                       cairo_surface_reference (surface));
+#endif /* MAEMO_CHANGES */
+
   cairo_surface_set_user_data (surface, &key,
 			       cairo_pixels, (cairo_destroy_func_t)g_free);
 

More information about the maemo-commits mailing list