[gimp] app: keep the preview TempBuf and GdkPixbuf in GimpViewablePrivate



commit 3e93f45703b9e3761ea4efed7e0678c97b5438da
Author: Michael Natterer <mitch gimp org>
Date:   Tue Mar 8 16:38:25 2011 +0100

    app: keep the preview TempBuf and GdkPixbuf in GimpViewablePrivate
    
    instead of attaching them as object data.

 app/core/gimpviewable.c |  121 ++++++++++++++++++++++++++--------------------
 1 files changed, 68 insertions(+), 53 deletions(-)
---
diff --git a/app/core/gimpviewable.c b/app/core/gimpviewable.c
index abb05d5..8219393 100644
--- a/app/core/gimpviewable.c
+++ b/app/core/gimpviewable.c
@@ -61,6 +61,9 @@ struct _GimpViewablePrivate
   gchar        *stock_id;
   gint          freeze_count;
   GimpViewable *parent;
+
+  TempBuf      *preview_temp_buf;
+  GdkPixbuf    *preview_pixbuf;
 };
 
 #define GET_PRIVATE(viewable) G_TYPE_INSTANCE_GET_PRIVATE (viewable, \
@@ -118,9 +121,7 @@ G_DEFINE_TYPE_WITH_CODE (GimpViewable, gimp_viewable, GIMP_TYPE_OBJECT,
 
 #define parent_class gimp_viewable_parent_class
 
-static guint  viewable_signals[LAST_SIGNAL] = { 0 };
-static GQuark quark_preview_temp_buf        = 0;
-static GQuark quark_preview_pixbuf          = 0;
+static guint viewable_signals[LAST_SIGNAL] = { 0 };
 
 
 static void
@@ -129,9 +130,6 @@ gimp_viewable_class_init (GimpViewableClass *klass)
   GObjectClass    *object_class      = G_OBJECT_CLASS (klass);
   GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
 
-  quark_preview_temp_buf = g_quark_from_static_string ("viewable-preview-temp-buf");
-  quark_preview_pixbuf   = g_quark_from_static_string ("viewable-preview-pixbuf");
-
   viewable_signals[INVALIDATE_PREVIEW] =
     g_signal_new ("invalidate-preview",
                   G_TYPE_FROM_CLASS (klass),
@@ -207,6 +205,18 @@ gimp_viewable_finalize (GObject *object)
       private->stock_id = NULL;
     }
 
+  if (private->preview_temp_buf)
+    {
+      temp_buf_free (private->preview_temp_buf);
+      private->preview_temp_buf = NULL;
+    }
+
+  if (private->preview_pixbuf)
+    {
+      g_object_unref (private->preview_pixbuf);
+      private->preview_pixbuf = NULL;
+    }
+
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
@@ -259,30 +269,16 @@ static gint64
 gimp_viewable_get_memsize (GimpObject *object,
                            gint64     *gui_size)
 {
-  TempBuf   *temp_buf;
-  GdkPixbuf *pixbuf;
-
-  temp_buf = g_object_get_qdata (G_OBJECT (object), quark_preview_temp_buf);
-  pixbuf   = g_object_get_qdata (G_OBJECT (object), quark_preview_pixbuf);
+  GimpViewablePrivate *private = GET_PRIVATE (object);
 
-  *gui_size += temp_buf_get_memsize (temp_buf);
+  *gui_size += temp_buf_get_memsize (private->preview_temp_buf);
 
-  if (pixbuf)
+  if (private->preview_pixbuf)
     {
-      static gsize pixbuf_instance_size = 0;
-
-      if (! pixbuf_instance_size)
-        {
-          GTypeQuery type_query;
-
-          g_type_query (G_TYPE_FROM_INSTANCE (pixbuf), &type_query);
-
-          pixbuf_instance_size = type_query.instance_size;
-        }
-
-      *gui_size += (pixbuf_instance_size +
-                    (gsize) gdk_pixbuf_get_height (pixbuf) *
-                            gdk_pixbuf_get_rowstride (pixbuf));
+      *gui_size +=
+        (gimp_g_object_get_memsize (G_OBJECT (private->preview_pixbuf)) +
+         (gsize) gdk_pixbuf_get_height (private->preview_pixbuf) *
+         gdk_pixbuf_get_rowstride (private->preview_pixbuf));
     }
 
   return GIMP_OBJECT_CLASS (parent_class)->get_memsize (object, gui_size);
@@ -291,8 +287,19 @@ gimp_viewable_get_memsize (GimpObject *object,
 static void
 gimp_viewable_real_invalidate_preview (GimpViewable *viewable)
 {
-  g_object_set_qdata (G_OBJECT (viewable), quark_preview_temp_buf, NULL);
-  g_object_set_qdata (G_OBJECT (viewable), quark_preview_pixbuf, NULL);
+  GimpViewablePrivate *private = GET_PRIVATE (viewable);
+
+  if (private->preview_temp_buf)
+    {
+      temp_buf_free (private->preview_temp_buf);
+      private->preview_temp_buf = NULL;
+    }
+
+  if (private->preview_pixbuf)
+    {
+      g_object_unref (private->preview_pixbuf);
+      private->preview_pixbuf = NULL;
+    }
 }
 
 static void
@@ -694,14 +701,17 @@ gimp_viewable_get_preview (GimpViewable *viewable,
                            gint          width,
                            gint          height)
 {
-  GimpViewableClass *viewable_class;
-  TempBuf           *temp_buf = NULL;
+  GimpViewablePrivate *private;
+  GimpViewableClass   *viewable_class;
+  TempBuf             *temp_buf = NULL;
 
   g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
   g_return_val_if_fail (context == NULL || GIMP_IS_CONTEXT (context), NULL);
   g_return_val_if_fail (width  > 0, NULL);
   g_return_val_if_fail (height > 0, NULL);
 
+  private = GET_PRIVATE (viewable);
+
   if (G_UNLIKELY (context == NULL))
     g_warning ("%s: context is NULL", G_STRFUNC);
 
@@ -713,22 +723,23 @@ gimp_viewable_get_preview (GimpViewable *viewable,
   if (temp_buf)
     return temp_buf;
 
-  temp_buf = g_object_get_qdata (G_OBJECT (viewable), quark_preview_temp_buf);
-
-  if (temp_buf                   &&
-      temp_buf->width  == width  &&
-      temp_buf->height == height)
-    return temp_buf;
+  if (private->preview_temp_buf)
+    {
+      if (private->preview_temp_buf->width  == width  &&
+          private->preview_temp_buf->height == height)
+        {
+          return private->preview_temp_buf;
+        }
 
-  temp_buf = NULL;
+      temp_buf_free (private->preview_temp_buf);
+      private->preview_temp_buf = NULL;
+    }
 
   if (viewable_class->get_new_preview)
     temp_buf = viewable_class->get_new_preview (viewable, context,
                                                 width, height);
 
-  g_object_set_qdata_full (G_OBJECT (viewable), quark_preview_temp_buf,
-                           temp_buf,
-                           (GDestroyNotify) temp_buf_free);
+  private->preview_temp_buf = temp_buf;
 
   return temp_buf;
 }
@@ -860,14 +871,17 @@ gimp_viewable_get_pixbuf (GimpViewable *viewable,
                           gint          width,
                           gint          height)
 {
-  GimpViewableClass *viewable_class;
-  GdkPixbuf         *pixbuf = NULL;
+  GimpViewablePrivate *private;
+  GimpViewableClass   *viewable_class;
+  GdkPixbuf           *pixbuf = NULL;
 
   g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
   g_return_val_if_fail (context == NULL || GIMP_IS_CONTEXT (context), NULL);
   g_return_val_if_fail (width  > 0, NULL);
   g_return_val_if_fail (height > 0, NULL);
 
+  private = GET_PRIVATE (viewable);
+
   if (G_UNLIKELY (context == NULL))
     g_warning ("%s: context is NULL", G_STRFUNC);
 
@@ -879,21 +893,22 @@ gimp_viewable_get_pixbuf (GimpViewable *viewable,
   if (pixbuf)
     return pixbuf;
 
-  pixbuf = g_object_get_qdata (G_OBJECT (viewable), quark_preview_pixbuf);
-
-  if (pixbuf                                  &&
-      gdk_pixbuf_get_width (pixbuf)  == width &&
-      gdk_pixbuf_get_height (pixbuf) == height)
-    return pixbuf;
+  if (private->preview_pixbuf)
+    {
+      if (gdk_pixbuf_get_width  (private->preview_pixbuf) == width &&
+          gdk_pixbuf_get_height (private->preview_pixbuf) == height)
+        {
+          return pixbuf;
+        }
 
-  pixbuf = NULL;
+      g_object_unref (private->preview_pixbuf);
+      private->preview_pixbuf = NULL;
+    }
 
   if (viewable_class->get_new_pixbuf)
     pixbuf = viewable_class->get_new_pixbuf (viewable, context, width, height);
 
-  g_object_set_qdata_full (G_OBJECT (viewable), quark_preview_pixbuf,
-                           pixbuf,
-                           (GDestroyNotify) g_object_unref);
+  private->preview_pixbuf = pixbuf;
 
   return pixbuf;
 }



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