Commit 5ac10664 authored by Øyvind Kolås's avatar Øyvind Kolås

Made the process methods of operations take a GeglNodeContext instead

of a context_id, this GeglNodeContext contains the logic to perform
concurrent bookkeeping of data on pads of nodes.
* gegl/gegl-chant.h:
* gegl/graph/gegl-node-context.[ch]:
* gegl/operation/gegl-operation-composer.[ch]:
* gegl/operation/gegl-operation-filter.[ch]:
* gegl/operation/gegl-operation-point-composer.c:
* gegl/operation/gegl-operation-point-filter.c:
* gegl/operation/gegl-operation-sink.[ch]:
* gegl/operation/gegl-operation-source.[ch]:
* gegl/operation/gegl-operation.c:
* gegl/operation/gegl-operation.h:
* gegl/process/gegl-eval-visitor.c:
* gegl/process/gegl-processor.c:
* operations/affine/affine.c:
* operations/blur/box-blur.c:
* operations/blur/gaussian-blur.c:
* operations/color/mono-mixer.c:
* operations/color/remap.c:
* operations/color/stretch-contrast.c:
* operations/core/clone.c:
* operations/core/crop.c:
* operations/core/nop.c:
* operations/core/shift.c:
* operations/enhance/bilateral-filter.c:
* operations/enhance/snn-mean.c:
* operations/io/display.c:
* operations/io/exr-load.cpp:
* operations/io/ff-load.c:
* operations/io/jpg-load.c:
* operations/io/load-buffer.c:
* operations/io/magick-load.c:
* operations/io/pixbuf.c:
* operations/io/png-load.c:
* operations/io/png-save.c:
* operations/io/raw-load.c:
* operations/io/save-buffer.c:
* operations/io/save-pixbuf.c:
* operations/io/svg-load.c:
* operations/render/FractalExplorer.c:
* operations/render/checkerboard.c:
* operations/render/color.c:
* operations/render/introspect.c:
* operations/render/noise.c:
* operations/render/text.c:
* operations/workshop/box-max.c:
* operations/workshop/box-min.c:
* operations/workshop/box-percentile.c:
* operations/workshop/c2g.c:
* operations/workshop/demosaic-simple.c:
* operations/workshop/disc-percentile.c:
* operations/workshop/gluas.c:
* operations/workshop/gtk-display.c:
* operations/workshop/hstack.c:
* operations/workshop/kuwahara-max.c:
* operations/workshop/kuwahara-min.c:
* operations/workshop/kuwahara.c:
* operations/workshop/line-profile.c:
* operations/workshop/mandelbrot.c:
* operations/workshop/max-envelope.c:
* operations/workshop/mblur.c:
* operations/workshop/min-envelope.c:
* operations/workshop/rawbayer-load.c:
* operations/workshop/snn-percentile.c:
* operations/workshop/stress.c:

