[gegl/pluggable-buffer] buffer: add API for pluggable buffers
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/pluggable-buffer] buffer: add API for pluggable buffers
- Date: Sun, 6 Feb 2011 23:07:32 +0000 (UTC)
commit 8c68df8948feb32cb5421cf9016beb3180dd6fb8
Author: �yvind Kolås <pippin gimp org>
Date: Mon Jan 24 22:20:49 2011 +0000
buffer: add API for pluggable buffers
gegl/Makefile.am | 4 ++
gegl/buffer/gegl-buffer-private.h | 64 +++++++++++++++++++++++
gegl/buffer/gegl-buffer-types.h | 9 +---
gegl/buffer/gegl-buffer.c | 89 ++++++++++++++++++++++++++++++---
gegl/buffer/gegl-buffer.h | 11 ++++
gegl/buffer/gegl-tile-backend-file.c | 6 +-
gegl/buffer/gegl-tile-backend-ram.c | 7 ---
gegl/buffer/gegl-tile-backend.c | 1 +
gegl/buffer/gegl-tile-backend.h | 14 +++--
gegl/buffer/gegl-tile-handler-chain.c | 1 +
gegl/buffer/gegl-tile-handler-empty.c | 4 ++
gegl/buffer/gegl-tile-handler-log.c | 1 +
gegl/buffer/gegl-tile-handler-zoom.c | 10 +++-
gegl/buffer/gegl-tile-handler.c | 1 +
gegl/buffer/gegl-tile-source.c | 1 +
gegl/buffer/gegl-tile-source.h | 26 ++++++---
gegl/buffer/gegl-tile-storage.c | 53 ++++---------------
gegl/buffer/gegl-tile-storage.h | 6 +--
gegl/buffer/gegl-tile.c | 56 ++++++++-------------
gegl/buffer/gegl-tile.h | 77 ++--------------------------
20 files changed, 245 insertions(+), 196 deletions(-)
---
diff --git a/gegl/Makefile.am b/gegl/Makefile.am
index bb161df..c9acc5a 100644
--- a/gegl/Makefile.am
+++ b/gegl/Makefile.am
@@ -36,6 +36,10 @@ GEGL_public_HEADERS = \
gegl-version.h \
buffer/gegl-buffer.h \
buffer/gegl-buffer-iterator.h \
+ buffer/gegl-buffer-backend.h \
+ buffer/gegl-tile.h \
+ buffer/gegl-tile-backend.h \
+ buffer/gegl-tile-source.h \
property-types/gegl-paramspecs.h \
property-types/gegl-color.h \
property-types/gegl-path.h \
diff --git a/gegl/buffer/gegl-buffer-private.h b/gegl/buffer/gegl-buffer-private.h
index 33a14e9..dec56e1 100644
--- a/gegl/buffer/gegl-buffer-private.h
+++ b/gegl/buffer/gegl-buffer-private.h
@@ -20,6 +20,7 @@
#ifndef __GEGL_BUFFER_PRIVATE_H__
#define __GEGL_BUFFER_PRIVATE_H__
+#include "gegl-buffer-types.h"
#include "gegl-buffer.h"
#include "gegl-sampler.h"
#include "gegl-tile-handler.h"
@@ -71,6 +72,8 @@ struct _GeglBuffer
gchar *alloc_stack_trace; /* Stack trace for allocation,
useful for debugging */
+
+ gpointer backend;
};
struct _GeglBufferClass
@@ -130,4 +133,65 @@ void gegl_buffer_sampler (GeglBuffer *buffer,
gpointer sampler);
+
+/* the instance size of a GeglTile is a bit large, and should if possible be
+ * trimmed down
+ */
+struct _GeglTile
+{
+ /* GObject parent_instance;*/
+ gint ref_count;
+
+ guchar *data; /* actual pixel data for tile, a linear buffer*/
+ gint size; /* The size of the linear buffer */
+
+ GeglTileStorage *tile_storage; /* the buffer from which this tile was
+ * retrieved needed for the tile to be able to
+ * store itself back (for instance when it is
+ * unreffed for the last time)
+ */
+ gint x, y, z;
+
+
+ guint rev; /* this tile revision */
+ guint stored_rev; /* what revision was we when we from tile_storage?
+ (currently set to 1 when loaded from disk */
+
+ gchar lock; /* number of times the tile is write locked
+ * should in theory just have the values 0/1
+ */
+ GMutex *mutex;
+
+ /* the shared list is a doubly linked circular list */
+ GeglTile *next_shared;
+ GeglTile *prev_shared;
+
+ void (*destroy_notify) (gpointer pixels,
+ gpointer data);
+ gpointer destroy_notify_data;
+};
+
+#ifndef __GEGL_TILE_C
+#define gegl_tile_get_data(tile) ((guchar*)((tile)->data))
+#endif // __GEGL_TILE_C
+
+
+/* computes the positive integer remainder (also for negative dividends)
+ */
+#define GEGL_REMAINDER(dividend, divisor) \
+ (((dividend) < 0) ? \
+ (divisor) - 1 - ((-((dividend) + 1)) % (divisor)) : \
+ (dividend) % (divisor))
+
+#define gegl_tile_offset(coordinate, stride) GEGL_REMAINDER((coordinate), (stride))
+
+/* helper function to compute tile indices and offsets for coordinates
+ * based on a tile stride (tile_width or tile_height)
+ */
+#define gegl_tile_indice(coordinate,stride) \
+ (((coordinate) >= 0)?\
+ (coordinate) / (stride):\
+ ((((coordinate) + 1) /(stride)) - 1))
+
+
#endif
diff --git a/gegl/buffer/gegl-buffer-types.h b/gegl/buffer/gegl-buffer-types.h
index 3e6d48f..756efdf 100644
--- a/gegl/buffer/gegl-buffer-types.h
+++ b/gegl/buffer/gegl-buffer-types.h
@@ -19,16 +19,9 @@
#ifndef __GEGL_BUFFER_TYPES_H__
#define __GEGL_BUFFER_TYPES_H__
-
-
-typedef struct _GeglTile GeglTile;
typedef struct _GeglTileClass GeglTileClass;
-typedef struct _GeglTileSource GeglTileSource;
-typedef struct _GeglTileSourceClass GeglTileSourceClass;
-
-typedef struct _GeglTileBackend GeglTileBackend;
-typedef struct _GeglTileBackendClass GeglTileBackendClass;
+#include "gegl-buffer-backend.h"
typedef struct _GeglTileHandler GeglTileHandler;
typedef struct _GeglTileHandlerClass GeglTileHandlerClass;
diff --git a/gegl/buffer/gegl-buffer.c b/gegl/buffer/gegl-buffer.c
index 99dfd50..2c585d8 100644
--- a/gegl/buffer/gegl-buffer.c
+++ b/gegl/buffer/gegl-buffer.c
@@ -55,6 +55,7 @@
#include "gegl-tile-storage.h"
#include "gegl-tile-backend.h"
#include "gegl-tile-backend-file.h"
+#include "gegl-tile-backend-ram.h"
#include "gegl-tile.h"
#include "gegl-tile-handler-cache.h"
#include "gegl-tile-handler-log.h"
@@ -107,7 +108,8 @@ enum
PROP_FORMAT,
PROP_PX_SIZE,
PROP_PIXELS,
- PROP_PATH
+ PROP_PATH,
+ PROP_BACKEND
};
enum {
@@ -199,6 +201,10 @@ gegl_buffer_get_property (GObject *gobject,
g_value_set_pointer (value, (void*)buffer->format); /* Eeeek? */
break;
+ case PROP_BACKEND:
+ g_value_set_pointer (value, buffer->backend);
+ break;
+
case PROP_X:
g_value_set_int (value, buffer->extent.x);
break;
@@ -293,6 +299,10 @@ gegl_buffer_set_property (GObject *gobject,
if (g_value_get_pointer (value))
buffer->format = g_value_get_pointer (value);
break;
+ case PROP_BACKEND:
+ if (g_value_get_pointer (value))
+ buffer->backend = g_value_get_pointer (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
@@ -488,7 +498,26 @@ gegl_buffer_constructor (GType type,
* source (this adds a redirection buffer in between for
* all "allocated from format", type buffers.
*/
- if (buffer->path && g_str_equal (buffer->path, "RAM"))
+ if (buffer->backend)
+ {
+ void *storage;
+
+ storage = gegl_tile_storage_new (buffer->backend);
+
+ source = g_object_new (GEGL_TYPE_BUFFER, "source", storage, NULL);
+
+ gegl_tile_handler_set_source ((GeglTileHandler*)(buffer), source);
+ g_object_unref (source);
+
+ g_signal_connect (storage, "changed",
+ G_CALLBACK(gegl_buffer_storage_changed), buffer);
+
+ g_assert (source);
+ backend = gegl_buffer_backend (GEGL_BUFFER (source));
+ g_assert (backend);
+ g_assert (backend == buffer->backend);
+ }
+ else if (buffer->path && g_str_equal (buffer->path, "RAM"))
{
source = GEGL_TILE_SOURCE (gegl_buffer_new_from_format (buffer->format,
buffer->extent.x,
@@ -512,10 +541,13 @@ gegl_buffer_constructor (GType type,
GeglBufferHeader *header;
void *storage;
- if (buffer->format)
- storage = gegl_tile_storage_new (-1, -1, buffer->format, buffer->path);
- else
- storage = gegl_tile_storage_new (-1, -1, babl_format ("RGBA float"), buffer->path);
+ backend = g_object_new (GEGL_TYPE_TILE_BACKEND_FILE,
+ "tile-width", 128,
+ "tile-height", 64,
+ "format", buffer->format?buffer->format:babl_format ("RGBA float"),
+ "path", buffer->path,
+ NULL);
+ storage = gegl_tile_storage_new (backend);
source = g_object_new (GEGL_TYPE_BUFFER, "source", storage, NULL);
@@ -821,6 +853,11 @@ gegl_buffer_class_init (GeglBufferClass *class)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
+ g_object_class_install_property (gobject_class, PROP_BACKEND,
+ g_param_spec_pointer ("backend", "backend", "A custom tile-backend instance to use",
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT));
+
g_object_class_install_property (gobject_class, PROP_TILE_HEIGHT,
g_param_spec_int ("tile-height", "tile-height", "height of a tile",
-1, G_MAXINT, gegl_config()->tile_height,
@@ -988,6 +1025,29 @@ gegl_buffer_new (const GeglRectangle *extent,
NULL);
}
+GeglBuffer *
+gegl_buffer_new_for_backend (const GeglRectangle *extent,
+ const Babl *format,
+ gpointer backend)
+{
+ GeglRectangle empty={0,0,0,0};
+
+ if (extent==NULL)
+ extent = ∅
+
+ if (format==NULL)
+ format = babl_format ("RGBA float");
+
+ return g_object_new (GEGL_TYPE_BUFFER,
+ "x", extent->x,
+ "y", extent->y,
+ "width", extent->width,
+ "height", extent->height,
+ "format", format,
+ "backend", backend,
+ NULL);
+}
+
/* FIXME: this function needs optimizing, perhaps keep a pool
* of GeglBuffer shells that can be adapted to the needs
@@ -1110,12 +1170,19 @@ gegl_tile_storage_new_cached (gint tile_width, gint tile_height,
g_str_equal (gegl_config()->swap, "RAM") ||
g_str_equal (gegl_config()->swap, "ram"))
{
+ GeglTileBackend *backend;
item->ram = TRUE;
- storage = gegl_tile_storage_new (tile_width, tile_height, babl_fmt, NULL);
+ backend = g_object_new (GEGL_TYPE_TILE_BACKEND_RAM,
+ "tile-width", tile_width,
+ "tile-height", tile_height,
+ "format", babl_fmt,
+ NULL);
+ storage = gegl_tile_storage_new (backend);
}
else
{
static gint no = 1;
+ GeglTileBackend *backend;
gchar *filename;
gchar *path;
@@ -1133,7 +1200,13 @@ gegl_tile_storage_new_cached (gint tile_width, gint tile_height,
path = g_build_filename (gegl_config()->swap, filename, NULL);
g_free (filename);
- storage = gegl_tile_storage_new (tile_width, tile_height, babl_fmt, path);
+ backend = g_object_new (GEGL_TYPE_TILE_BACKEND_FILE,
+ "tile-width", tile_width,
+ "tile-height", tile_height,
+ "format", babl_fmt,
+ "path", path,
+ NULL);
+ storage = gegl_tile_storage_new (backend);
g_free (path);
}
item->storage = storage;
diff --git a/gegl/buffer/gegl-buffer.h b/gegl/buffer/gegl-buffer.h
index bee1c98..f15f926 100644
--- a/gegl/buffer/gegl-buffer.h
+++ b/gegl/buffer/gegl-buffer.h
@@ -57,6 +57,17 @@ GType gegl_buffer_get_type (void) G_GNUC_CONST;
GeglBuffer* gegl_buffer_new (const GeglRectangle *extent,
const Babl *format);
+GeglBuffer *
+gegl_buffer_new_custom (const GeglRectangle *extent,
+ const Babl *format,
+ GType backend,
+ gpointer backend_data);
+
+
+GeglBuffer *
+gegl_buffer_new_for_backend (const GeglRectangle *extent,
+ const Babl *format,
+ gpointer backend);
/**
* gegl_buffer_open:
diff --git a/gegl/buffer/gegl-tile-backend-file.c b/gegl/buffer/gegl-tile-backend-file.c
index 3c113cc..290745c 100644
--- a/gegl/buffer/gegl-tile-backend-file.c
+++ b/gegl/buffer/gegl-tile-backend-file.c
@@ -37,7 +37,7 @@
#include "gegl-tile-backend-file.h"
#include "gegl-buffer-index.h"
#include "gegl-debug.h"
-#include "gegl-types-internal.h"
+//#include "gegl-types-internal.h"
struct _GeglTileBackendFile
@@ -463,7 +463,7 @@ gegl_tile_backend_file_get_tile (GeglTileSource *self,
return NULL;
tile = gegl_tile_new (backend->tile_size);
- tile->rev = entry->rev;
+ gegl_tile_set_rev (tile, entry->rev);
gegl_tile_mark_as_stored (tile);
gegl_tile_backend_file_file_entry_read (tile_backend_file, entry, gegl_tile_get_data (tile));
@@ -493,7 +493,7 @@ gegl_tile_backend_file_set_tile (GeglTileSource *self,
entry->z = z;
g_hash_table_insert (tile_backend_file->index, entry, entry);
}
- entry->rev = tile->rev;
+ entry->rev = gegl_tile_get_rev (tile);
gegl_tile_backend_file_file_entry_write (tile_backend_file, entry, gegl_tile_get_data (tile));
gegl_tile_mark_as_stored (tile);
diff --git a/gegl/buffer/gegl-tile-backend-ram.c b/gegl/buffer/gegl-tile-backend-ram.c
index 1e335fd..d1869ca 100644
--- a/gegl/buffer/gegl-tile-backend-ram.c
+++ b/gegl/buffer/gegl-tile-backend-ram.c
@@ -25,16 +25,9 @@
#include "gegl-tile-backend.h"
#include "gegl-tile-backend-ram.h"
-
static void dbg_alloc (int size);
static void dbg_dealloc (int size);
-/* These entries are kept in RAM for now, they should be written as an index to the
- * swap file, at a position specified by a header block, making the header grow up
- * to a multiple of the size used in this swap file is probably a good idea
- *
- * Serializing the bablformat is probably also a good idea.
- */
typedef struct _RamEntry RamEntry;
struct _RamEntry
diff --git a/gegl/buffer/gegl-tile-backend.c b/gegl/buffer/gegl-tile-backend.c
index 2222aae..bf3b745 100644
--- a/gegl/buffer/gegl-tile-backend.c
+++ b/gegl/buffer/gegl-tile-backend.c
@@ -21,6 +21,7 @@
#include <string.h>
#include <babl/babl.h>
+#include "gegl-buffer-types.h"
#include "gegl-tile-source.h"
#include "gegl-tile-backend.h"
diff --git a/gegl/buffer/gegl-tile-backend.h b/gegl/buffer/gegl-tile-backend.h
index d26d702..aa29011 100644
--- a/gegl/buffer/gegl-tile-backend.h
+++ b/gegl/buffer/gegl-tile-backend.h
@@ -34,11 +34,13 @@ struct _GeglTileBackend
{
GeglTileSource parent_instance;
+ /* XXXX: all of this should be private? */
+
gint tile_width;
gint tile_height;
- Babl *format; /* defaults to the babl format "R'G'B'A u8" */
- gint px_size; /* size of a single pixel in bytes */
- gint tile_size; /* size of an entire tile in bytes */
+ Babl *format; /* defaults to the babl format "R'G'B'A u8" */
+ gint px_size; /* size of a single pixel in bytes */
+ gint tile_size; /* size of an entire tile in bytes */
/* private */
gpointer header;
@@ -50,8 +52,10 @@ struct _GeglTileBackendClass
{
GeglTileSourceClass parent_class;
- void (* create) (GeglTileBackend *backend);
- void (* destroy) (GeglTileBackend *backend);
+ gpointer padding1;
+ gpointer padding2;
+ gpointer padding3;
+ gpointer padding4;
};
GType gegl_tile_backend_get_type (void) G_GNUC_CONST;
diff --git a/gegl/buffer/gegl-tile-handler-chain.c b/gegl/buffer/gegl-tile-handler-chain.c
index 424eff1..c7815ba 100644
--- a/gegl/buffer/gegl-tile-handler-chain.c
+++ b/gegl/buffer/gegl-tile-handler-chain.c
@@ -20,6 +20,7 @@
#include <glib.h>
+#include "gegl-buffer-types.h"
#include "gegl-tile-handler-chain.h"
#include "gegl-tile-handler-cache.h"
diff --git a/gegl/buffer/gegl-tile-handler-empty.c b/gegl/buffer/gegl-tile-handler-empty.c
index de3a029..ff3d497 100644
--- a/gegl/buffer/gegl-tile-handler-empty.c
+++ b/gegl/buffer/gegl-tile-handler-empty.c
@@ -20,6 +20,10 @@
#include <glib-object.h>
#include <string.h>
+#include "gegl-types.h"
+#include "gegl-matrix.h"
+#include "gegl-buffer-types.h"
+#include "gegl-buffer-private.h"
#include "gegl-tile-handler.h"
#include "gegl-tile-handler-empty.h"
#include "gegl-tile-handler-cache.h"
diff --git a/gegl/buffer/gegl-tile-handler-log.c b/gegl/buffer/gegl-tile-handler-log.c
index 936cc67..58fc1d0 100644
--- a/gegl/buffer/gegl-tile-handler-log.c
+++ b/gegl/buffer/gegl-tile-handler-log.c
@@ -20,6 +20,7 @@
#include <glib-object.h>
#include <string.h>
+#include "gegl-buffer-types.h"
#include "gegl-tile-handler.h"
#include "gegl-tile-handler-log.h"
diff --git a/gegl/buffer/gegl-tile-handler-zoom.c b/gegl/buffer/gegl-tile-handler-zoom.c
index dc2f07d..4f8f2ff 100644
--- a/gegl/buffer/gegl-tile-handler-zoom.c
+++ b/gegl/buffer/gegl-tile-handler-zoom.c
@@ -20,6 +20,10 @@
#include <glib-object.h>
#include <string.h>
+#include "gegl-types.h"
+#include "gegl-matrix.h"
+#include "gegl-buffer-types.h"
+#include "gegl-buffer-private.h"
#include "gegl-tile-handler.h"
#include "gegl-tile-handler-zoom.h"
#include "gegl-tile-handler-cache.h"
@@ -255,9 +259,9 @@ get_tile (GeglTileSource *gegl_tile_source,
{
tile = gegl_tile_new (tile_size);
- tile->x = x;
- tile->y = y;
- tile->z = z;
+ tile->x = x;
+ tile->y = y;
+ tile->z = z;
tile->tile_storage = zoom->tile_storage;
if (zoom->cache)
diff --git a/gegl/buffer/gegl-tile-handler.c b/gegl/buffer/gegl-tile-handler.c
index e2b0642..601f770 100644
--- a/gegl/buffer/gegl-tile-handler.c
+++ b/gegl/buffer/gegl-tile-handler.c
@@ -22,6 +22,7 @@
#include <glib-object.h>
+#include "gegl-buffer-types.h"
#include "gegl-tile-source.h"
#include "gegl-tile-handler.h"
#include "gegl-tile-handler-chain.h"
diff --git a/gegl/buffer/gegl-tile-source.c b/gegl/buffer/gegl-tile-source.c
index d30de3d..3f56651 100644
--- a/gegl/buffer/gegl-tile-source.c
+++ b/gegl/buffer/gegl-tile-source.c
@@ -18,6 +18,7 @@
#include "config.h"
#include <glib.h>
#include <glib-object.h>
+#include "gegl-buffer-types.h"
#include "gegl-tile-source.h"
G_DEFINE_TYPE (GeglTileSource, gegl_tile_source, G_TYPE_OBJECT)
diff --git a/gegl/buffer/gegl-tile-source.h b/gegl/buffer/gegl-tile-source.h
index 85c6a5a..f5d1397 100644
--- a/gegl/buffer/gegl-tile-source.h
+++ b/gegl/buffer/gegl-tile-source.h
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU Lesser General Public
* License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
*
- * Copyright 2006 �yvind Kolås <pippin gimp org>
+ * Copyright 2006-2011 �yvind Kolås <pippin gimp org>
*/
#ifndef __GEGL_TILE_SOURCE_H__
@@ -21,7 +21,6 @@
#include <glib-object.h>
#include <babl/babl.h>
-#include "gegl-buffer-types.h"
#include "gegl-tile.h"
G_BEGIN_DECLS
@@ -39,16 +38,24 @@ struct _GeglTileSource
{
GObject parent_instance;
gpointer (*command) (GeglTileSource *gegl_tile_source,
- GeglTileCommand command,
- gint x,
- gint y,
- gint z,
- gpointer data);
+ GeglTileCommand command,
+ gint x,
+ gint y,
+ gint z,
+ gpointer data);
+ gpointer padding1;
+ gpointer padding2;
+ gpointer padding3;
+ gpointer padding4;
};
struct _GeglTileSourceClass
{
GObjectClass parent_class;
+ gpointer padding1;
+ gpointer padding2;
+ gpointer padding3;
+ gpointer padding4;
};
GType gegl_tile_source_get_type (void) G_GNUC_CONST;
@@ -61,7 +68,7 @@ GType gegl_tile_source_get_type (void) G_GNUC_CONST;
enum _GeglTileCommand
{
GEGL_TILE_IDLE = 0,
- GEGL_TILE_SET,
+ GEGL_TILE_SET,
GEGL_TILE_GET,
GEGL_TILE_IS_CACHED,
GEGL_TILE_EXIST,
@@ -72,6 +79,7 @@ enum _GeglTileCommand
};
#ifdef NOT_REALLY_COS_THIS_IS_MACROS
+/* The functions documented below are actually macros, all using the command vfunc */
/**
* gegl_tile_source_get_tile:
@@ -99,7 +107,7 @@ GeglTile *gegl_tile_source_get_tile (GeglTileSource *source,
* @z: tile zoom level
* @tile: a #GeglTile
*
- * Get a GeglTile *from the buffer.
+ * Set a GeglTile in *from the buffer.
*
* Returns: the TRUE if the set was successful.
*/
diff --git a/gegl/buffer/gegl-tile-storage.c b/gegl/buffer/gegl-tile-storage.c
index 43beda3..a5f0a1e 100644
--- a/gegl/buffer/gegl-tile-storage.c
+++ b/gegl/buffer/gegl-tile-storage.c
@@ -21,6 +21,7 @@
#include <glib-object.h>
#include "gegl.h"
+#include "gegl-buffer-types.h"
#include "gegl-tile-storage.h"
#include "gegl-tile.h"
#include "gegl-tile-backend-file.h"
@@ -66,66 +67,34 @@ tile_storage_idle (gpointer data)
GeglTileBackend *gegl_buffer_backend (GObject *buffer);
GeglTileStorage *
-gegl_tile_storage_new (gint tile_width,
- gint tile_height,
- const Babl *format,
- const gchar *path)
+gegl_tile_storage_new (GeglTileBackend *backend)
{
GeglTileStorage *tile_storage = g_object_new (GEGL_TYPE_TILE_STORAGE, NULL);
GeglTileHandlerChain *tile_handler_chain;
GeglTileHandler *handler;
- GeglTileBackend *backend = NULL;
GeglTileHandler *empty = NULL;
GeglTileHandler *zoom = NULL;
GeglTileHandlerCache *cache = NULL;
- if (tile_width <= 0)
- tile_width = 128;
- if (tile_height <= 0)
- tile_height = 64;
-
tile_storage->seen_zoom = 0;
tile_storage->mutex = g_mutex_new ();
tile_storage->width = G_MAXINT;
tile_storage->height = G_MAXINT;
- tile_storage->tile_width = tile_width;
- tile_storage->tile_height = tile_height;
- tile_storage->format = format;
- if (path)
- tile_storage->path = g_strdup (path);
-
- tile_handler_chain = GEGL_TILE_HANDLER_CHAIN (tile_storage);
- handler = GEGL_TILE_HANDLER (tile_storage);
- if (tile_storage->path != NULL)
+ if (g_object_class_find_property (G_OBJECT_GET_CLASS (backend), "path"))
{
-#if 1
- backend = g_object_new (GEGL_TYPE_TILE_BACKEND_FILE,
- "tile-width", tile_storage->tile_width,
- "tile-height", tile_storage->tile_height,
- "format", tile_storage->format,
- "path", tile_storage->path,
- NULL);
-#else
- backend = g_object_new (GEGL_TYPE_TILE_BACKEND_TILEDIR,
- "tile-width", tile_storage->tile_width,
- "tile-height", tile_storage->tile_height,
- "format", tile_storage->format,
- "path", tile_storage->path,
- NULL);
-#endif
- }
- else
- {
- backend = g_object_new (GEGL_TYPE_TILE_BACKEND_RAM,
- "tile-width", tile_storage->tile_width,
- "tile-height", tile_storage->tile_height,
- "format", tile_storage->format,
- NULL);
+ g_object_get (backend, "path", &tile_storage->path, NULL);
}
+ tile_handler_chain = GEGL_TILE_HANDLER_CHAIN (tile_storage);
+ handler = GEGL_TILE_HANDLER (tile_storage);
+
+ tile_storage->tile_width = backend->tile_width;
+ tile_storage->tile_height = backend->tile_height;
+ tile_storage->format = backend->format;
tile_storage->tile_size = backend->tile_size;
tile_storage->px_size = backend->px_size;
+
gegl_tile_handler_set_source (handler, (void*)backend);
{ /* should perhaps be a.. method on gegl_tile_handler_chain_set_source
diff --git a/gegl/buffer/gegl-tile-storage.h b/gegl/buffer/gegl-tile-storage.h
index e4d34ae..6d48e3f 100644
--- a/gegl/buffer/gegl-tile-storage.h
+++ b/gegl/buffer/gegl-tile-storage.h
@@ -53,10 +53,8 @@ struct _GeglTileStorageClass
};
GType gegl_tile_storage_get_type (void) G_GNUC_CONST;
+
GeglTileStorage *
-gegl_tile_storage_new (gint tile_width,
- gint tile_height,
- const Babl *format,
- const gchar *path);
+gegl_tile_storage_new (GeglTileBackend *backend);
#endif
diff --git a/gegl/buffer/gegl-tile.c b/gegl/buffer/gegl-tile.c
index 25af601..6215025 100644
--- a/gegl/buffer/gegl-tile.c
+++ b/gegl/buffer/gegl-tile.c
@@ -24,6 +24,8 @@
#include <unistd.h>
#endif
+#define __GEGL_TILE_C
+
#include <glib-object.h>
#include "gegl-types-internal.h"
@@ -261,41 +263,6 @@ gegl_tile_void (GeglTile *tile)
gegl_tile_void_pyramid (tile);
}
-void
-gegl_tile_cpy (GeglTile *src,
- GeglTile *dst)
-{
- gegl_tile_lock (dst);
-
- gegl_free (dst->data);
- dst->data = NULL;
-
- dst->next_shared = src->next_shared;
- src->next_shared = dst;
- dst->prev_shared = src;
- dst->next_shared->prev_shared = dst;
-
- dst->data = src->data;
-
- gegl_tile_unlock (dst);
-}
-
-void
-gegl_tile_swp (GeglTile *a,
- GeglTile *b)
-{
- guchar *tmp;
-
- gegl_tile_unclone (a);
- gegl_tile_unclone (b);
-
- g_assert (a->size == b->size);
-
- tmp = a->data;
- a->data = b->data;
- b->data = tmp;
-}
-
gboolean gegl_tile_store (GeglTile *tile)
{
if (gegl_tile_is_stored (tile))
@@ -308,3 +275,22 @@ gboolean gegl_tile_store (GeglTile *tile)
tile->z,
tile);
}
+
+/* for internal use, a macro poking directly at the data will be faster
+ */
+guchar *gegl_tile_get_data (GeglTile *tile)
+{
+ return tile->data;
+}
+
+
+void gegl_tile_set_rev (GeglTile *tile,
+ guint rev)
+{
+ tile->rev = rev;
+}
+
+guint gegl_tile_get_rev (GeglTile *tile)
+{
+ return tile->rev;
+}
diff --git a/gegl/buffer/gegl-tile.h b/gegl/buffer/gegl-tile.h
index 40e6df9..05d5469 100644
--- a/gegl/buffer/gegl-tile.h
+++ b/gegl/buffer/gegl-tile.h
@@ -20,52 +20,12 @@
#define __GEGL_TILE_H__
#include <glib-object.h>
-
-#include "gegl-buffer-types.h"
-
-/* the instance size of a GeglTile is a bit large, and should if possible be
- * trimmed down
- */
-struct _GeglTile
-{
- /* GObject parent_instance;*/
- gint ref_count;
-
- guchar *data; /* actual pixel data for tile, a linear buffer*/
- gint size; /* The size of the linear buffer */
-
- GeglTileStorage *tile_storage; /* the buffer from which this tile was
- * retrieved needed for the tile to be able to
- * store itself back (for instance when it is
- * unreffed for the last time)
- */
- gint x, y, z;
-
-
- guint rev; /* this tile revision */
- guint stored_rev; /* what revision was we when we from tile_storage?
- (currently set to 1 when loaded from disk */
-
- gchar lock; /* number of times the tile is write locked
- * should in theory just have the values 0/1
- */
- GMutex *mutex;
-
- /* the shared list is a doubly linked circular list */
- GeglTile *next_shared;
- GeglTile *prev_shared;
-
- void (*destroy_notify) (gpointer pixels,
- gpointer data);
- gpointer destroy_notify_data;
-};
+#include "gegl-buffer-backend.h"
GeglTile * gegl_tile_new (gint size);
GeglTile * gegl_tile_new_bare (void); /* special hack for linear bufs */
GeglTile * gegl_tile_ref (GeglTile *tile);
void gegl_tile_unref (GeglTile *tile);
-void * gegl_tile_get_format (GeglTile *tile);
-
/* lock a tile for writing, this would allow writing to buffers
* later gotten with get_data()
@@ -78,43 +38,16 @@ void gegl_tile_lock (GeglTile *tile);
void gegl_tile_unlock (GeglTile *tile);
-
void gegl_tile_mark_as_stored (GeglTile *tile);
gboolean gegl_tile_is_stored (GeglTile *tile);
gboolean gegl_tile_store (GeglTile *tile);
void gegl_tile_void (GeglTile *tile);
GeglTile *gegl_tile_dup (GeglTile *tile);
-/* utility low-level functions used by an undo system in horizon
- * where the geglbufer originated, kept around in case they
- * become useful again
- */
-void gegl_tile_swp (GeglTile *a,
- GeglTile *b);
-void gegl_tile_cpy (GeglTile *src,
- GeglTile *dst);
-
-
-/* computes the positive integer remainder (also for negative dividends)
- */
-#define GEGL_REMAINDER(dividend, divisor) \
- (((dividend) < 0) ? \
- (divisor) - 1 - ((-((dividend) + 1)) % (divisor)) : \
- (dividend) % (divisor))
-
-/* get a pointer to the linear buffer of the tile.
- */
-#define gegl_tile_get_data(tile) ((guchar*)((tile)->data))
-
-#define gegl_tile_offset(coordinate, stride) GEGL_REMAINDER((coordinate), (stride))
-
-/* helper function to compute tile indices and offsets for coordinates
- * based on a tile stride (tile_width or tile_height)
- */
-#define gegl_tile_indice(coordinate,stride) \
- (((coordinate) >= 0)?\
- (coordinate) / (stride):\
- ((((coordinate) + 1) /(stride)) - 1))
+void gegl_tile_set_rev (GeglTile *tile,
+ guint rev);
+guint gegl_tile_get_rev (GeglTile *tile);
+guchar *gegl_tile_get_data (GeglTile *tile);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]