[gimp] app: virtualize GimpBrush::begin_use() and ::end_use()



commit 5a4a741936959833fb640dffc34952d53a946e41
Author: Michael Natterer <mitch gimp org>
Date:   Tue Apr 12 13:59:04 2011 +0200

    app: virtualize GimpBrush::begin_use() and ::end_use()

 app/core/gimpbrush.c |   94 ++++++++++++++++++++++++++++----------------------
 app/core/gimpbrush.h |    8 +++--
 2 files changed, 58 insertions(+), 44 deletions(-)
---
diff --git a/app/core/gimpbrush.c b/app/core/gimpbrush.c
index 4f4d7ea..222246c 100644
--- a/app/core/gimpbrush.c
+++ b/app/core/gimpbrush.c
@@ -81,6 +81,8 @@ static gchar       * gimp_brush_get_description       (GimpViewable         *vie
 static void          gimp_brush_dirty                 (GimpData             *data);
 static const gchar * gimp_brush_get_extension         (GimpData             *data);
 
+static void          gimp_brush_real_begin_use        (GimpBrush            *brush);
+static void          gimp_brush_real_end_use          (GimpBrush            *brush);
 static GimpBrush   * gimp_brush_real_select_brush     (GimpBrush            *brush,
                                                        const GimpCoords     *last_coords,
                                                        const GimpCoords     *current_coords);
@@ -131,6 +133,8 @@ gimp_brush_class_init (GimpBrushClass *klass)
   data_class->dirty                = gimp_brush_dirty;
   data_class->get_extension        = gimp_brush_get_extension;
 
+  klass->begin_use                 = gimp_brush_real_begin_use;
+  klass->end_use                   = gimp_brush_real_end_use;
   klass->select_brush              = gimp_brush_real_select_brush;
   klass->want_null_motion          = gimp_brush_real_want_null_motion;
   klass->transform_size            = gimp_brush_real_transform_size;
@@ -406,6 +410,32 @@ gimp_brush_get_extension (GimpData *data)
   return GIMP_BRUSH_FILE_EXTENSION;
 }
 
+static void
+gimp_brush_real_begin_use (GimpBrush *brush)
+{
+  brush->mask_cache =
+    gimp_brush_cache_new ((GDestroyNotify) temp_buf_free, 'M', 'm');
+
+  brush->pixmap_cache =
+    gimp_brush_cache_new ((GDestroyNotify) temp_buf_free, 'P', 'p');
+
+  brush->boundary_cache =
+    gimp_brush_cache_new ((GDestroyNotify) gimp_bezier_desc_free, 'B', 'b');
+}
+
+static void
+gimp_brush_real_end_use (GimpBrush *brush)
+{
+  g_object_unref (brush->mask_cache);
+  brush->mask_cache = NULL;
+
+  g_object_unref (brush->pixmap_cache);
+  brush->pixmap_cache = NULL;
+
+  g_object_unref (brush->boundary_cache);
+  brush->boundary_cache = NULL;
+}
+
 static GimpBrush *
 gimp_brush_real_select_brush (GimpBrush        *brush,
                               const GimpCoords *last_coords,
@@ -479,6 +509,29 @@ gimp_brush_get_standard (GimpContext *context)
   return standard_brush;
 }
 
+void
+gimp_brush_begin_use (GimpBrush *brush)
+{
+  g_return_if_fail (GIMP_IS_BRUSH (brush));
+
+  brush->use_count++;
+
+  if (brush->use_count == 1)
+    GIMP_BRUSH_GET_CLASS (brush)->begin_use (brush);
+}
+
+void
+gimp_brush_end_use (GimpBrush *brush)
+{
+  g_return_if_fail (GIMP_IS_BRUSH (brush));
+  g_return_if_fail (brush->use_count > 0);
+
+  brush->use_count--;
+
+  if (brush->use_count == 0)
+    GIMP_BRUSH_GET_CLASS (brush)->end_use (brush);
+}
+
 GimpBrush *
 gimp_brush_select_brush (GimpBrush        *brush,
                          const GimpCoords *last_coords,
@@ -736,44 +789,3 @@ gimp_brush_set_spacing (GimpBrush *brush,
       g_object_notify (G_OBJECT (brush), "spacing");
     }
 }
-
-void
-gimp_brush_begin_use (GimpBrush *brush)
-{
-  g_return_if_fail (GIMP_IS_BRUSH (brush));
-
-  brush->use_count++;
-
-  if (brush->use_count == 1)
-    {
-      brush->mask_cache =
-        gimp_brush_cache_new ((GDestroyNotify) temp_buf_free, 'M', 'm');
-
-      brush->pixmap_cache =
-        gimp_brush_cache_new ((GDestroyNotify) temp_buf_free, 'P', 'p');
-
-      brush->boundary_cache =
-        gimp_brush_cache_new ((GDestroyNotify) gimp_bezier_desc_free, 'B', 'b');
-    }
-}
-
-void
-gimp_brush_end_use (GimpBrush *brush)
-{
-  g_return_if_fail (GIMP_IS_BRUSH (brush));
-  g_return_if_fail (brush->use_count > 0);
-
-  brush->use_count--;
-
-  if (brush->use_count == 0)
-    {
-      g_object_unref (brush->mask_cache);
-      brush->mask_cache = NULL;
-
-      g_object_unref (brush->pixmap_cache);
-      brush->pixmap_cache = NULL;
-
-      g_object_unref (brush->boundary_cache);
-      brush->boundary_cache = NULL;
-    }
-}
diff --git a/app/core/gimpbrush.h b/app/core/gimpbrush.h
index 771b0af..f8af699 100644
--- a/app/core/gimpbrush.h
+++ b/app/core/gimpbrush.h
@@ -55,6 +55,8 @@ struct _GimpBrushClass
   GimpDataClass  parent_class;
 
   /*  virtual functions  */
+  void             (* begin_use)          (GimpBrush        *brush);
+  void             (* end_use)            (GimpBrush        *brush);
   GimpBrush      * (* select_brush)       (GimpBrush        *brush,
                                            const GimpCoords *last_coords,
                                            const GimpCoords *current_coords);
@@ -96,6 +98,9 @@ GimpData             * gimp_brush_new                (GimpContext      *context,
                                                       const gchar      *name);
 GimpData             * gimp_brush_get_standard       (GimpContext      *context);
 
+void                   gimp_brush_begin_use          (GimpBrush        *brush);
+void                   gimp_brush_end_use            (GimpBrush        *brush);
+
 GimpBrush            * gimp_brush_select_brush       (GimpBrush        *brush,
                                                       const GimpCoords *last_coords,
                                                       const GimpCoords *current_coords);
@@ -140,8 +145,5 @@ gint                   gimp_brush_get_spacing        (const GimpBrush  *brush);
 void                   gimp_brush_set_spacing        (GimpBrush        *brush,
                                                       gint              spacing);
 
-void                   gimp_brush_begin_use          (GimpBrush        *brush);
-void                   gimp_brush_end_use            (GimpBrush        *brush);
-
 
 #endif /* __GIMP_BRUSH_H__ */



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