removed the brush outline members since we have no chance to really cache

2003-07-24  Michael Natterer  <mitch@gimp.org>

	* app/tools/gimppainttool.[ch]: removed the brush outline members
	since we have no chance to really cache them without duplicating
	GimpPaintCore's brush change notification code.

	* app/paint/gimppaintcore.[ch]: added the outline here and really
	cache it this time. The paint_core doesn't create or use the
	outline but frees and NULLifies it whenever the brush changes.
This commit is contained in:
Michael Natterer 2003-07-24 16:35:25 +00:00 committed by Michael Natterer
parent fc3c1b41d9
commit 827c3f37c4
7 changed files with 91 additions and 68 deletions

View File

@ -1,3 +1,13 @@
2003-07-24 Michael Natterer <mitch@gimp.org>
* app/tools/gimppainttool.[ch]: removed the brush outline members
since we have no chance to really cache them without duplicating
GimpPaintCore's brush change notification code.
* app/paint/gimppaintcore.[ch]: added the outline here and really
cache it this time. The paint_core doesn't create or use the
outline but frees and NULLifies it whenever the brush changes.
2003-07-24 Michael Natterer <mitch@gimp.org>
* app/paint/gimppaintcore-stroke.c

View File

@ -245,6 +245,8 @@ gimp_paint_core_init (GimpPaintCore *core)
core->cache_invalid = FALSE;
core->grr_brush = NULL;
core->brush_bound_segs = NULL;
core->n_brush_bound_segs = 0;
}
static void
@ -300,6 +302,13 @@ gimp_paint_core_finalize (GObject *object)
core->grr_brush = NULL;
}
if (core->brush_bound_segs)
{
g_free (core->brush_bound_segs);
core->brush_bound_segs = NULL;
core->n_brush_bound_segs = 0;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -372,27 +381,40 @@ gimp_paint_core_start (GimpPaintCore *core,
* the maximum bounds of the active brush...
*/
if (core->grr_brush &&
core->grr_brush != gimp_context_get_brush (GIMP_CONTEXT (paint_options)))
if (core->grr_brush != gimp_context_get_brush (GIMP_CONTEXT (paint_options)))
{
g_signal_handlers_disconnect_by_func (core->grr_brush,
gimp_paint_core_invalidate_cache,
core);
g_object_unref (core->grr_brush);
}
if (core->grr_brush)
{
g_signal_handlers_disconnect_by_func (core->grr_brush,
gimp_paint_core_invalidate_cache,
core);
g_object_unref (core->grr_brush);
core->grr_brush = NULL;
}
core->grr_brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options));
if (core->brush_bound_segs)
{
g_free (core->brush_bound_segs);
core->brush_bound_segs = NULL;
core->n_brush_bound_segs = 0;
}
}
if (! core->grr_brush)
{
g_message (_("No brushes available for use with this tool."));
return FALSE;
}
core->grr_brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options));
g_object_ref (core->grr_brush);
g_signal_connect (core->grr_brush, "invalidate_preview",
G_CALLBACK (gimp_paint_core_invalidate_cache),
core);
if (! core->grr_brush)
{
g_message (_("No brushes available for use with this tool."));
return FALSE;
}
g_object_ref (core->grr_brush);
g_signal_connect (core->grr_brush, "invalidate_preview",
G_CALLBACK (gimp_paint_core_invalidate_cache),
core);
}
core->spacing = (gdouble) gimp_brush_get_spacing (core->grr_brush) / 100.0;
@ -1007,6 +1029,13 @@ gimp_paint_core_invalidate_cache (GimpBrush *brush,
core->cache_invalid = TRUE;
core->solid_cache_invalid = TRUE;
if (core->brush_bound_segs)
{
g_free (core->brush_bound_segs);
core->brush_bound_segs = NULL;
core->n_brush_bound_segs = 0;
}
}
/************************************************************

View File

@ -122,8 +122,10 @@ struct _GimpPaintCore
MaskBuf *last_brush_mask;
gboolean cache_invalid;
/* don't use this one... */
/* don't use these... */
GimpBrush *grr_brush;
BoundSeg *brush_bound_segs;
gint n_brush_bound_segs;
};
struct _GimpPaintCoreClass

View File

