[gimp/soc-2011-seamless-clone2] app: cache values to speed up GEGL paintbrush



commit cebcf0ff538949fe9fb48edf8f25e70ba1ad12f5
Author: Daniel Sabo <DanielSabo gmail com>
Date:   Sat Dec 8 10:31:05 2012 -0800

    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.

 app/gegl/gimpapplicator.c |   43 ++++++++++++++++++++++++++++++-------------
 app/gegl/gimpapplicator.h |   25 ++++++++++++++++---------
 app/paint/gimpbrushcore.c |   10 ++++++++++
 3 files changed, 56 insertions(+), 22 deletions(-)
---
diff --git a/app/gegl/gimpapplicator.c b/app/gegl/gimpapplicator.c
index 3228e36..ce3b3e2 100644
--- a/app/gegl/gimpapplicator.c
+++ b/app/gegl/gimpapplicator.c
@@ -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,
diff --git a/app/gegl/gimpapplicator.h b/app/gegl/gimpapplicator.h
index bccd994..976cda3 100644
--- a/app/gegl/gimpapplicator.h
+++ b/app/gegl/gimpapplicator.h
@@ -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
diff --git a/app/paint/gimpbrushcore.c b/app/paint/gimpbrushcore.c
index 78319d7..063153c 100644
--- a/app/paint/gimpbrushcore.c
+++ b/app/paint/gimpbrushcore.c
@@ -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"));
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]