[gegl] buffer: add gegl_tile_handler_get[_source]_tile()



commit 4a2a74fdfe9aae6ba34302e7f9bb45a41762b94e
Author: Ell <ell_se yahoo com>
Date:   Tue Jan 1 14:27:10 2019 -0500

    buffer: add gegl_tile_handler_get[_source]_tile()
    
    In GeglTileHandler, add new gegl_tile_handler_get[_source]_tile()
    functions, which fetch a tile with a given coordinates from the
    tile handler (or its source).  If the tile doesn't exist, these
    functions return a newly-created tile.
    
    The functions take an additional preserve_data argument.  When it
    is FALSE, the existing tile data doesn't have to be preserved,
    which allow us to perform several optimizations:  Instead of trying
    to fetch the tile using a TILE_GET command, we look up the tile in
    the cache.  If the tile is not in the cache, we return a new tile
    -- this avoids unnecesarily reading the tile from the storage, or
    generating it.  If the tile is in the cache, we fully damage it, so
    that if it's uncloned, its existing data won't be copied (see last
    commit).

 gegl/buffer/gegl-buffer.c             |  5 ++++
 gegl/buffer/gegl-tile-handler-cache.c |  6 +---
 gegl/buffer/gegl-tile-handler-cache.h |  4 +++
 gegl/buffer/gegl-tile-handler.c       | 54 +++++++++++++++++++++++++++++++++++
 gegl/buffer/gegl-tile-handler.h       | 43 ++++++++++++++++++++++++++++
 5 files changed, 107 insertions(+), 5 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer.c b/gegl/buffer/gegl-buffer.c
index b922066cb..ad09c972d 100644
--- a/gegl/buffer/gegl-buffer.c
+++ b/gegl/buffer/gegl-buffer.c
@@ -42,6 +42,8 @@
 #include "gegl-buffer-config.h"
 #include "gegl-buffer-private.h"
 #include "gegl-rectangle.h"
+#include "gegl-tile-handler-cache.h"
+#include "gegl-tile-handler-private.h"
 #include "gegl-tile-storage.h"
 #include "gegl-tile-backend-file.h"
 #include "gegl-tile-backend-swap.h"