@ -180,10 +180,10 @@ gimp_paint_tool_init (GimpPaintTool *paint_tool)
paint_tool->draw_line = FALSE;
paint_tool->draw_brush = TRUE;
paint_tool->brush_bound_segs = NULL;
paint_tool->n_brush_bound_segs = 0;
paint_tool->brush_x = 0.0;
paint_tool->brush_y = 0.0;
paint_tool->brush_x = 0.0;
paint_tool->brush_y = 0.0;
paint_tool->core = NULL;
}
static void
@ -191,13 +191,6 @@ gimp_paint_tool_finalize (GObject *object)
{
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (object);
if (paint_tool->brush_bound_segs)
{
g_free (paint_tool->brush_bound_segs);
paint_tool->brush_bound_segs = NULL;
paint_tool->n_brush_bound_segs = 0;
}
if (paint_tool->core)
{
g_object_unref (paint_tool->core);
@ -702,7 +695,14 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool)
brush = gimp_context_get_brush (context);
mask = gimp_brush_get_mask (brush);
if (! paint_tool->brush_bound_segs)
if (brush != core->grr_brush && core->brush_bound_segs)
{
g_free (core->brush_bound_segs);
core->brush_bound_segs = NULL;
core->n_brush_bound_segs = 0;
}
if (! core->brush_bound_segs)
{
PixelRegion PR = { 0, };
@ -714,15 +714,15 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool)
PR.bytes = mask->bytes;
PR.rowstride = PR.w * PR.bytes;
paint_tool->brush_bound_segs =
find_mask_boundary (&PR, &paint_tool->n_brush_bound_segs,
core->brush_bound_segs =
find_mask_boundary (&PR, &core->n_brush_bound_segs,
WithinBounds,
0, 0,
PR.w, PR.h,
0);
}
if (paint_tool->brush_bound_segs)
if (core->brush_bound_segs)
{
GimpPaintOptions *paint_options;
gdouble brush_x, brush_y;
@ -747,18 +747,11 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool)
}
gimp_draw_tool_draw_boundary (draw_tool,
paint_tool->brush_bound_segs,
paint_tool->n_brush_bound_segs,
core->brush_bound_segs,
core->n_brush_bound_segs,
brush_x,
brush_y);
}
if (paint_tool->brush_bound_segs)
{
g_free (paint_tool->brush_bound_segs);
paint_tool->brush_bound_segs = NULL;
paint_tool->n_brush_bound_segs = 0;
}
}
}

View File

@ -41,8 +41,6 @@ struct _GimpPaintTool
gboolean draw_line;
gboolean draw_brush;
BoundSeg *brush_bound_segs;
gint n_brush_bound_segs;
gdouble brush_x;
gdouble brush_y;

View File

@ -180,10 +180,10 @@ gimp_paint_tool_init (GimpPaintTool *paint_tool)
paint_tool->draw_line = FALSE;
paint_tool->draw_brush = TRUE;
paint_tool->brush_bound_segs = NULL;
paint_tool->n_brush_bound_segs = 0;
paint_tool->brush_x = 0.0;
paint_tool->brush_y = 0.0;
paint_tool->brush_x = 0.0;
paint_tool->brush_y = 0.0;
paint_tool->core = NULL;
}
static void
@ -191,13 +191,6 @@ gimp_paint_tool_finalize (GObject *object)
{
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (object);
if (paint_tool->brush_bound_segs)
{
g_free (paint_tool->brush_bound_segs);
paint_tool->brush_bound_segs = NULL;
paint_tool->n_brush_bound_segs = 0;
}
if (paint_tool->core)
{
g_object_unref (paint_tool->core);
@ -702,7 +695,14 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool)
brush = gimp_context_get_brush (context);
mask = gimp_brush_get_mask (brush);
if (! paint_tool->brush_bound_segs)
if (brush != core->grr_brush && core->brush_bound_segs)
{
g_free (core->brush_bound_segs);
core->brush_bound_segs = NULL;
core->n_brush_bound_segs = 0;
}
if (! core->brush_bound_segs)
{
PixelRegion PR = { 0, };
@ -714,15 +714,15 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool)
PR.bytes = mask->bytes;
PR.rowstride = PR.w * PR.bytes;
paint_tool->brush_bound_segs =
find_mask_boundary (&PR, &paint_tool->n_brush_bound_segs,
core->brush_bound_segs =
find_mask_boundary (&PR, &core->n_brush_bound_segs,
WithinBounds,
0, 0,
PR.w, PR.h,
0);
}
if (paint_tool->brush_bound_segs)
if (core->brush_bound_segs)
{
GimpPaintOptions *paint_options;
gdouble brush_x, brush_y;
@ -747,18 +747,11 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool)
}
gimp_draw_tool_draw_boundary (draw_tool,
paint_tool->brush_bound_segs,
paint_tool->n_brush_bound_segs,
core->brush_bound_segs,
core->n_brush_bound_segs,
brush_x,
brush_y);
}
if (paint_tool->brush_bound_segs)
{
g_free (paint_tool->brush_bound_segs);
paint_tool->brush_bound_segs = NULL;
paint_tool->n_brush_bound_segs = 0;
}
}
}

View File

@ -41,8 +41,6 @@ struct _GimpPaintTool
gboolean draw_line;
gboolean draw_brush;
BoundSeg *brush_bound_segs;
gint n_brush_bound_segs;
gdouble brush_x;
gdouble brush_y;