[gnome-shell] Add shell_texture_cache_pixbufs_equal



commit 926643b025c87c9343937965131fb9b2963f6d31
Author: Colin Walters <walters verbum org>
Date:   Tue Sep 1 14:13:15 2009 -0400

    Add shell_texture_cache_pixbufs_equal
    
    Mutter is currently creating separate pixbufs for window icons;
    use this to analyze them.

 src/shell-texture-cache.c |   29 +++++++++++++++++++++++++++++
 src/shell-texture-cache.h |    2 ++
 2 files changed, 31 insertions(+), 0 deletions(-)
---
diff --git a/src/shell-texture-cache.c b/src/shell-texture-cache.c
index 0ed3446..93835af 100644
--- a/src/shell-texture-cache.c
+++ b/src/shell-texture-cache.c
@@ -1236,6 +1236,35 @@ shell_texture_cache_evict_recent_thumbnail (ShellTextureCache *cache,
   shell_texture_cache_evict_thumbnail (cache, gtk_recent_info_get_uri (info));
 }
 
+static size_t
+pixbuf_byte_size (GdkPixbuf *pixbuf)
+{
+  /* This bit translated from gtk+/gdk-pixbuf/gdk-pixbuf.c:gdk_pixbuf_copy.  The comment
+   * there was:
+   *
+   * Calculate a semi-exact size.  Here we copy with full rowstrides;
+   * maybe we should copy each row individually with the minimum
+   * rowstride?
+   */
+  return (gdk_pixbuf_get_height (pixbuf) - 1) * gdk_pixbuf_get_rowstride (pixbuf) +
+    + gdk_pixbuf_get_width (pixbuf) * ((gdk_pixbuf_get_n_channels (pixbuf)* gdk_pixbuf_get_bits_per_sample (pixbuf) + 7) / 8);
+}
+
+/**
+ * shell_texture_cache_pixbuf_equal:
+ *
+ * Returns: %TRUE iff the given pixbufs are bytewise-equal
+ */
+gboolean
+shell_texture_cache_pixbuf_equal (ShellTextureCache *cache, GdkPixbuf *a, GdkPixbuf *b)
+{
+  size_t size_a = pixbuf_byte_size (a);
+  size_t size_b = pixbuf_byte_size (b);
+  if (size_a != size_b)
+    return FALSE;
+  return memcmp (gdk_pixbuf_get_pixels (a), gdk_pixbuf_get_pixels (b), size_a) == 0;
+}
+
 static ShellTextureCache *instance = NULL;
 
 /**
diff --git a/src/shell-texture-cache.h b/src/shell-texture-cache.h
index 940e101..057eae3 100644
--- a/src/shell-texture-cache.h
+++ b/src/shell-texture-cache.h
@@ -79,4 +79,6 @@ ClutterActor *shell_texture_cache_load_uri_sync (ShellTextureCache *cache,
                                                  int                available_height,
                                                  GError           **error);
 
+gboolean shell_texture_cache_pixbuf_equal (ShellTextureCache *cache, GdkPixbuf *a, GdkPixbuf *b);
+
 #endif /* __SHELL_TEXTURE_CACHE_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]