Commit 4c7dc6a4 authored by Daniel Sabo's avatar Daniel Sabo Committed by Michael Natterer

app: cache values to speed up GEGL paintbrush

Cache values in GimpApplicator to avoid the overhead of gegl_node_set().
Don't reallocate paint_core->paint_buffer if it's already the correct size.
parent 31314584
......@@ -52,8 +52,10 @@ gimp_applicator_class_init (GimpApplicatorClass *klass)
}
static void
gimp_applicator_init (GimpApplicator *core)
gimp_applicator_init (GimpApplicator *applicator)
{
applicator->opacity = 1.0;
applicator->paint_mode = GIMP_NORMAL_MODE;
}
static void
......@@ -222,27 +224,42 @@ gimp_applicator_apply (GimpApplicator *applicator,
gdouble opacity,
GimpLayerModeEffects paint_mode)
{
gint width;
gint height;
gint width = gegl_buffer_get_width (apply_buffer);
gint height = gegl_buffer_get_height (apply_buffer);
gegl_node_set (applicator->src_node,
"buffer", src_buffer,
NULL);
if (applicator->src_buffer != src_buffer)
{
applicator->src_buffer = src_buffer;
gegl_node_set (applicator->src_node,
"buffer", src_buffer,
NULL);
}
if (applicator->apply_buffer != apply_buffer)
{
applicator->apply_buffer = apply_buffer;
gegl_node_set (applicator->apply_src_node,
"buffer", apply_buffer,
NULL);
}
gegl_node_set (applicator->apply_src_node,
"buffer", apply_buffer,
NULL);
gegl_node_set (applicator->apply_offset_node,
"x", (gdouble) apply_buffer_x,
"y", (gdouble) apply_buffer_y,
NULL);
gimp_gegl_mode_node_set (applicator->mode_node,
paint_mode, opacity, FALSE);
if ((applicator->opacity != opacity) ||
(applicator->paint_mode != paint_mode))
{
applicator->opacity = opacity;
applicator->paint_mode = paint_mode;
width = gegl_buffer_get_width (apply_buffer);
height = gegl_buffer_get_height (apply_buffer);
gimp_gegl_mode_node_set (applicator->mode_node,
paint_mode, opacity, FALSE);
}
gegl_processor_set_rectangle (applicator->processor,
GEGL_RECTANGLE (apply_buffer_x,
......
......@@ -34,15 +34,22 @@ typedef struct _GimpApplicatorClass GimpApplicatorClass;
struct _GimpApplicator
{
GObject parent_instance;
GObject parent_instance;
GeglNode *node;
GeglNode *mode_node;
GeglNode *src_node;
GeglNode *apply_src_node;
GeglNode *apply_offset_node;
GeglNode *dest_node;
GeglProcessor *processor;
GeglNode *node;
GeglNode *mode_node;
GeglNode *src_node;
GeglNode *apply_src_node;
GeglNode *apply_offset_node;
GeglNode *dest_node;
GeglProcessor *processor;
GeglBuffer *src_buffer;
GeglBuffer *apply_buffer;
gint apply_buffer_x;
gint apply_buffer_y;
gdouble opacity;
GimpLayerModeEffects paint_mode;
};
struct _GimpApplicatorClass
......
......@@ -821,6 +821,16 @@ gimp_brush_core_get_paint_buffer (GimpPaintCore *paint_core,
{
GimpTempBuf *temp_buf;
if (paint_core->paint_buffer &&
gegl_buffer_get_width (paint_core->paint_buffer) == (x2 - x1) &&
gegl_buffer_get_height (paint_core->paint_buffer) == (y2 - y1))
{
*paint_buffer_x = x1;
*paint_buffer_y = y1;
return paint_core->paint_buffer;
}
temp_buf = gimp_temp_buf_new ((x2 - x1), (y2 - y1),
babl_format ("RGBA float"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment