[gegl] buffer: add GEGL_TILE_COPY tile-source command



commit c5045711164ee44b0ce9e585e98266a3e6cbb9da
Author: Ell <ell_se yahoo com>
Date:   Tue Aug 14 10:00:31 2018 -0400

    buffer: add GEGL_TILE_COPY tile-source command
    
    GEGL_TILE_COPY requests a tile source to copy a tile to a given
    destination buffer (or to the same buffer to which the tile source
    belongs), at given destination tile coordinates.  The tile source
    and the destination buffer are assumed to be tile-compatible (i.e.,
    having the same tile dimensions and format).  The tile source
    should return a boolean value, indicating whether the tile has been
    copied.
    
    This is mostly meant to be implemented by the cache handler, and by
    tile backends (the swap backend, in particular).  It allows
    backends to implement a cheap copy operation, avoiding the need to
    actually fetch the tile.  For example, at the moment, copying a
    swapped-out tile between two buffers, both of which are using the
    swap backend, requires reading the tile from disk into memory
    first, only to COW the result.  This might not be an issue if the
    same tile is known to be accessed shortly after, but when doing a
    tentative copy, usually of an entire buffer (as is done in GIMP in
    several cases), this incurs a very noticeable overhead.

 gegl/buffer/gegl-buffer-backend.h | 10 ++++++++++
 gegl/buffer/gegl-tile-source.h    | 40 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)
---
diff --git a/gegl/buffer/gegl-buffer-backend.h b/gegl/buffer/gegl-buffer-backend.h
index 8c486bf0f..b2cee230f 100644
--- a/gegl/buffer/gegl-buffer-backend.h
+++ b/gegl/buffer/gegl-buffer-backend.h
@@ -46,9 +46,19 @@ typedef enum
   GEGL_TILE_FLUSH,
   GEGL_TILE_REFETCH,
   GEGL_TILE_REINIT,
+  GEGL_TILE_COPY,
   GEGL_TILE_LAST_COMMAND
 } GeglTileCommand;
 
+typedef struct _GeglTileCopyParams
+{
+  GeglBuffer *dst_buffer;
+
+  gint        dst_x;
+  gint        dst_y;
+  gint        dst_z;
+} GeglTileCopyParams;
+
 G_END_DECLS
 
 #include "gegl-tile-backend.h"
diff --git a/gegl/buffer/gegl-tile-source.h b/gegl/buffer/gegl-tile-source.h
index 74166fc32..5009f50d6 100644
--- a/gegl/buffer/gegl-tile-source.h
+++ b/gegl/buffer/gegl-tile-source.h
@@ -200,6 +200,46 @@ gegl_tile_source_void (GeglTileSource *source,
   gegl_tile_source_command (source, GEGL_TILE_VOID, x, y, z, NULL);
 }
 
+/**
+ * gegl_tile_source_copy:
+ * @source: a GeglTileSource *
+ * @x: x coordinate
+ * @y: y coordinate
+ * @z: tile zoom level
+ * @dst_buffer: destination buffer, or #NULL
+ * @dst_x: x coordinate of destination tile
+ * @dst_y: y coordinate of destination tile
+ * @dst_z: z coordinate of destination tile
+ *
+ * Copies a tile from @source to @dst_buffer, or, if @dst_buffer is #NULL, to
+ * the buffer @source belongs to.
+ *
+ * Returns: #TRUE if the tile was copied.
+ */
+static inline gboolean
+gegl_tile_source_copy (GeglTileSource *source,
+                       gint            x,
+                       gint            y,
+                       gint            z,
+                       GeglBuffer     *dst_buffer,
+                       gint            dst_x,
+                       gint            dst_y,
+                       gint            dst_z)
+{
+  GeglTileCopyParams params;
+
+  params.dst_buffer = dst_buffer;
+
+  params.dst_x      = dst_x;
+  params.dst_y      = dst_y;
+  params.dst_z      = dst_z;
+
+  if (gegl_tile_source_command (source, GEGL_TILE_COPY, x, y, z, &params))
+    return TRUE;
+  else
+    return FALSE;
+}
+
 /*    INTERNAL API
  * gegl_tile_source_refetch:
  * @source: a GeglTileSource *


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