[gegl] buffer: mark linear buffers to avoid COW



commit c539d0d528218d9a418e5ab373771847dcfea34e
Author: Ãyvind KolÃs <pippin gimp org>
Date:   Tue Apr 10 16:30:40 2012 +0200

    buffer: mark linear buffers to avoid COW
    
    Doing COW on GeglBuffers backed by linear buffers will not work, since it
    effectively might replace the initial allocated buffer with the new COW
    copy - removing assumptions the user of the API might have that the passed
    in buffer remains a valid way of accessing the data.
    
    A proper linear backend with real flushing to the underlying memory could
    fix this.

 gegl/buffer/gegl-buffer-access.c |   28 ++++++++--------------------
 gegl/buffer/gegl-buffer-linear.c |    8 +++++++-
 2 files changed, 15 insertions(+), 21 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-access.c b/gegl/buffer/gegl-buffer-access.c
index 13be852..1aa4970 100644
--- a/gegl/buffer/gegl-buffer-access.c
+++ b/gegl/buffer/gegl-buffer-access.c
@@ -1173,7 +1173,9 @@ gegl_buffer_copy2 (GeglBuffer          *src,
                                     GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE);
       read = gegl_buffer_iterator_add (i, src, src_rect, 0, src->soft_format,
                                        GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
-      while (gegl_buffer_iterator_next (i) && i->length > 0)
+      while (gegl_buffer_iterator_next (i) &&
+             i->length > 0 /* XXX: <- looks suspicious */
+             )
         babl_process (fish, i->data[read], i->data[0], i->length);
     }
 }
@@ -1200,6 +1202,9 @@ gegl_buffer_copy (GeglBuffer          *src,
 
 
   if (src->soft_format == dst->soft_format &&
+      src->tile_width == dst->tile_width  &&
+      src->tile_height == dst->tile_height &&
+      !g_object_get_data (dst, "is-linear") &&
       gegl_buffer_scan_compatible (src, src_rect->x, src_rect->y,
                                    dst, dst_rect->x, dst_rect->y))
     {
@@ -1344,26 +1349,9 @@ gegl_buffer_copy (GeglBuffer          *src,
                              dst, &right);
         }
       }
-      return;
-    }
-
-  fish = babl_fish (src->soft_format, dst->soft_format);
-
-    {
-      GeglRectangle dest_rect_r = *dst_rect;
-      GeglBufferIterator *i;
-      gint read;
-
-      dest_rect_r.width = src_rect->width;
-      dest_rect_r.height = src_rect->height;
-
-      i = gegl_buffer_iterator_new (dst, &dest_rect_r, 0, dst->soft_format, 
-                                    GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE);
-      read = gegl_buffer_iterator_add (i, src, src_rect, 0, src->soft_format,
-                                       GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
-      while (gegl_buffer_iterator_next (i))
-        babl_process (fish, i->data[read], i->data[0], i->length);
     }
+  else
+    gegl_buffer_copy2 (src, src_rect, dst, dst_rect);
 }
 
 void
diff --git a/gegl/buffer/gegl-buffer-linear.c b/gegl/buffer/gegl-buffer-linear.c
index a4cd108..23e56e1 100644
--- a/gegl/buffer/gegl-buffer-linear.c
+++ b/gegl/buffer/gegl-buffer-linear.c
@@ -18,6 +18,8 @@ gegl_buffer_linear_new2 (const GeglRectangle *extent,
                          const Babl          *format,
                          gint                 rowstride)
 {
+  GeglBuffer *buffer;
+
   if (extent==NULL)
     {
       g_error ("got a NULL extent");
@@ -33,7 +35,7 @@ gegl_buffer_linear_new2 (const GeglRectangle *extent,
    * requesting the correct parameters when creating the
    * buffer
    */
-  return g_object_new (GEGL_TYPE_BUFFER,
+  buffer = g_object_new (GEGL_TYPE_BUFFER,
                        "x",          extent->x,
                        "y",          extent->y,
                        "shift-x",    extent->x,
@@ -44,6 +46,10 @@ gegl_buffer_linear_new2 (const GeglRectangle *extent,
                        "tile-height", extent->height,
                        "format", format,
                        NULL);
+
+  g_object_set_data (buffer, "is-linear", (void*)0xf00);
+
+  return buffer;
 }
 
 GeglBuffer *



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