[gimp] app: avoid copying the brush boundary on each brush tool flush()



commit 09b16f6cc085aeb523a1eacf1ba479db6c4ff165
Author: Ell <ell_se yahoo com>
Date:   Sat Apr 14 17:55:44 2018 -0400

    app: avoid copying the brush boundary on each brush tool flush()
    
    In GimpBrushTool, remember the settings used for the last cached
    brush boundary, and avoid creating a new copy if the settings
    didn't change.  This should lower the overhead of
    gimp_brush_tool_flush_paint() when not using dynamics.

 app/tools/gimpbrushtool.c |   43 ++++++++++++++++++++++++++++++++++++-------
 app/tools/gimpbrushtool.h |    5 +++++
 2 files changed, 41 insertions(+), 7 deletions(-)
---
diff --git a/app/tools/gimpbrushtool.c b/app/tools/gimpbrushtool.c
index 5b35573..47bf26e 100644
--- a/app/tools/gimpbrushtool.c
+++ b/app/tools/gimpbrushtool.c
@@ -235,10 +235,25 @@ gimp_brush_tool_options_notify (GimpTool         *tool,
 static void
 gimp_brush_tool_start_paint (GimpPaintTool *paint_tool)
 {
+  GimpBrushTool        *brush_tool = GIMP_BRUSH_TOOL (paint_tool);
+  GimpBrushCore        *brush_core = GIMP_BRUSH_CORE (paint_tool->core);
+  const GimpBezierDesc *boundary;
+
   if (GIMP_PAINT_TOOL_CLASS (parent_class)->start_paint)
     GIMP_PAINT_TOOL_CLASS (parent_class)->start_paint (paint_tool);
 
-  gimp_brush_tool_flush_paint (paint_tool);
+  boundary = gimp_brush_tool_get_boundary (brush_tool,
+                                           &brush_tool->boundary_width,
+                                           &brush_tool->boundary_height);
+
+  if (boundary)
+    brush_tool->boundary = gimp_bezier_desc_copy (boundary);
+
+  brush_tool->boundary_scale        = brush_core->scale;
+  brush_tool->boundary_aspect_ratio = brush_core->aspect_ratio;
+  brush_tool->boundary_angle        = brush_core->angle;
+  brush_tool->boundary_reflect      = brush_core->reflect;
+  brush_tool->boundary_hardness     = brush_core->hardness;
 }
 
 static void
@@ -256,19 +271,33 @@ static void
 gimp_brush_tool_flush_paint (GimpPaintTool *paint_tool)
 {
   GimpBrushTool        *brush_tool = GIMP_BRUSH_TOOL (paint_tool);
+  GimpBrushCore        *brush_core = GIMP_BRUSH_CORE (paint_tool->core);
   const GimpBezierDesc *boundary;
 
   if (GIMP_PAINT_TOOL_CLASS (parent_class)->flush_paint)
     GIMP_PAINT_TOOL_CLASS (parent_class)->flush_paint (paint_tool);
 
-  g_clear_pointer (&brush_tool->boundary, gimp_bezier_desc_free);
+  if (brush_tool->boundary_scale        != brush_core->scale        ||
+      brush_tool->boundary_aspect_ratio != brush_core->aspect_ratio ||
+      brush_tool->boundary_angle        != brush_core->angle        ||
+      brush_tool->boundary_reflect      != brush_core->reflect      ||
+      brush_tool->boundary_hardness     != brush_core->hardness)
+    {
+      g_clear_pointer (&brush_tool->boundary, gimp_bezier_desc_free);
 
-  boundary = gimp_brush_tool_get_boundary (brush_tool,
-                                           &brush_tool->boundary_width,
-                                           &brush_tool->boundary_height);
+      boundary = gimp_brush_tool_get_boundary (brush_tool,
+                                               &brush_tool->boundary_width,
+                                               &brush_tool->boundary_height);
 
-  if (boundary)
-    brush_tool->boundary = gimp_bezier_desc_copy (boundary);
+      if (boundary)
+        brush_tool->boundary = gimp_bezier_desc_copy (boundary);
+
+      brush_tool->boundary_scale        = brush_core->scale;
+      brush_tool->boundary_aspect_ratio = brush_core->aspect_ratio;
+      brush_tool->boundary_angle        = brush_core->angle;
+      brush_tool->boundary_reflect      = brush_core->reflect;
+      brush_tool->boundary_hardness     = brush_core->hardness;
+    }
 }
 
 static GimpCanvasItem *
diff --git a/app/tools/gimpbrushtool.h b/app/tools/gimpbrushtool.h
index 3145557..6f49df5 100644
--- a/app/tools/gimpbrushtool.h
+++ b/app/tools/gimpbrushtool.h
@@ -39,6 +39,11 @@ struct _GimpBrushTool
   GimpBezierDesc *boundary;
   gint            boundary_width;
   gint            boundary_height;
+  gdouble         boundary_scale;
+  gdouble         boundary_aspect_ratio;
+  gdouble         boundary_angle;
+  gboolean        boundary_reflect;
+  gdouble         boundary_hardness;
 };
 
 struct _GimpBrushToolClass


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