[gimp/goat-invasion: 38/412] app: cache readable and writable buffers in the drawable



commit 8a8824ac7d62ff46e07dc556da8a63e0f280eb6b
Author: Michael Natterer <mitch gimp org>
Date:   Thu Mar 15 02:42:59 2012 +0100

    app: cache readable and writable buffers in the drawable
    
    As API, replace gimp_drawable_create_buffer() by
    gimp_drawable_get_read_buffer() and gimp_drawable_get_write_buffer().

 app/core/gimpdrawable-offset.c    |    3 +-
 app/core/gimpdrawable-operation.c |    3 +-
 app/core/gimpdrawable-private.h   |    3 +
 app/core/gimpdrawable.c           |   81 +++++++++++++++++++++++++------------
 app/core/gimpdrawable.h           |    4 +-
 app/core/gimpimagemap.c           |    8 +--
 app/core/gimplayer.c              |   10 +---
 app/core/gimpselection.c          |   17 +++-----
 8 files changed, 74 insertions(+), 55 deletions(-)
---
diff --git a/app/core/gimpdrawable-offset.c b/app/core/gimpdrawable-offset.c
index 7795069..b9e9472 100644
--- a/app/core/gimpdrawable-offset.c
+++ b/app/core/gimpdrawable-offset.c
@@ -93,7 +93,7 @@ gimp_drawable_offset (GimpDrawable   *drawable,
 
   new_tiles = tile_manager_new (width, height, gimp_drawable_bytes (drawable));
 
-  src_buffer  = gimp_drawable_create_buffer (drawable, FALSE);
+  src_buffer  = gimp_drawable_get_read_buffer (drawable);
   dest_buffer = gimp_tile_manager_create_buffer (new_tiles, TRUE);
 
   if (offset_x >= 0)
@@ -322,7 +322,6 @@ gimp_drawable_offset (GimpDrawable   *drawable,
         }
     }
 
