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.
This commit is contained in:
Ell 2018-04-14 17:55:44 -04:00
parent 1806e56405
commit 09b16f6cc0
2 changed files with 41 additions and 7 deletions

View File

@ -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,11 +271,18 @@ 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);
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,
@ -269,6 +291,13 @@ gimp_brush_tool_flush_paint (GimpPaintTool *paint_tool)
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 *

View File

@ -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