[gimp] app: add gimp_brush_start_use() and gimp_brush_end_use()



commit e2226e9933cd37fcf494cab18d53563f982634a7
Author: Michael Natterer <mitch gimp org>
Date:   Tue Apr 5 19:18:26 2011 +0200

    app: add gimp_brush_start_use() and gimp_brush_end_use()
    
    and use them in GimpBrushCore when setting/unsetting a brush. They
    will be used for managing some caches inside GimpBrush.

 app/core/gimpbrush.c      |   22 ++++++++++++++++++++++
 app/core/gimpbrush.h      |    5 +++++
 app/paint/gimpbrushcore.c |    3 +++
 3 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/app/core/gimpbrush.c b/app/core/gimpbrush.c
index 9477a02..ceeafea 100644
--- a/app/core/gimpbrush.c
+++ b/app/core/gimpbrush.c
@@ -605,3 +605,25 @@ gimp_brush_set_spacing (GimpBrush *brush,
       g_object_notify (G_OBJECT (brush), "spacing");
     }
 }
+
+void
+gimp_brush_start_use (GimpBrush *brush)
+{
+  g_return_if_fail (GIMP_IS_BRUSH (brush));
+
+  brush->use_count++;
+}
+
+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)
+    {
+      /* flush caches */
+    }
+}
diff --git a/app/core/gimpbrush.h b/app/core/gimpbrush.h
index 90e9b62..45632fd 100644
--- a/app/core/gimpbrush.h
+++ b/app/core/gimpbrush.h
@@ -43,6 +43,8 @@ struct _GimpBrush
   gint          spacing;    /*  brush's spacing                */
   GimpVector2   x_axis;     /*  for calculating brush spacing  */
   GimpVector2   y_axis;     /*  for calculating brush spacing  */
+
+  gint          use_count;  /*  for keeping the caches alive   */
 };
 
 struct _GimpBrushClass
@@ -135,5 +137,8 @@ gint             gimp_brush_get_spacing        (const GimpBrush  *brush);
 void             gimp_brush_set_spacing        (GimpBrush        *brush,
                                                 gint              spacing);
 
+void             gimp_brush_start_use          (GimpBrush        *brush);
+void             gimp_brush_end_use            (GimpBrush        *brush);
+
 
 #endif /* __GIMP_BRUSH_H__ */
diff --git a/app/paint/gimpbrushcore.c b/app/paint/gimpbrushcore.c
index 841f461..0dcdd22 100644
--- a/app/paint/gimpbrushcore.c
+++ b/app/paint/gimpbrushcore.c
@@ -290,6 +290,7 @@ gimp_brush_core_finalize (GObject *object)
       g_signal_handlers_disconnect_by_func (core->main_brush,
                                             gimp_brush_core_invalidate_cache,
                                             core);
+      gimp_brush_end_use (core->main_brush);
       g_object_unref (core->main_brush);
       core->main_brush = NULL;
     }
@@ -867,6 +868,7 @@ gimp_brush_core_real_set_brush (GimpBrushCore *core,
       g_signal_handlers_disconnect_by_func (core->main_brush,
                                             gimp_brush_core_invalidate_cache,
                                             core);
+      gimp_brush_end_use (core->main_brush);
       g_object_unref (core->main_brush);
       core->main_brush = NULL;
     }
@@ -876,6 +878,7 @@ gimp_brush_core_real_set_brush (GimpBrushCore *core,
   if (core->main_brush)
     {
       g_object_ref (core->main_brush);
+      gimp_brush_start_use (core->main_brush);
       g_signal_connect (core->main_brush, "invalidate-preview",
                         G_CALLBACK (gimp_brush_core_invalidate_cache),
                         core);



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