@@ -691,6 +693,9 @@ gegl_buffer_constructor (GType                  type,
 
   buffer->tile_storage = gegl_buffer_tile_storage (buffer);
 
+  _gegl_tile_handler_set_tile_storage (handler, buffer->tile_storage);
+  _gegl_tile_handler_set_cache (handler, buffer->tile_storage->cache);
+
   /* intialize the soft format to be equivalent to the actual
    * format, unless the soft format was copied from a source buffer
    */
diff --git a/gegl/buffer/gegl-tile-handler-cache.c b/gegl/buffer/gegl-tile-handler-cache.c
index 85487279d..2ff894bc9 100644
--- a/gegl/buffer/gegl-tile-handler-cache.c
+++ b/gegl/buffer/gegl-tile-handler-cache.c
@@ -66,10 +66,6 @@ static gpointer   gegl_tile_handler_cache_command    (GeglTileSource           *
                                                       gint                      y,
                                                       gint                      z,
                                                       gpointer                  data);
-static GeglTile * gegl_tile_handler_cache_get_tile   (GeglTileHandlerCache     *cache,
-                                                      gint                      x,
-                                                      gint                      y,
-                                                      gint                      z);
 static gboolean   gegl_tile_handler_cache_has_tile   (GeglTileHandlerCache     *cache,
                                                       gint                      x,
                                                       gint                      y,
@@ -463,7 +459,7 @@ cache_lookup (GeglTileHandlerCache *cache,
 
 /* returns the requested Tile if it is in the cache, NULL otherwize.
  */
-static GeglTile *
+GeglTile *
 gegl_tile_handler_cache_get_tile (GeglTileHandlerCache *cache,
                                   gint                  x,
                                   gint                  y,
diff --git a/gegl/buffer/gegl-tile-handler-cache.h b/gegl/buffer/gegl-tile-handler-cache.h
index d3447326d..6056337c0 100644
--- a/gegl/buffer/gegl-tile-handler-cache.h
+++ b/gegl/buffer/gegl-tile-handler-cache.h
@@ -68,6 +68,10 @@ void              gegl_tile_handler_cache_remove             (GeglTileHandlerCac
                                                               gint                  x,
                                                               gint                  y,
                                                               gint                  z);
+GeglTile        * gegl_tile_handler_cache_get_tile           (GeglTileHandlerCache *cache,
+                                                              gint                  x,
+                                                              gint                  y,
+                                                              gint                  z);
 void              gegl_tile_handler_cache_tile_uncloned      (GeglTileHandlerCache *cache,
                                                               GeglTile             *tile);
 
diff --git a/gegl/buffer/gegl-tile-handler.c b/gegl/buffer/gegl-tile-handler.c
index 1748d38ef..2c2f3b38f 100644
--- a/gegl/buffer/gegl-tile-handler.c
+++ b/gegl/buffer/gegl-tile-handler.c
@@ -203,6 +203,60 @@ gegl_tile_handler_create_tile (GeglTileHandler *handler,
   return tile;
 }
 
+static GeglTile *
+gegl_tile_handler_get_tile_internal (GeglTileHandler *handler,
+                                     GeglTileSource  *source,
+                                     gint             x,
+                                     gint             y,
+                                     gint             z,
+                                     gboolean         preserve_data)
+{
+  GeglTile *tile = NULL;
+
+  if (preserve_data && source)
+    {
+      tile = gegl_tile_source_command (source, GEGL_TILE_GET, x, y, z, NULL);
+    }
+  else if (handler->priv->cache)
+    {
+      tile = gegl_tile_handler_cache_get_tile (handler->priv->cache, x, y, z);
+
+      if (tile)
+        tile->damage = ~(guint64) 0;
+    }
+
+  if (! tile)
+    tile = gegl_tile_handler_create_tile (handler, x, y, z);
+
+  return tile;
+}
+
+GeglTile *
+gegl_tile_handler_get_tile (GeglTileHandler *handler,
+                            gint             x,
+                            gint             y,
+                            gint             z,
+                            gboolean         preserve_data)
+{
+  return gegl_tile_handler_get_tile_internal (handler,
+                                              GEGL_TILE_SOURCE (handler),
+                                              x, y, z,
+                                              preserve_data);
+}
+
+GeglTile *
+gegl_tile_handler_get_source_tile (GeglTileHandler *handler,
+                                   gint             x,
+                                   gint             y,
+                                   gint             z,
+                                   gboolean         preserve_data)
+{
+  return gegl_tile_handler_get_tile_internal (handler,
+                                              handler->source,
+                                              x, y, z,
+                                              preserve_data);
+}
+
 GeglTile *
 gegl_tile_handler_dup_tile (GeglTileHandler *handler,
                             GeglTile        *tile,
diff --git a/gegl/buffer/gegl-tile-handler.h b/gegl/buffer/gegl-tile-handler.h
index 2134c1f38..87579849d 100644
--- a/gegl/buffer/gegl-tile-handler.h
+++ b/gegl/buffer/gegl-tile-handler.h
@@ -83,6 +83,49 @@ GeglTile * gegl_tile_handler_create_tile (GeglTileHandler *handler,
                                           gint             y,
                                           gint             z);
 
+/**
+ * gegl_tile_handler_get_tile: (skip)
+ * @handler: a #GeglTileHandler
+ * @x: The tile space x coordinate for the tile
+ * @y: The tile space y coordinate for the tile
+ * @z: The tile space z coordinate for the tile
+ * @preserve_data: whether existing tile data should be preserved
+ *
+ * Fetches the tile at the given coordinates from @handler.  If the tile
+ * doesn't exist, creates a new tile associated with this tile handler.
+ *
+ * If @preserve_data is FALSE, the tile contents are unspecified.
+ *
+ * Return value: the tile
+ */
+GeglTile * gegl_tile_handler_get_tile (GeglTileHandler *handler,
+                                       gint             x,
+                                       gint             y,
+                                       gint             z,
+                                       gboolean         preserve_data);
+
+/**
+ * gegl_tile_handler_get_source_tile: (skip)
+ * @handler: a #GeglTileHandler
+ * @x: The tile space x coordinate for the tile
+ * @y: The tile space y coordinate for the tile
+ * @z: The tile space z coordinate for the tile
+ * @preserve_data: whether existing tile data should be preserved
+ *
+ * Fetches the tile at the given coordinates from @handler source.  If the tile
+ * doesn't exist, or if @handler doesn't have a source, creates a new tile
+ * associated with this tile handler.
+ *
+ * If @preserve_data is FALSE, the tile contents are unspecified.
+ *
+ * Return value: the tile
+ */
+GeglTile * gegl_tile_handler_get_source_tile (GeglTileHandler *handler,
+                                              gint             x,
+                                              gint             y,
+                                              gint             z,
+                                              gboolean         preserve_data);
+
 /**
  * gegl_tile_handler_dup_tile: (skip)
  * @handler: a #GeglTileHandler


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