gegl r2164 - in trunk: . gegl/buffer
- From: ok svn gnome org
- To: svn-commits-list gnome org
- Subject: gegl r2164 - in trunk: . gegl/buffer
- Date: Mon, 14 Apr 2008 20:57:12 +0100 (BST)
Author: ok
Date: Mon Apr 14 20:57:12 2008
New Revision: 2164
URL: http://svn.gnome.org/viewvc/gegl?rev=2164&view=rev
Log:
* gegl/buffer/gegl-handler.[ch]: added new gegl_handler_chain_up
method to abstract away the chain up call needed.
* gegl/buffer/gegl-handler-cache.c: (message): chain up
* gegl/buffer/gegl-handler-log.c: (get_tile), (message): chain up, and
update log messages.
* gegl/buffer/gegl-handler-zoom.c: (message): chain up
* gegl/buffer/gegl-handlers.h: s/TILE_TRAITS/HANDLERS/g
* gegl/buffer/gegl-storage.c: make it possible to enable logging
through environment variables.
* gegl/buffer/gegl-tile-gio.c: (message): added comment.
* gegl/buffer/gegl-buffer.[ch]: general cleanup
Modified:
trunk/ChangeLog
trunk/gegl/buffer/gegl-buffer.c
trunk/gegl/buffer/gegl-buffer.h
trunk/gegl/buffer/gegl-handler-cache.c
trunk/gegl/buffer/gegl-handler-log.c
trunk/gegl/buffer/gegl-handler-zoom.c
trunk/gegl/buffer/gegl-handler.c
trunk/gegl/buffer/gegl-handler.h
trunk/gegl/buffer/gegl-handlers.h
trunk/gegl/buffer/gegl-storage.c
trunk/gegl/buffer/gegl-tile-gio.c
Modified: trunk/gegl/buffer/gegl-buffer.c
==============================================================================
--- trunk/gegl/buffer/gegl-buffer.c (original)
+++ trunk/gegl/buffer/gegl-buffer.c Mon Apr 14 20:57:12 2008
@@ -41,9 +41,10 @@
#include "gegl-sampler-cubic.h"
#include "gegl-types.h"
#include "gegl-utils.h"
+#include "gegl-id-pool.h"
-G_DEFINE_TYPE (GeglBuffer, gegl_buffer, GEGL_TYPE_TILE_TRAITS)
+G_DEFINE_TYPE (GeglBuffer, gegl_buffer, GEGL_TYPE_HANDLERS)
#if ENABLE_MP
GStaticRecMutex mutex = G_STATIC_REC_MUTEX_INIT;
@@ -1832,7 +1833,9 @@
const GeglRectangle *extent)
{
g_return_val_if_fail (GEGL_IS_BUFFER (buffer), NULL);
- g_return_val_if_fail (extent != NULL, NULL);
+
+ if (extent == NULL)
+ extent = gegl_buffer_get_extent (buffer);
return g_object_new (GEGL_TYPE_BUFFER,
"provider", buffer,
@@ -1840,8 +1843,6 @@
"y", extent->y,
"width", extent->width,
"height", extent->height,
- /* "abyss-width", 0,
- "abyss-height", 0, */
NULL);
}
@@ -1930,3 +1931,86 @@
return GEGL_INTERPOLATION_NEAREST;
}
+
+static GeglIDPool *pool = NULL;
+
+guint
+gegl_buffer_share (GeglBuffer *buffer)
+{
+ guint id;
+ if (!pool)
+ pool = gegl_id_pool_new (16);
+ id = gegl_id_pool_add (pool, buffer);
+ /* FIXME: weak reference to void the handle when the buffer is
+ * finalized
+ */
+ return id;
+}
+
+#include <glib/gprintf.h>
+
+void
+gegl_buffer_make_uri (gchar *buf_128,
+ gchar *host,
+ gint port,
+ gint process,
+ gint handle)
+{
+ gchar *p=buf_128;
+
+ g_sprintf (p, "buffer://%s", host?host:"");
+ p+=strlen (p);
+ if (port)
+ {
+ g_sprintf (p, ":%i", port);
+ p+=strlen (p);
+ }
+ g_sprintf (p, "/");
+ p+=strlen (p);
+ if (process)
+ {
+ g_sprintf (p, "%i", process);
+ p+=strlen (p);
+ }
+ g_sprintf (p, "/");
+ p+=strlen (p);
+ if (handle || 1)
+ {
+ g_sprintf (p, "%i", handle);
+ p+=strlen (p);
+ }
+ else
+ {
+ g_warning ("no handle provided when building uri:\n%s\n", buf_128);
+ }
+}
+
+
+GeglBuffer*
+gegl_buffer_open (const gchar *uri)
+{
+ /* only supports local addresses for now */
+ guint process; /* self */
+ guint handle;
+
+ process = 0;
+ handle = 0;
+
+ if (!pool)
+ pool = gegl_id_pool_new (16);
+
+ if (!g_str_has_prefix (uri, "buffer://"))
+ {
+ g_warning ("'%s' does not start like a valid buffer handle", uri);
+ return NULL;
+ }
+ if (g_str_has_prefix (uri, "buffer:////"))
+ {
+ /* local buffer */
+ handle = atoi (uri + 11);
+ g_print ("got %i, %p\n", handle, gegl_id_pool_lookup (pool, handle));
+ return gegl_buffer_create_sub_buffer (gegl_id_pool_lookup (pool, handle), NULL);
+ }
+ g_warning ("don't know how to handle buffer path: %s", uri);
+ return NULL;
+}
Modified: trunk/gegl/buffer/gegl-buffer.h
==============================================================================
--- trunk/gegl/buffer/gegl-buffer.h (original)
+++ trunk/gegl/buffer/gegl-buffer.h Mon Apr 14 20:57:12 2008
@@ -54,6 +54,41 @@
GeglBuffer* gegl_buffer_new (const GeglRectangle *extent,
const Babl *format);
+
+/**
+ * gegl_buffer_share:
+ * @buffer: a #GeglBuffer.
+ *
+ * return a integer handle or 0 upon error, the handle returned is
+ * unique for this process on this host,
+ *
+ * An uri for this buffer can be constructed by gegl_buffer_make_uri.
+ *
+ * Returns: an integer handle for referring to this buffer.
+ */
+guint gegl_buffer_share (GeglBuffer *buffer);
+
+/**
+ * gegl_buffer_open:
+ * @uri: a uri referring to a local, other process or other host buffer to
+ * be opened.
+ *
+ * buffer://host:port/process/handle
+ * buffer:////42 handle 42 from same GEGL instance.
+ *
+ * Returns: a GeglBuffer object.
+ */
+
+GeglBuffer* gegl_buffer_open (const gchar *uri);
+
+
+void
+gegl_buffer_make_uri (gchar *buf_128,
+ gchar *host,
+ gint port,
+ gint process,
+ gint handle);
+
/**
* gegl_buffer_create_sub_buffer:
* @buffer: parent buffer.
Modified: trunk/gegl/buffer/gegl-handler-cache.c
==============================================================================
--- trunk/gegl/buffer/gegl-handler-cache.c (original)
+++ trunk/gegl/buffer/gegl-handler-cache.c Mon Apr 14 20:57:12 2008
@@ -144,7 +144,9 @@
{
gboolean is_cached = gegl_handler_cache_has_tile (cache, x, y, z);
if (is_cached)
- return TRUE;
+ return TRUE; /* XXX: perhaps we could return an integer/pointer
+ * value over the bus instead of a boolean?
+ */
/* otherwise pass on the request */
}
@@ -158,9 +160,7 @@
{
gegl_handler_cache_void (cache, x, y, z);
}
- if (handler->provider)
- return gegl_provider_message (handler->provider, message, x, y, z, data);
- return FALSE;
+ return gegl_handler_chain_up (handler, message, x, y, z, data);
}
static void
Modified: trunk/gegl/buffer/gegl-handler-log.c
==============================================================================
--- trunk/gegl/buffer/gegl-handler-log.c (original)
+++ trunk/gegl/buffer/gegl-handler-log.c Mon Apr 14 20:57:12 2008
@@ -26,14 +26,14 @@
static GeglTile *
get_tile (GeglProvider *gegl_provider,
- gint x,
- gint y,
- gint z)
+ gint x,
+ gint y,
+ gint z)
{
GeglProvider *provider = GEGL_HANDLER (gegl_provider)->provider;
GeglTile *tile = NULL;
- g_warning ("%p get_tile (%i,%i,%i)", (void *) gegl_provider, x, y, z);
+ g_print ("(get %p %i,%i,%i)", (void *) gegl_provider, x, y, z);
if (provider)
tile = gegl_provider_get_tile (provider, x, y, z);
@@ -43,8 +43,8 @@
static char *messages[] =
{
- "set", "is_dirty", "is_cached", "undo_start_group", "zoom_update", "dirty",
- "flush_dirty", "idle", "void", "last_message (or added to enum)", "eekmsg", "eekmsg"
+ "idle", "set", "is_cached", "exist", "void", "void tl", "void tr", "void bl",
+ "void br", "undo start group", "last message", "eeek", NULL
};
static gboolean
@@ -56,11 +56,20 @@
gpointer data)
{
GeglHandler *handler = GEGL_HANDLER (gegl_provider);
+ gboolean result = FALSE;
- g_warning ("%p message(%s, x=%i, y=%i, z=%i, data=%p)", (void *) gegl_provider, messages[message], x, y, z, data);
- if (handler->provider)
- return gegl_provider_message (handler->provider, message, x, y, z, data);
- return FALSE;
+ result = gegl_handler_chain_up (handler, message, x, y, z, data);
+
+ switch (message)
+ {
+ case GEGL_TILE_IDLE:
+ break;
+ default:
+ g_print ("(%s %p %p %i,%i,%i => %s)",
+ messages[message], (void *) gegl_provider, data, x, y, z,
+ result?"1":"0");
+ }
+ return result;
}
static void
Modified: trunk/gegl/buffer/gegl-handler-zoom.c
==============================================================================
--- trunk/gegl/buffer/gegl-handler-zoom.c (original)
+++ trunk/gegl/buffer/gegl-handler-zoom.c Mon Apr 14 20:57:12 2008
@@ -372,9 +372,7 @@
return FALSE;
}
/* pass the message on */
- if (handler->provider)
- return gegl_provider_message (handler->provider, message, x, y, z, data);
- return FALSE; /* pass it on */
+ return gegl_handler_chain_up (handler, message, x, y, z, data);
}
Modified: trunk/gegl/buffer/gegl-handler.c
==============================================================================
--- trunk/gegl/buffer/gegl-handler.c (original)
+++ trunk/gegl/buffer/gegl-handler.c Mon Apr 14 20:57:12 2008
@@ -66,7 +66,7 @@
}
static gboolean
-message (GeglProvider *gegl_provider,
+message (GeglProvider *gegl_provider,
GeglTileMessage message,
gint x,
gint y,
@@ -75,9 +75,7 @@
{
GeglHandler *handler = (GeglHandler*)gegl_provider;
- if (handler->provider)
- return gegl_provider_message (handler->provider, message, x, y, z, data);
- return FALSE;
+ return gegl_handler_chain_up (handler, message, x, y, z, data);
}
static void
@@ -118,7 +116,7 @@
/* special case if we are the Traits subclass of Trait
* also set the source at the end of the chain.
*/
- if (GEGL_IS_TILE_TRAITS (handler))
+ if (GEGL_IS_HANDLERS (handler))
{
GeglHandlers *handlers = GEGL_HANDLERS (handler);
GSList *iter = (void *) handlers->chain;
@@ -137,6 +135,19 @@
}
}
+gboolean gegl_handler_chain_up (GeglHandler *handler,
+ GeglTileMessage message,
+ gint x,
+ gint y,
+ gint z,
+ gpointer data)
+{
+ GeglProvider *provider = gegl_handler_get_provider (handler);
+ if (provider)
+ return gegl_provider_message (provider, message, x, y, z, data);
+ return FALSE;
+}
+
static void
gegl_handler_class_init (GeglHandlerClass *klass)
{
@@ -163,3 +174,5 @@
{
self->provider = NULL;
}
+
+
Modified: trunk/gegl/buffer/gegl-handler.h
==============================================================================
--- trunk/gegl/buffer/gegl-handler.h (original)
+++ trunk/gegl/buffer/gegl-handler.h Mon Apr 14 20:57:12 2008
@@ -47,6 +47,14 @@
#define gegl_handler_get_provider(handler) (((GeglHandler*)handler)->provider)
+
+gboolean gegl_handler_chain_up (GeglHandler *handler,
+ GeglTileMessage message,
+ gint x,
+ gint y,
+ gint z,
+ gpointer data);
+
G_END_DECLS
#endif
Modified: trunk/gegl/buffer/gegl-handlers.h
==============================================================================
--- trunk/gegl/buffer/gegl-handlers.h (original)
+++ trunk/gegl/buffer/gegl-handlers.h Mon Apr 14 20:57:12 2008
@@ -21,12 +21,12 @@
#include "gegl-handler.h"
-#define GEGL_TYPE_TILE_TRAITS (gegl_handlers_get_type ())
-#define GEGL_HANDLERS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEGL_TYPE_TILE_TRAITS, GeglHandlers))
-#define GEGL_HANDLERS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEGL_TYPE_TILE_TRAITS, GeglHandlersClass))
-#define GEGL_IS_TILE_TRAITS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEGL_TYPE_TILE_TRAITS))
-#define GEGL_IS_TILE_TRAITS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEGL_TYPE_TILE_TRAITS))
-#define GEGL_HANDLERS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEGL_TYPE_TILE_TRAITS, GeglHandlersClass))
+#define GEGL_TYPE_HANDLERS (gegl_handlers_get_type ())
+#define GEGL_HANDLERS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEGL_TYPE_HANDLERS, GeglHandlers))
+#define GEGL_HANDLERS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEGL_TYPE_HANDLERS, GeglHandlersClass))
+#define GEGL_IS_HANDLERS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEGL_TYPE_HANDLERS))
+#define GEGL_IS_HANDLERS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEGL_TYPE_HANDLERS))
+#define GEGL_HANDLERS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEGL_TYPE_HANDLERS, GeglHandlersClass))
struct _GeglHandlers
{
@@ -42,7 +42,17 @@
GType gegl_handlers_get_type (void) G_GNUC_CONST;
-/* NOTE: gegl_handlers_add steals the initial assumed reference */
+/**
+ * gegl_handlers_add:
+ * @handlers: a #GeglHandlers
+ * @handler: a #GeglHandler.
+ *
+ * Adds @handler to the list of handlers to be processed, the order handlers
+ * are added in is from original provider to last processing element, messages
+ * are passed from the last added to the first one in the chain.
+ *
+ * Returns: the added handler.
+ */
GeglHandler * gegl_handlers_add (GeglHandlers *handlers,
GeglHandler *handler);
Modified: trunk/gegl/buffer/gegl-storage.c
==============================================================================
--- trunk/gegl/buffer/gegl-storage.c (original)
+++ trunk/gegl/buffer/gegl-storage.c Mon Apr 14 20:57:12 2008
@@ -23,14 +23,15 @@
#include "gegl-storage.h"
#include "gegl-tile.h"
#include "gegl-tile-disk.h"
+#include "gegl-tile-mem.h"
+#include "gegl-tile-gio.h"
#include "gegl-handler-empty.h"
#include "gegl-handler-zoom.h"
-#include "gegl-tile-mem.h"
#include "gegl-handler-cache.h"
#include "gegl-handler-log.h"
-G_DEFINE_TYPE (GeglStorage, gegl_storage, GEGL_TYPE_TILE_TRAITS)
+G_DEFINE_TYPE (GeglStorage, gegl_storage, GEGL_TYPE_HANDLERS)
#define TILE_WIDTH 128
#define TILE_HEIGHT 64
@@ -175,6 +176,7 @@
GeglStorage *storage;
GeglHandlers *handlers;
GeglHandler *handler;
+ GeglHandler *cache = NULL;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
@@ -184,6 +186,7 @@
if (storage->path != NULL)
{
+#if 1
g_object_set (storage,
"provider", g_object_new (GEGL_TYPE_TILE_DISK,
"tile-width", storage->tile_width,
@@ -192,6 +195,16 @@
"path", storage->path,
NULL),
NULL);
+#else
+ g_object_set (storage,
+ "provider", g_object_new (GEGL_TYPE_TILE_GIO,
+ "tile-width", storage->tile_width,
+ "tile-height", storage->tile_height,
+ "format", storage->format,
+ "path", storage->path,
+ NULL),
+ NULL);
+#endif
}
else
{
@@ -209,31 +222,46 @@
"px-size", &storage->px_size,
NULL);
- if (1) gegl_handlers_add (handlers, g_object_new (GEGL_TYPE_HANDLER_CACHE,
- "size", 256,
- NULL));
+ if (g_getenv("GEGL_LOG_TILE_BACKEND"))
+ gegl_handlers_add (handlers, g_object_new (GEGL_TYPE_HANDLER_LOG, NULL));
+
+
+ /* FIXME: the cache should be made shared between all GeglStorages,
+ * to get a better gauge of memory use (ideally we would want to make
+ * to adapt to an approximate number of bytes to be allocated)
+ */
+ if (1)
+ cache = gegl_handlers_add (handlers, g_object_new (GEGL_TYPE_HANDLER_CACHE,
+ "size", 256,
+ NULL));
+ if (g_getenv("GEGL_LOG_TILE_CACHE"))
+ gegl_handlers_add (handlers, g_object_new (GEGL_TYPE_HANDLER_LOG, NULL));
- if (0) gegl_handlers_add (handlers, g_object_new (GEGL_TYPE_HANDLER_LOG,
- NULL));
if (1) gegl_handlers_add (handlers, g_object_new (GEGL_TYPE_HANDLER_ZOOM,
"backend", handler->provider,
"storage", storage,
NULL));
+ if (g_getenv("GEGL_LOG_TILE_ZOOM"))
+ gegl_handlers_add (handlers, g_object_new (GEGL_TYPE_HANDLER_LOG, NULL));
+
/* moved here to allow sharing between buffers (speeds up, but only
- * allows nulled (transparent) blank tiles,..
+ * allows nulled (transparent) blank tiles, or we would need a separate
+ * gegl-storage for each tile.
*/
if (1) gegl_handlers_add (handlers, g_object_new (GEGL_TYPE_HANDLER_EMPTY,
"backend", handler->provider,
NULL));
+ if (g_getenv("GEGL_LOG_TILE_EMPTY"))
+ gegl_handlers_add (handlers, g_object_new (GEGL_TYPE_HANDLER_LOG, NULL));
/* it doesn't really matter that empty tiles are not cached, since they
* are Copy on Write.
*/
storage->idle_swapper = g_timeout_add_full (G_PRIORITY_LOW,
- 250,
+ 500,
storage_idle,
storage,
NULL);
Modified: trunk/gegl/buffer/gegl-tile-gio.c
==============================================================================
--- trunk/gegl/buffer/gegl-tile-gio.c (original)
+++ trunk/gegl/buffer/gegl-tile-gio.c Mon Apr 14 20:57:12 2008
@@ -264,6 +264,7 @@
return set_tile (tile_store, data, x, y, z);
case GEGL_TILE_IDLE:
+ /* this backend has nothing to do on idle calls */
return FALSE;
case GEGL_TILE_VOID:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]