-  g_object_unref (src_buffer);
   g_object_unref (dest_buffer);
 
   gimp_drawable_set_tiles (drawable, gimp_item_is_attached (item),
diff --git a/app/core/gimpdrawable-operation.c b/app/core/gimpdrawable-operation.c
index ff4e248..55843b1 100644
--- a/app/core/gimpdrawable-operation.c
+++ b/app/core/gimpdrawable-operation.c
@@ -180,7 +180,7 @@ gimp_drawable_apply_operation_private (GimpDrawable        *drawable,
                 "dont-cache", TRUE,
                 NULL);
 
-  inbuf  = gimp_drawable_create_buffer (drawable, FALSE);
+  inbuf  = gimp_drawable_get_read_buffer (drawable);
   outbuf = gimp_tile_manager_create_buffer (dest_tiles, TRUE);
 
   input  = gegl_node_new_child (gegl,
@@ -191,7 +191,6 @@ gimp_drawable_apply_operation_private (GimpDrawable        *drawable,
                                 "operation", "gegl:write-buffer",
                                 "buffer",    outbuf,
                                 NULL);
-  g_object_unref (inbuf);
   g_object_unref (outbuf);
 
   gegl_node_add_child (gegl, operation);
diff --git a/app/core/gimpdrawable-private.h b/app/core/gimpdrawable-private.h
index 3524bf1..3716f30 100644
--- a/app/core/gimpdrawable-private.h
+++ b/app/core/gimpdrawable-private.h
@@ -25,6 +25,9 @@ struct _GimpDrawablePrivate
   TileManager   *tiles;  /* tiles for drawable data */
   TileManager   *shadow; /* shadow buffer tiles     */
 
+  GeglBuffer    *read_buffer;
+  GeglBuffer    *write_buffer;
+
   GeglNode      *source_node;
   GeglNode      *tile_source_node;
 
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index e5d0534..d8d6fd0 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -301,6 +301,18 @@ gimp_drawable_finalize (GObject *object)
 
   gimp_drawable_free_shadow_tiles (drawable);
 
+  if (drawable->private->read_buffer)
+    {
+      g_object_unref (drawable->private->read_buffer);
+      drawable->private->read_buffer = NULL;
+    }
+
+  if (drawable->private->write_buffer)
+    {
+      g_object_unref (drawable->private->write_buffer);
+      drawable->private->write_buffer = NULL;
+    }
+
   if (drawable->private->source_node)
     {
       g_object_unref (drawable->private->source_node);
@@ -422,8 +434,6 @@ gimp_drawable_duplicate (GimpItem *item,
       GimpDrawable  *drawable     = GIMP_DRAWABLE (item);
       GimpDrawable  *new_drawable = GIMP_DRAWABLE (new_item);
       GimpImageType  image_type   = gimp_drawable_type (drawable);
-      GeglBuffer    *src;
-      GeglBuffer    *dest;
 
       new_drawable->private->type = image_type;
 
@@ -435,13 +445,8 @@ gimp_drawable_duplicate (GimpItem *item,
                           gimp_item_get_height (new_item),
                           gimp_drawable_bytes (new_drawable));
 
-      src  = gimp_drawable_create_buffer (drawable, FALSE);
-      dest = gimp_drawable_create_buffer (new_drawable, TRUE);
-
-      gegl_buffer_copy (src, NULL, dest, NULL);
-
-      g_object_unref (src);
-      g_object_unref (dest);
+      gegl_buffer_copy (gimp_drawable_get_read_buffer (drawable), NULL,
+                        gimp_drawable_get_write_buffer (new_drawable), NULL);
     }
 
   return new_item;
@@ -838,6 +843,18 @@ gimp_drawable_real_set_tiles (GimpDrawable *drawable,
   drawable->private->tiles = tiles;
   drawable->private->type  = type;
 
+  if (drawable->private->read_buffer)
+    {
+      g_object_unref (drawable->private->read_buffer);
+      drawable->private->read_buffer = NULL;
+    }
+
+  if (drawable->private->write_buffer)
+    {
+      g_object_unref (drawable->private->write_buffer);
+      drawable->private->write_buffer = NULL;
+    }
+
   gimp_item_set_offset (item, offset_x, offset_y);
   gimp_item_set_size (item,
                       tile_manager_width  (tiles),
@@ -847,14 +864,9 @@ gimp_drawable_real_set_tiles (GimpDrawable *drawable,
     gimp_drawable_alpha_changed (drawable);
 
   if (drawable->private->tile_source_node)
-    {
-      GeglBuffer *buffer = gimp_drawable_create_buffer (drawable, FALSE);
-
-      gegl_node_set (drawable->private->tile_source_node,
-                     "buffer", buffer,
-                     NULL);
-      g_object_unref (buffer);
-    }
+    gegl_node_set (drawable->private->tile_source_node,
+                   "buffer", gimp_drawable_get_read_buffer (drawable),
+                   NULL);
 }
 
 static GeglNode *
@@ -1471,16 +1483,38 @@ gimp_drawable_init_src_region (GimpDrawable  *drawable,
   *temp_tiles = NULL;
 }
 
-GeglBuffer *
+static GeglBuffer *
 gimp_drawable_create_buffer (GimpDrawable *drawable,
                              gboolean      write)
 {
-  g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
-
   return gimp_tile_manager_create_buffer (gimp_drawable_get_tiles (drawable),
                                           write);
 }
 
+GeglBuffer *
+gimp_drawable_get_read_buffer (GimpDrawable *drawable)
+{
+  g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
+
+  if (! drawable->private->read_buffer)
+    drawable->private->read_buffer = gimp_drawable_create_buffer (drawable,
+                                                                  FALSE);
+
+  return drawable->private->read_buffer;
+}
+
+GeglBuffer *
+gimp_drawable_get_write_buffer (GimpDrawable *drawable)
+{
+  g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
+
+  if (! drawable->private->write_buffer)
+    drawable->private->write_buffer = gimp_drawable_create_buffer (drawable,
+                                                                   TRUE);
+
+  return drawable->private->write_buffer;
+}
+
 TileManager *
 gimp_drawable_get_tiles (GimpDrawable *drawable)
 {
@@ -1559,7 +1593,6 @@ gimp_drawable_set_tiles_full (GimpDrawable  *drawable,
 GeglNode *
 gimp_drawable_get_source_node (GimpDrawable *drawable)
 {
-  GeglBuffer *buffer;
   g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
 
   if (drawable->private->source_node)
@@ -1567,16 +1600,12 @@ gimp_drawable_get_source_node (GimpDrawable *drawable)
 
   drawable->private->source_node = gegl_node_new ();
 
-  buffer = gimp_drawable_create_buffer (drawable, FALSE);
-
   drawable->private->tile_source_node =
     gegl_node_new_child (drawable->private->source_node,
                          "operation", "gegl:buffer-source",
-                         "buffer",    buffer,
+                         "buffer",    gimp_drawable_get_read_buffer (drawable),
                          NULL);
 
-  g_object_unref (buffer);
-
   gimp_drawable_sync_source_node (drawable, FALSE);
 
   return drawable->private->source_node;
diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h
index 821dd2c..7fd0353 100644
--- a/app/core/gimpdrawable.h
+++ b/app/core/gimpdrawable.h
@@ -178,8 +178,8 @@ void            gimp_drawable_init_src_region    (GimpDrawable       *drawable,
                                                   gint                height,
                                                   TileManager       **temp_tiles);
 
-GeglBuffer    * gimp_drawable_create_buffer      (GimpDrawable       *drawable,
-                                                  gboolean            write);
+GeglBuffer    * gimp_drawable_get_read_buffer    (GimpDrawable       *drawable);
+GeglBuffer    * gimp_drawable_get_write_buffer   (GimpDrawable       *drawable);
 
 TileManager   * gimp_drawable_get_tiles          (GimpDrawable       *drawable);
 void            gimp_drawable_set_tiles          (GimpDrawable       *drawable,
diff --git a/app/core/gimpimagemap.c b/app/core/gimpimagemap.c
index f9d1f27..1566358 100644
--- a/app/core/gimpimagemap.c
+++ b/app/core/gimpimagemap.c
@@ -660,12 +660,11 @@ gimp_image_map_update_undo_tiles (GimpImageMap        *image_map,
         }
 
       /*  Copy from the image to the new tiles  */
-      src = gimp_drawable_create_buffer (image_map->drawable, TRUE);
-      dest = gimp_tile_manager_create_buffer (image_map->undo_tiles, FALSE);
+      src = gimp_drawable_get_read_buffer (image_map->drawable);
+      dest = gimp_tile_manager_create_buffer (image_map->undo_tiles, TRUE);
 
       gegl_buffer_copy (src, rect, dest, &dest_rect);
 
-      g_object_unref (src);
       g_object_unref (dest);
 
       /*  Set the offsets  */
@@ -817,7 +816,7 @@ gimp_image_map_data_written (GObject             *operation,
       GeglRectangle  dest_rect;
 
       src = gimp_tile_manager_create_buffer (image_map->undo_tiles, FALSE);
-      dest = gimp_drawable_create_buffer (image_map->drawable, TRUE);
+      dest = gimp_drawable_get_write_buffer (image_map->drawable);
 
       src_rect.x      = extent->x - image_map->undo_offset_x;
       src_rect.y      = extent->y - image_map->undo_offset_y;
@@ -830,7 +829,6 @@ gimp_image_map_data_written (GObject             *operation,
       gegl_buffer_copy (src, &src_rect, dest, &dest_rect);
 
       g_object_unref (src);
-      g_object_unref (dest);
     }
 
   /* Apply the result of the gegl graph. */
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index 9c66a2d..934ea29 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -1200,9 +1200,8 @@ gimp_layer_new_from_buffer (GeglBuffer           *buffer,
                           type, name,
                           opacity, mode);
 
-  dest = gimp_drawable_create_buffer (GIMP_DRAWABLE (layer), TRUE);
+  dest = gimp_drawable_get_write_buffer (GIMP_DRAWABLE (layer));
   gegl_buffer_copy (buffer, NULL, dest, NULL);
-  g_object_unref (dest);
 
   return layer;
 }
@@ -1692,8 +1691,8 @@ gimp_layer_create_mask (const GimpLayer *layer,
             GeglRectangle  src_rect;
             GeglRectangle  dest_rect;
 
-            src  = gimp_drawable_create_buffer (GIMP_DRAWABLE (channel), FALSE);
-            dest = gimp_drawable_create_buffer (GIMP_DRAWABLE (mask), TRUE);
+            src  = gimp_drawable_get_read_buffer (GIMP_DRAWABLE (channel));
+            dest = gimp_drawable_get_write_buffer (GIMP_DRAWABLE (mask));
 
             src_rect.x      = copy_x;
             src_rect.y      = copy_y;
@@ -1705,9 +1704,6 @@ gimp_layer_create_mask (const GimpLayer *layer,
 
             gegl_buffer_copy (src, &src_rect, dest, &dest_rect);
 
-            g_object_unref (src);
-            g_object_unref (dest);
-
             GIMP_CHANNEL (mask)->bounds_known = FALSE;
           }
       }
diff --git a/app/core/gimpselection.c b/app/core/gimpselection.c
index 5e15f77..d67dfcb 100644
--- a/app/core/gimpselection.c
+++ b/app/core/gimpselection.c
@@ -564,10 +564,8 @@ void
 gimp_selection_load (GimpSelection *selection,
                      GimpChannel   *channel)
 {
-  GeglBuffer *src;
-  GeglBuffer *dest;
-  gint        width;
-  gint        height;
+  gint width;
+  gint height;
 
   g_return_if_fail (GIMP_IS_SELECTION (selection));
   g_return_if_fail (GIMP_IS_CHANNEL (channel));
@@ -582,13 +580,10 @@ gimp_selection_load (GimpSelection *selection,
                           C_("undo-type", "Channel to Selection"));
 
   /*  copy the channel to the mask  */
-  src  = gimp_drawable_create_buffer (GIMP_DRAWABLE (channel), FALSE);
-  dest = gimp_drawable_create_buffer (GIMP_DRAWABLE (selection), TRUE);
-
-  gegl_buffer_copy (src, NULL, dest, NULL);
-
-  g_object_unref (src);
-  g_object_unref (dest);
+  gegl_buffer_copy (gimp_drawable_get_read_buffer (GIMP_DRAWABLE (channel)),
+                    NULL,
+                    gimp_drawable_get_write_buffer (GIMP_DRAWABLE (selection)),
+                    NULL);
 
   GIMP_CHANNEL (selection)->bounds_known = FALSE;
 



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