[gegl] buffer: simplified construction of some of the gegl-tile-handlers
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] buffer: simplified construction of some of the gegl-tile-handlers
- Date: Tue, 20 Jul 2010 20:35:19 +0000 (UTC)
commit 66a42b21c3ef90d6978fa99be6c6c1d1eac53a1b
Author: �yvind Kolås <pippin gimp org>
Date: Tue Jul 20 01:39:51 2010 +0100
buffer: simplified construction of some of the gegl-tile-handlers
gegl/buffer/gegl-buffer-linear.c | 7 +--
gegl/buffer/gegl-tile-handler-cache.c | 6 ++
gegl/buffer/gegl-tile-handler-cache.h | 7 ++
gegl/buffer/gegl-tile-handler-chain.c | 7 ++-
gegl/buffer/gegl-tile-handler-empty.c | 120 ++++++--------------------------
gegl/buffer/gegl-tile-handler-empty.h | 10 ++-
gegl/buffer/gegl-tile-handler-zoom.c | 115 ++++---------------------------
gegl/buffer/gegl-tile-handler-zoom.h | 12 ++-
gegl/buffer/gegl-tile-handler.h | 4 +-
gegl/buffer/gegl-tile-storage.c | 24 +++----
gegl/buffer/gegl-tile-storage.h | 26 ++++---
11 files changed, 98 insertions(+), 240 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-linear.c b/gegl/buffer/gegl-buffer-linear.c
index 4c6f110..255e669 100644
--- a/gegl/buffer/gegl-buffer-linear.c
+++ b/gegl/buffer/gegl-buffer-linear.c
@@ -95,11 +95,8 @@ gegl_buffer_linear_new_from_data (const gpointer data,
tile->next_shared = tile;
tile->prev_shared = tile;
- {
- GeglTileHandlerCache *cache = g_object_get_data (G_OBJECT (buffer->tile_storage), "cache");
- if (cache)
- gegl_tile_handler_cache_insert (cache, tile, 0, 0, 0);
- }
+ if (buffer->tile_storage->cache)
+ gegl_tile_handler_cache_insert (buffer->tile_storage->cache, tile, 0, 0, 0);
gegl_tile_unref (tile);
}
diff --git a/gegl/buffer/gegl-tile-handler-cache.c b/gegl/buffer/gegl-tile-handler-cache.c
index d18eb05..a8345a7 100644
--- a/gegl/buffer/gegl-tile-handler-cache.c
+++ b/gegl/buffer/gegl-tile-handler-cache.c
@@ -513,3 +513,9 @@ gegl_tile_handler_cache_insert (GeglTileHandlerCache *cache,
}
g_static_mutex_unlock (&mutex);
}
+
+GeglTileHandlerCache *
+gegl_tile_handler_cache_new (void)
+{
+ return g_object_new (GEGL_TYPE_TILE_HANDLER_CACHE, NULL);
+}
diff --git a/gegl/buffer/gegl-tile-handler-cache.h b/gegl/buffer/gegl-tile-handler-cache.h
index 4fa3418..956b2dc 100644
--- a/gegl/buffer/gegl-tile-handler-cache.h
+++ b/gegl/buffer/gegl-tile-handler-cache.h
@@ -40,4 +40,11 @@ struct _GeglTileHandlerCacheClass
GType gegl_tile_handler_cache_get_type (void) G_GNUC_CONST;
+GeglTileHandlerCache *gegl_tile_handler_cache_new (void);
+void gegl_tile_handler_cache_insert (GeglTileHandlerCache *cache,
+ GeglTile *tile,
+ gint x,
+ gint y,
+ gint z);
+
#endif
diff --git a/gegl/buffer/gegl-tile-handler-chain.c b/gegl/buffer/gegl-tile-handler-chain.c
index 0401e51..5d598a6 100644
--- a/gegl/buffer/gegl-tile-handler-chain.c
+++ b/gegl/buffer/gegl-tile-handler-chain.c
@@ -63,7 +63,12 @@ dispose (GObject *object)
while (iter)
{
if (iter->data)
- g_object_unref (iter->data);
+ {
+ if (G_IS_OBJECT (iter->data))
+ g_object_unref (iter->data);
+ else
+ g_free (iter->data);
+ }
iter = iter->next;
}
diff --git a/gegl/buffer/gegl-tile-handler-empty.c b/gegl/buffer/gegl-tile-handler-empty.c
index 32280bf..515d492 100644
--- a/gegl/buffer/gegl-tile-handler-empty.c
+++ b/gegl/buffer/gegl-tile-handler-empty.c
@@ -26,12 +26,6 @@
G_DEFINE_TYPE (GeglTileHandlerEmpty, gegl_tile_handler_empty, GEGL_TYPE_TILE_HANDLER)
-enum
-{
- PROP_0,
- PROP_BACKEND
-};
-
static void
finalize (GObject *object)
{
@@ -43,11 +37,6 @@ finalize (GObject *object)
G_OBJECT_CLASS (gegl_tile_handler_empty_parent_class)->finalize (object);
}
-void gegl_tile_handler_cache_insert (GeglTileHandlerCache *cache,
- GeglTile *tile,
- gint x,
- gint y,
- gint z);
static GeglTile *
get_tile (GeglTileSource *gegl_tile_source,
@@ -68,84 +57,13 @@ get_tile (GeglTileSource *gegl_tile_source,
tile->x = x;
tile->y = y;
tile->z = z;
- {
- GeglTileHandlerCache *cache = g_object_get_data (G_OBJECT (gegl_tile_source), "cache");
- if (cache)
- gegl_tile_handler_cache_insert (cache, tile, x, y, z);
- }
-
- return tile;
-}
+ if (empty->cache)
+ gegl_tile_handler_cache_insert (empty->cache, tile, x, y, z);
-static void
-get_property (GObject *gobject,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GeglTileHandlerEmpty *empty = GEGL_TILE_HANDLER_EMPTY (gobject);
-
- switch (property_id)
- {
- case PROP_BACKEND:
- g_value_set_object (value, empty->backend);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
- break;
- }
-}
-
-static void
-set_property (GObject *gobject,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GeglTileHandlerEmpty *empty = GEGL_TILE_HANDLER_EMPTY (gobject);
-
- switch (property_id)
- {
- case PROP_BACKEND:
- empty->backend = g_value_get_object (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
- break;
- }
-}
-
-static GObject *
-constructor (GType type,
- guint n_params,
- GObjectConstructParam *params)
-{
- GObject *object;
- GeglTileHandlerEmpty *empty;
- gint tile_width;
- gint tile_height;
- gint tile_size;
-
- object = G_OBJECT_CLASS (gegl_tile_handler_empty_parent_class)->constructor (type, n_params, params);
-
- empty = GEGL_TILE_HANDLER_EMPTY (object);
-
- g_assert (empty->backend);
- g_object_get (empty->backend, "tile-width", &tile_width,
- "tile-height", &tile_height,
- "tile-size", &tile_size,
- NULL);
- /* FIXME: need babl format here */
- empty->tile = gegl_tile_new (tile_size);
- memset (gegl_tile_get_data (empty->tile), 0x00, tile_size);
-
- return object;
+ return tile;
}
-
static gpointer
gegl_tile_handler_empty_command (GeglTileSource *buffer,
GeglTileCommand command,
@@ -159,29 +77,37 @@ gegl_tile_handler_empty_command (GeglTileSource *buffer,
return gegl_tile_handler_chain_up (buffer, command, x, y, z, data);
}
-
static void
gegl_tile_handler_empty_class_init (GeglTileHandlerEmptyClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GeglTileSourceClass *source_class = GEGL_TILE_SOURCE_CLASS (klass);
- gobject_class->constructor = constructor;
gobject_class->finalize = finalize;
- gobject_class->set_property = set_property;
- gobject_class->get_property = get_property;
source_class->command = gegl_tile_handler_empty_command;
-
- g_object_class_install_property (gobject_class, PROP_BACKEND,
- g_param_spec_object ("backend",
- "backend",
- "backend for this tilestore (needed for tile size data)",
- G_TYPE_OBJECT,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY));
}
static void
gegl_tile_handler_empty_init (GeglTileHandlerEmpty *self)
{
}
+
+GeglTileHandler *
+gegl_tile_handler_empty_new (GeglTileBackend *backend,
+ GeglTileHandlerCache *cache)
+{
+ GeglTileHandlerEmpty *empty = g_object_new (GEGL_TYPE_TILE_HANDLER_EMPTY, NULL);
+ gint tile_width, tile_height, tile_size;
+ empty->backend = backend;
+ empty->cache = cache;
+
+ g_object_get (empty->backend, "tile-width", &tile_width,
+ "tile-height", &tile_height,
+ "tile-size", &tile_size,
+ NULL);
+ /* FIXME: need babl format here */
+ empty->tile = gegl_tile_new (tile_size);
+ memset (gegl_tile_get_data (empty->tile), 0x00, tile_size);
+
+ return (void*)empty;
+}
diff --git a/gegl/buffer/gegl-tile-handler-empty.h b/gegl/buffer/gegl-tile-handler-empty.h
index 5879fa0..d8b3c97 100644
--- a/gegl/buffer/gegl-tile-handler-empty.h
+++ b/gegl/buffer/gegl-tile-handler-empty.h
@@ -20,6 +20,7 @@
#define __GEGL_TILE_HANDLER_EMPTY_H__
#include "gegl-tile-handler.h"
+#include "gegl-tile-handler-cache.h"
G_BEGIN_DECLS
@@ -36,10 +37,11 @@ typedef struct _GeglTileHandlerEmptyClass GeglTileHandlerEmptyClass;
struct _GeglTileHandlerEmpty
{
- GeglTileHandler parent_instance;
+ GeglTileHandler parent_instance;
- GeglTile *tile;
- GeglTileBackend *backend;
+ GeglTile *tile;
+ GeglTileBackend *backend;
+ GeglTileHandlerCache *cache;
};
struct _GeglTileHandlerEmptyClass
@@ -48,6 +50,8 @@ struct _GeglTileHandlerEmptyClass
};
GType gegl_tile_handler_empty_get_type (void) G_GNUC_CONST;
+GeglTileHandler *gegl_tile_handler_empty_new (GeglTileBackend *backend,
+ GeglTileHandlerCache *cache);
G_END_DECLS
diff --git a/gegl/buffer/gegl-tile-handler-zoom.c b/gegl/buffer/gegl-tile-handler-zoom.c
index 06814cd..b9fb065 100644
--- a/gegl/buffer/gegl-tile-handler-zoom.c
+++ b/gegl/buffer/gegl-tile-handler-zoom.c
@@ -27,13 +27,6 @@
G_DEFINE_TYPE (GeglTileHandlerZoom, gegl_tile_handler_zoom, GEGL_TYPE_TILE_HANDLER)
-enum
-{
- PROP_0,
- PROP_TILE_STORAGE,
- PROP_BACKEND
-};
-
#include <babl/babl.h>
#include "gegl-tile-backend.h"
#include "gegl-tile-storage.h"
@@ -270,14 +263,8 @@ get_tile (GeglTileSource *gegl_tile_source,
tile->stored_rev = 1;
tile->rev = 1;
- {
- GeglTileHandlerCache *cache;
- cache = g_object_get_data (G_OBJECT (gegl_tile_source), "cache");
- if (cache)
- {
- gegl_tile_handler_cache_insert (cache, tile, x, y, z);
- }
- }
+ if (zoom->cache)
+ gegl_tile_handler_cache_insert (zoom->cache, tile, x, y, z);
}
gegl_tile_lock (tile);
data = gegl_tile_get_data (tile); /* XXX: is this needed? */
@@ -322,96 +309,11 @@ gegl_tile_handler_zoom_command (GeglTileSource *tile_store,
}
}
-
-static void
-get_property (GObject *gobject,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GeglTileHandlerZoom *zoom = GEGL_TILE_HANDLER_ZOOM (gobject);
-
- switch (property_id)
- {
- case PROP_TILE_STORAGE:
- g_value_set_object (value, zoom->tile_storage);
- break;
-
- case PROP_BACKEND:
- g_value_set_object (value, zoom->backend);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
- break;
- }
-}
-
-static void
-set_property (GObject *gobject,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GeglTileHandlerZoom *zoom = GEGL_TILE_HANDLER_ZOOM (gobject);
-
- switch (property_id)
- {
- case PROP_TILE_STORAGE:
- zoom->tile_storage = g_value_get_object (value);
- break;
-
- case PROP_BACKEND:
- zoom->backend = g_value_get_object (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
- break;
- }
-}
-
-static GObject *
-constructor (GType type,
- guint n_params,
- GObjectConstructParam *params)
-{
- GObject *object;
-
- object = G_OBJECT_CLASS (gegl_tile_handler_zoom_parent_class)->constructor (type, n_params, params);
-
- return object;
-}
-
-
static void
gegl_tile_handler_zoom_class_init (GeglTileHandlerZoomClass *klass)
{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GeglTileSourceClass *source_class = GEGL_TILE_SOURCE_CLASS (klass);
-
- gobject_class->constructor = constructor;
- gobject_class->set_property = set_property;
- gobject_class->get_property = get_property;
-
source_class->command = gegl_tile_handler_zoom_command;
-
- g_object_class_install_property (gobject_class, PROP_TILE_STORAGE,
- g_param_spec_object ("tile_storage",
- "tile_storage",
- "tile_storage for this tilestore (needed for tile size data)",
- G_TYPE_OBJECT,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY));
-
-
- g_object_class_install_property (gobject_class, PROP_BACKEND,
- g_param_spec_object ("backend",
- "backend",
- "backend for this tilestore (needed for tile size data)",
- G_TYPE_OBJECT,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY));
}
static void
@@ -420,3 +322,16 @@ gegl_tile_handler_zoom_init (GeglTileHandlerZoom *self)
self->backend = NULL;
self->tile_storage = NULL;
}
+
+GeglTileHandler *
+gegl_tile_handler_zoom_new (GeglTileBackend *backend,
+ GeglTileStorage *tile_storage,
+ GeglTileHandlerCache *cache)
+{
+ GeglTileHandlerZoom *ret = g_object_new (GEGL_TYPE_TILE_HANDLER_ZOOM,
+ NULL);
+ ret->backend = backend;
+ ret->tile_storage = tile_storage;
+ ret->cache = cache;
+ return (void*)ret;
+}
diff --git a/gegl/buffer/gegl-tile-handler-zoom.h b/gegl/buffer/gegl-tile-handler-zoom.h
index 400c824..a4e1ff4 100644
--- a/gegl/buffer/gegl-tile-handler-zoom.h
+++ b/gegl/buffer/gegl-tile-handler-zoom.h
@@ -20,6 +20,7 @@
#define __GEGL_TILE_HANDLER_ZOOM_H__
#include "gegl-tile-handler.h"
+#include "gegl-tile-handler-cache.h"
G_BEGIN_DECLS
@@ -36,10 +37,10 @@ typedef struct _GeglTileHandlerZoomClass GeglTileHandlerZoomClass;
struct _GeglTileHandlerZoom
{
- GeglTileHandler parent_instance;
-
- GeglTileBackend *backend;
- GeglTileStorage *tile_storage;
+ GeglTileHandler parent_instance;
+ GeglTileHandlerCache *cache;
+ GeglTileBackend *backend;
+ GeglTileStorage *tile_storage;
};
struct _GeglTileHandlerZoomClass
@@ -48,6 +49,9 @@ struct _GeglTileHandlerZoomClass
};
GType gegl_tile_handler_zoom_get_type (void) G_GNUC_CONST;
+GeglTileHandler *gegl_tile_handler_zoom_new (GeglTileBackend *backend,
+ GeglTileStorage *tile_storage,
+ GeglTileHandlerCache *cache);
G_END_DECLS
diff --git a/gegl/buffer/gegl-tile-handler.h b/gegl/buffer/gegl-tile-handler.h
index 57a8139..5b92f30 100644
--- a/gegl/buffer/gegl-tile-handler.h
+++ b/gegl/buffer/gegl-tile-handler.h
@@ -23,18 +23,16 @@
G_BEGIN_DECLS
-#define GEGL_TYPE_TILE_HANDLER (gegl_tile_handler_get_type ())
+#define GEGL_TYPE_TILE_HANDLER (gegl_tile_handler_get_type ())
#define GEGL_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEGL_TYPE_TILE_HANDLER, GeglTileHandler))
#define GEGL_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEGL_TYPE_TILE_HANDLER, GeglTileHandlerClass))
#define GEGL_IS_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEGL_TYPE_TILE_HANDLER))
#define GEGL_IS_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEGL_TYPE_TILE_HANDLER))
#define GEGL_HANDLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEGL_TYPE_TILE_HANDLER, GeglTileHandlerClass))
-
struct _GeglTileHandler
{
GeglTileSource parent_instance;
-
GeglTileSource *source; /* The source of the data, which we can rely on if
our command handler doesn't handle a command, this
is typically done with gegl_tile_handler_chain_up
diff --git a/gegl/buffer/gegl-tile-storage.c b/gegl/buffer/gegl-tile-storage.c
index fde7e6c..68a914c 100644
--- a/gegl/buffer/gegl-tile-storage.c
+++ b/gegl/buffer/gegl-tile-storage.c
@@ -185,9 +185,10 @@ gegl_tile_storage_constructor (GType type,
GeglTileStorage *tile_storage;
GeglTileHandlerChain *tile_handler_chain;
GeglTileHandler *handler;
+ GeglTileBackend *backend;
GeglTileHandler *empty = NULL;
GeglTileHandler *zoom = NULL;
- GeglTileHandler *cache = NULL;
+ GeglTileHandlerCache *cache = NULL;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
@@ -232,32 +233,25 @@ gegl_tile_storage_constructor (GType type,
NULL);
g_object_unref (handler->source); /* eeek */
+ backend = GEGL_TILE_BACKEND (handler->source);
if (g_getenv("GEGL_LOG_TILE_BACKEND")||
g_getenv("GEGL_TILE_LOG"))
gegl_tile_handler_chain_add (tile_handler_chain,
g_object_new (GEGL_TYPE_TILE_HANDLER_LOG, NULL));
- cache = g_object_new (GEGL_TYPE_TILE_HANDLER_CACHE,
- NULL);
- empty = g_object_new (GEGL_TYPE_TILE_HANDLER_EMPTY,
- "backend", handler->source,
- NULL);
- zoom = g_object_new (GEGL_TYPE_TILE_HANDLER_ZOOM,
- "backend", handler->source,
- "tile_storage", tile_storage,
- NULL);
-
- gegl_tile_handler_chain_add (tile_handler_chain, cache);
+ cache = gegl_tile_handler_cache_new ();
+ empty = gegl_tile_handler_empty_new (backend, cache);
+ zoom = gegl_tile_handler_zoom_new (backend, tile_storage, cache);
+
+ gegl_tile_handler_chain_add (tile_handler_chain, (void*)cache);
gegl_tile_handler_chain_add (tile_handler_chain, zoom);
gegl_tile_handler_chain_add (tile_handler_chain, empty);
if (g_getenv("GEGL_LOG_TILE_CACHE"))
gegl_tile_handler_chain_add (tile_handler_chain,
g_object_new (GEGL_TYPE_TILE_HANDLER_LOG, NULL));
- g_object_set_data (G_OBJECT (tile_storage), "cache", cache);
- g_object_set_data (G_OBJECT (empty), "cache", cache);
- g_object_set_data (G_OBJECT (zoom), "cache", cache);
+ tile_storage->cache = cache;
gegl_tile_handler_chain_bind (tile_handler_chain);
diff --git a/gegl/buffer/gegl-tile-storage.h b/gegl/buffer/gegl-tile-storage.h
index 887ee26..cc9d214 100644
--- a/gegl/buffer/gegl-tile-storage.h
+++ b/gegl/buffer/gegl-tile-storage.h
@@ -20,6 +20,7 @@
#define __GEGL_TILE_STORAGE_H__
#include "gegl-tile-handler-chain.h"
+#include "gegl-tile-handler-cache.h"
#define GEGL_TYPE_TILE_STORAGE (gegl_tile_storage_get_type ())
#define GEGL_TILE_STORAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEGL_TYPE_TILE_STORAGE, GeglTileStorage))
@@ -31,18 +32,19 @@
struct _GeglTileStorage
{
GeglTileHandlerChain parent_instance;
- GMutex *mutex;
- Babl *format;
- gint tile_width;
- gint tile_height;
- gint tile_size;
- gint px_size;
- gint width;
- gint height;
- gchar *path;
- gint seen_zoom; /* the maximum zoom level we've seen tiles for */
-
- guint idle_swapper;
+ GeglTileHandlerCache *cache;
+ GMutex *mutex;
+ Babl *format;
+ gint tile_width;
+ gint tile_height;
+ gint tile_size;
+ gint px_size;
+ gint width;
+ gint height;
+ gchar *path;
+ gint seen_zoom; /* the maximum zoom level we've seen tiles for */
+
+ guint idle_swapper;
};
struct _GeglTileStorageClass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]