svn path=/trunk/; revision=1801
parent a6c0d4dd
2008-01-05 Øyvind Kolås <pippin@gimp.org>
Made the process methods of operations take a GeglNodeContext instead
of a context_id, this GeglNodeContext contains the logic to perform
concurrent bookkeeping of data on pads of nodes.
* gegl/gegl-chant.h:
* gegl/graph/gegl-node-context.[ch]:
* gegl/operation/gegl-operation-composer.[ch]:
* gegl/operation/gegl-operation-filter.[ch]:
* gegl/operation/gegl-operation-point-composer.c:
* gegl/operation/gegl-operation-point-filter.c:
* gegl/operation/gegl-operation-sink.[ch]:
* gegl/operation/gegl-operation-source.[ch]:
* gegl/operation/gegl-operation.c:
* gegl/operation/gegl-operation.h:
* gegl/process/gegl-eval-visitor.c:
* gegl/process/gegl-processor.c:
* operations/affine/affine.c:
* operations/blur/box-blur.c:
* operations/blur/gaussian-blur.c:
* operations/color/mono-mixer.c:
* operations/color/remap.c:
* operations/color/stretch-contrast.c:
* operations/core/clone.c:
* operations/core/crop.c:
* operations/core/nop.c:
* operations/core/shift.c:
* operations/enhance/bilateral-filter.c:
* operations/enhance/snn-mean.c:
* operations/io/display.c:
* operations/io/exr-load.cpp:
* operations/io/ff-load.c:
* operations/io/jpg-load.c:
* operations/io/load-buffer.c:
* operations/io/magick-load.c:
* operations/io/pixbuf.c:
* operations/io/png-load.c:
* operations/io/png-save.c:
* operations/io/raw-load.c:
* operations/io/save-buffer.c:
* operations/io/save-pixbuf.c:
* operations/io/svg-load.c:
* operations/render/FractalExplorer.c:
* operations/render/checkerboard.c:
* operations/render/color.c:
* operations/render/introspect.c:
* operations/render/noise.c:
* operations/render/text.c:
* operations/workshop/box-max.c:
* operations/workshop/box-min.c:
* operations/workshop/box-percentile.c:
* operations/workshop/c2g.c:
* operations/workshop/demosaic-simple.c:
* operations/workshop/disc-percentile.c:
* operations/workshop/gluas.c:
* operations/workshop/gtk-display.c:
* operations/workshop/hstack.c:
* operations/workshop/kuwahara-max.c:
* operations/workshop/kuwahara-min.c:
* operations/workshop/kuwahara.c:
* operations/workshop/line-profile.c:
* operations/workshop/mandelbrot.c:
* operations/workshop/max-envelope.c:
* operations/workshop/mblur.c:
* operations/workshop/min-envelope.c:
* operations/workshop/rawbayer-load.c:
* operations/workshop/snn-percentile.c:
* operations/workshop/stress.c:
2008-01-05 Øyvind Kolås <pippin@gimp.org>
Renamed GeglNodeDynamic to GeglNodeContext.
......
......@@ -421,8 +421,8 @@ static gboolean process (GeglOperation *operation,
glong samples);
#else
#ifndef GEGL_CHANT_META
static gboolean process (GeglOperation *operation,
gpointer context_id,
static gboolean process (GeglOperation *operation,
GeglNodeContext *context,
const GeglRectangle *result);
#endif
#endif
......
......@@ -27,6 +27,8 @@
#include "gegl-node-context.h"
#include "gegl-node.h"
#include "gegl-pad.h"
#include "operation/gegl-operation.h"
static void gegl_node_context_class_init (GeglNodeContextClass *klass);
static void gegl_node_context_init (GeglNodeContext *self);
......@@ -251,3 +253,121 @@ finalize (GObject *gobject)
G_OBJECT_CLASS (gegl_node_context_parent_class)->finalize (gobject);
}
void
gegl_node_context_set_object (GeglNodeContext *context,
const gchar *padname,
GObject *data)
{
GeglNode *node;
GeglOperation *operation;
GParamSpec *pspec;
GValue value = {0,};
node = context->node;
operation = node->operation;
pspec = gegl_node_find_property (node, padname);
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
g_value_set_object (&value, data);
gegl_node_context_set_property (context, padname, &value);
g_value_unset (&value);
g_object_unref (data); /* are we stealing the initial reference? */
}
GObject *
gegl_node_context_get_object (GeglNodeContext *context,
const gchar *padname)
{
GeglNode *node;
GeglOperation *operation;
GObject *ret;
GParamSpec *pspec;
GValue value = { 0, };
node = context->node;
operation = node->operation;
pspec = gegl_node_find_property (node, padname);
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
gegl_node_context_get_property (context, padname, &value);
/* FIXME: handle other things than gobjects as well? */
ret = g_value_get_object (&value);
if (!ret)
{/*
g_warning ("some important data was not found on %s.%s",
gegl_node_get_debug_name (node), property_name);
*/
}
g_value_unset (&value);
return ret;
}
GeglBuffer *
gegl_node_context_get_target (GeglNodeContext *context,
const gchar *padname)
{
GeglBuffer *output;
GeglPad *pad;
const GeglRectangle *result;
Babl *format;
GeglNode *node;
GeglOperation *operation;
node = context->node;
operation = node->operation;
pad = gegl_node_get_pad (node, padname);
format = pad->format;
g_assert (format != NULL);
g_assert (!strcmp (padname, "output"));
g_assert (context);
result = &context->result_rect;
#if 1 /* change to 0 to disable per node caches */
if (GEGL_OPERATION_CLASS (G_OBJECT_GET_CLASS (operation))->no_cache)
{
output = gegl_buffer_new (result, format);
}
else
{
GeglBuffer *cache;
cache = GEGL_BUFFER (gegl_node_get_cache (node));
output = gegl_buffer_create_sub_buffer (cache, result);
}
#else
output = gegl_buffer_new (result, format);
#endif
gegl_node_context_set_object (context, padname, G_OBJECT (output));
return output;
}
GeglBuffer *
gegl_node_context_get_source (GeglNodeContext *context,
const gchar *padname)
{
GeglNode *node;
GeglOperation *operation;
GeglBuffer *real_input;
GeglBuffer *input;
GeglRectangle input_request;
node = context->node;
operation = node->operation;
input_request = gegl_operation_compute_input_request (operation,
padname,
&context->need_rect);
real_input = GEGL_BUFFER (gegl_node_context_get_object (context, padname));
if (!real_input)
return NULL;
input = gegl_buffer_create_sub_buffer (real_input, &input_request);
return input;
}
......@@ -65,14 +65,20 @@ struct _GeglNodeContextClass
GType gegl_node_context_get_type (void) G_GNUC_CONST;
/* sets a GValue on a named property (pad) of the NodeContext */
GeglBuffer *gegl_node_context_get_target (GeglNodeContext *self,
const gchar *padname);
GeglBuffer *gegl_node_context_get_source (GeglNodeContext *self,
const gchar *padname);
GObject *gegl_node_context_get_object (GeglNodeContext *context,
const gchar *padname);
void gegl_node_context_set_object (GeglNodeContext *context,
const gchar *padname,
GObject *data);
void gegl_node_context_set_property (GeglNodeContext *node,
const gchar *name,
const GValue *value);
/* retrieves the stored data from a named property (pad) of the NodeContext
* and stores it in a GValue
*/
void gegl_node_context_get_property (GeglNodeContext *node,
const gchar *name,
GValue *value);
......@@ -82,6 +88,11 @@ void gegl_node_context_get_property (GeglNodeContext *node,
void gegl_node_context_remove_property (GeglNodeContext *self,
const gchar *name);
GeglRectangle * gegl_node_context_get_need_rect (GeglNodeContext *node);
void gegl_node_context_set_need_rect (GeglNodeContext *node,
gint x,
......
......@@ -31,22 +31,22 @@ enum
PROP_LAST
};
static void get_property (GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void set_property (GObject *gobject,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static gboolean process (GeglOperation *operation,
gpointer context_id,
const gchar *output_prop,
static void get_property (GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void set_property (GObject *gobject,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static gboolean process (GeglOperation *operation,
GeglNodeContext *context,
const gchar *output_prop,
const GeglRectangle *result);
static void attach (GeglOperation *operation);
static GeglNode*detect (GeglOperation *operation,
gint x,
gint y);
static void attach (GeglOperation *operation);
static GeglNode*detect (GeglOperation *operation,
gint x,
gint y);
static GeglRectangle get_defined_region (GeglOperation *self);
static GeglRectangle compute_input_request (GeglOperation *self,
......@@ -137,7 +137,7 @@ set_property (GObject *object,
static gboolean
process (GeglOperation *operation,
gpointer context_id,
GeglNodeContext *context,
const gchar *output_prop,
const GeglRectangle *result)
{
......@@ -153,8 +153,8 @@ process (GeglOperation *operation,
return FALSE;
}
input = GEGL_BUFFER (gegl_operation_get_data (operation, context_id, "input"));
aux = GEGL_BUFFER (gegl_operation_get_data (operation, context_id, "aux"));
input = gegl_node_context_get_source (context, "input");
aux = gegl_node_context_get_source (context, "aux");
/* A composer with a NULL aux, can still be valid, the
* subclass has to handle it.
......@@ -162,7 +162,7 @@ process (GeglOperation *operation,
if (input != NULL ||
aux != NULL)
{
success = klass->process (operation, context_id, result);
success = klass->process (operation, context, result);
}
else
{
......
......@@ -40,8 +40,8 @@ struct _GeglOperationComposerClass
{
GeglOperationClass parent_class;
gboolean (* process) (GeglOperation *self,
gpointer context_id,
gboolean (* process) (GeglOperation *self,
GeglNodeContext *context,
const GeglRectangle *result);
};
......
......@@ -39,9 +39,9 @@ static void set_property (GObject *gobject,
const GValue *value,
GParamSpec *pspec);
static gboolean process (GeglOperation *operation,
gpointer context_id,
const gchar *output_prop,
static gboolean process (GeglOperation *operation,
GeglNodeContext *context,
const gchar *output_prop,
const GeglRectangle *result);
static void attach (GeglOperation *operation);
......@@ -170,9 +170,9 @@ set_property (GObject *object,
static gboolean
process (GeglOperation *operation,
gpointer context_id,
const gchar *output_prop,
process (GeglOperation *operation,
GeglNodeContext *context,
const gchar *output_prop,
const GeglRectangle *result)
{
GeglOperationFilter *gegl_operation_filter;
......@@ -191,10 +191,10 @@ process (GeglOperation *operation,
return FALSE;
}
input = GEGL_BUFFER (gegl_operation_get_data (operation, context_id, "input"));
input = gegl_node_context_get_source (context, "input");
if (input != NULL)
{
success = klass->process (operation, context_id, result);
{ /* FIXME: perhaps input should really be passed instead of context */
success = klass->process (operation, context, result);
}
else
{
......
......@@ -41,7 +41,7 @@ struct _GeglOperationFilterClass
GeglOperationClass parent_class;
gboolean (* process) (GeglOperation *self,
gpointer context_id,
GeglNodeContext *context,
const GeglRectangle *result);
};
......
......@@ -22,7 +22,7 @@
#include <string.h>
static gboolean process_inner (GeglOperation *operation,
gpointer context_id,
GeglNodeContext *context,
const GeglRectangle *result);
G_DEFINE_TYPE (GeglOperationPointComposer, gegl_operation_point_composer, GEGL_TYPE_OPERATION_COMPOSER)
......@@ -55,7 +55,7 @@ gegl_operation_point_composer_init (GeglOperationPointComposer *self)
static gboolean
fast_paths (GeglOperation *operation,
gpointer context_id,
GeglNodeContext *context,
Babl *in_format,
Babl *aux_format,
Babl *out_format,
......@@ -63,11 +63,11 @@ fast_paths (GeglOperation *operation,
static gboolean
process_inner (GeglOperation *operation,
gpointer context_id,
GeglNodeContext *context,
const GeglRectangle *result)
{
GeglBuffer *input = GEGL_BUFFER (gegl_operation_get_data (operation, context_id, "input"));
GeglBuffer *aux = GEGL_BUFFER (gegl_operation_get_data (operation, context_id, "aux"));
GeglBuffer *input = gegl_node_context_get_source (context, "input");
GeglBuffer *aux = gegl_node_context_get_source (context, "aux");
GeglBuffer *output;
GeglPad *pad;
Babl *in_format;
......@@ -104,11 +104,15 @@ process_inner (GeglOperation *operation,
* good idea. NB! some of the OpenRaster meta ops, depends on the
* short-circuiting happening in fast_paths.
* */
if (fast_paths (operation, context_id, in_format, aux_format, out_format, result))
if (fast_paths (operation, context,
in_format,
aux_format,
out_format,
result))
return TRUE;
/* retrieve the buffer we're writing to from GEGL */
output = gegl_operation_get_target (operation, context_id, "output");
output = gegl_node_context_get_target (context, "output");
if ((result->width > 0) && (result->height > 0))
{
......@@ -157,19 +161,19 @@ process_inner (GeglOperation *operation,
static gboolean
fast_paths (GeglOperation *operation,
gpointer context_id,
GeglNodeContext *context,
Babl *in_format,
Babl *aux_format,
Babl *out_format,
const GeglRectangle *result)
{
GeglBuffer *input = GEGL_BUFFER (gegl_operation_get_data (operation, context_id, "input"));
GeglBuffer *aux = GEGL_BUFFER (gegl_operation_get_data (operation, context_id, "aux"));
GeglBuffer *input = gegl_node_context_get_source (context, "input");
GeglBuffer *aux = gegl_node_context_get_source (context, "aux");
if (!input && aux)
{
g_object_ref (aux);
gegl_operation_set_data (operation, context_id, "output", G_OBJECT (aux));
gegl_node_context_set_object (context, "output", G_OBJECT (aux));
return TRUE;
}
......@@ -197,11 +201,11 @@ fast_paths (GeglOperation *operation,
if (!gegl_rectangle_intersect (NULL, aux_abyss, result))
{
GeglBuffer *output = gegl_buffer_new (NULL, NULL);
gegl_operation_set_data (operation, context_id, "output", G_OBJECT (output));
gegl_node_context_set_object (context, "output", G_OBJECT (output));
return TRUE;
}
g_object_ref (aux);
gegl_operation_set_data (operation, context_id, "output", G_OBJECT (aux));
gegl_node_context_set_object (context, "output", G_OBJECT (aux));
return TRUE;
}
}
......@@ -216,7 +220,7 @@ fast_paths (GeglOperation *operation,
(aux && !gegl_rectangle_intersect (NULL, aux_abyss, result)))
{
g_object_ref (input);
gegl_operation_set_data (operation, context_id, "output", G_OBJECT (input));
gegl_node_context_set_object (context, "output", G_OBJECT (input));
return TRUE;
}
}
......@@ -225,7 +229,7 @@ fast_paths (GeglOperation *operation,
else
{
GeglBuffer *output = gegl_buffer_new (NULL, out_format);
gegl_operation_set_data (operation, context_id, "output", G_OBJECT (output));
gegl_node_context_set_object (context, "output", G_OBJECT (output));
return TRUE;
}
}
......
......@@ -21,7 +21,7 @@
#include <string.h>
static gboolean process_inner (GeglOperation *operation,
gpointer context_id,
GeglNodeContext *context,
const GeglRectangle *result);
G_DEFINE_TYPE (GeglOperationPointFilter, gegl_operation_point_filter, GEGL_TYPE_OPERATION_FILTER)
......@@ -49,7 +49,7 @@ gegl_operation_point_filter_init (GeglOperationPointFilter *self)
static gboolean
process_inner (GeglOperation *operation,
gpointer context_id,
GeglNodeContext *context,
const GeglRectangle *result)
{
GeglBuffer *input;
......@@ -59,7 +59,7 @@ process_inner (GeglOperation *operation,
Babl *in_format;
Babl *out_format;
input = gegl_operation_get_source (operation, context_id, "input");
input = gegl_node_context_get_source (context, "input");
pad = gegl_node_get_pad (operation->node, "input");
in_format = pad->format;
......@@ -77,7 +77,7 @@ process_inner (GeglOperation *operation,
}
g_assert (out_format);
output = gegl_operation_get_target (operation, context_id, "output");
output = gegl_node_context_get_target (context, "output");
if ((result->width > 0) && (result->height > 0))
{
......
......@@ -38,7 +38,7 @@ static void set_property (GObject *gobject,
GParamSpec *pspec);
static gboolean process (GeglOperation *operation,
gpointer context_id,
GeglNodeContext *context,
const gchar *output_prop,
const GeglRectangle *result);
static void attach (GeglOperation *operation);
......@@ -110,7 +110,7 @@ set_property (GObject *object,
static gboolean
process (GeglOperation *operation,
gpointer context_id,
GeglNodeContext *context,
const gchar *output_prop,
const GeglRectangle *result)
{
......@@ -124,10 +124,10 @@ process (GeglOperation *operation,
g_assert (klass->process);
input = GEGL_BUFFER (gegl_operation_get_data (operation, context_id, "input"));
input = gegl_node_context_get_source (context, "input");
if (input)
{
success = klass->process (operation, context_id, result);
success = klass->process (operation, context, result);
}
return success;
......
......@@ -45,7 +45,7 @@ struct _GeglOperationSinkClass
gboolean needs_full;
gboolean (* process) (GeglOperation *self,
gpointer context_id,
GeglNodeContext *context,
const GeglRectangle *result);
};
......
......@@ -36,8 +36,8 @@ static void set_property (GObject *gobject,
const GValue *value,
GParamSpec *pspec);
static gboolean process (GeglOperation *operation,
gpointer context_id,
const gchar *output_prop,
GeglNodeContext *context,
const gchar *output_prop,
const GeglRectangle *result);
static void attach (GeglOperation *operation);
......@@ -111,9 +111,9 @@ set_property (GObject *object,
}
static gboolean
process (GeglOperation *operation,
gpointer context_id,
const gchar *output_prop,
process (GeglOperation *operation,
GeglNodeContext *context,
const gchar *output_prop,
const GeglRectangle *result)
{
GeglOperationSourceClass *klass = GEGL_OPERATION_SOURCE_GET_CLASS (operation);
......@@ -126,7 +126,7 @@ process (GeglOperation *operation,
}
g_assert (klass->process);
success = klass->process (operation, context_id, result);
success = klass->process (operation, context, result);
return success;
}
......
......@@ -40,7 +40,7 @@ struct _GeglOperationSourceClass
{
GeglOperationClass parent_class;
gboolean (*process) (GeglOperation *self,
gpointer context_id,
GeglNodeContext *context,
const GeglRectangle *result);
};
......
......@@ -99,7 +99,7 @@ gegl_operation_create_pad (GeglOperation *self,
gboolean
gegl_operation_process (GeglOperation *operation,
gpointer context_id,
GeglNodeContext *context,
const gchar *output_pad,
const GeglRectangle *result)
{
......@@ -113,11 +113,11 @@ gegl_operation_process (GeglOperation *operation,
(result->width == 0 || result->height == 0))
{
GeglBuffer *output = gegl_buffer_new (NULL, NULL);
gegl_operation_set_data (operation, context_id, "output", G_OBJECT (output));
gegl_node_context_set_object (context, "output", G_OBJECT (output));
return TRUE;
}
return klass->process (operation, context_id, output_pad, result);
return klass->process (operation, context, output_pad, result);
}
GeglRectangle
......@@ -494,33 +494,6 @@ gegl_list_properties (const gchar *operation_type,
return pspecs;
}
GObject *
gegl_operation_get_data (GeglOperation *operation,
gpointer context_id,
const gchar *property_name)
{
GObject *ret;
GeglNode *node = operation->node;
GParamSpec *pspec;
GValue value = { 0, };
GeglNodeContext *context = gegl_node_get_context (node, context_id);
pspec = gegl_node_find_property (node, property_name);
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
gegl_node_context_get_property (context, property_name, &value);
/* FIXME: handle other things than gobjects as well? */
ret = g_value_get_object (&value);
if (!ret)
{/*
g_warning ("some important data was not found on %s.%s",
gegl_node_get_debug_name (node), property_name);
*/
}
g_value_unset (&value);
return ret;
}
GeglNode *
gegl_operation_detect (GeglOperation *operation,
gint x,
......@@ -552,65 +525,6 @@ gegl_operation_detect (GeglOperation *operation,
return NULL;
}
void
gegl_operation_set_data (GeglOperation *operation,
gpointer context_id,
const gchar *property_name,
GObject *data)
{
GeglNode *node = operation->node;
GParamSpec *pspec;
GValue value = { 0, };
GeglNodeContext *context = gegl_node_get_context (node, context_id);
pspec = gegl_node_find_property (node, property_name);
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
g_value_set_object (&value, data);
gegl_node_context_set_property (context, property_name, &value);
g_value_unset (&value);
g_object_unref (data); /* stealing the initial reference? */
}
GeglBuffer *
gegl_operation_get_target (GeglOperation *operation,
gpointer context_id,
const gchar *property_name)
{
GeglBuffer *output;
GeglPad *pad;
const GeglRectangle *result;
Babl *format;
GeglNodeContext *context;
pad = gegl_node_get_pad (operation->node, property_name);
context = gegl_node_get_context (operation->node, context_id);
format = pad->format;