Commit dccb9090 authored by Michael Natterer's avatar Michael Natterer 😴
Browse files

app: make GimpTempBuf reference counted

and remove the "take_ownership" parameter from
gimp_temp_buf_create_buffer(), simply always ref the buf.
parent d5d8e36d
......@@ -44,11 +44,12 @@ gimp_temp_buf_new (gint width,
temp = g_slice_new (GimpTempBuf);
temp->format = format;
temp->width = width;
temp->height = height;
temp->x = 0;
temp->y = 0;
temp->ref_count = 1;
temp->format = format;
temp->width = width;
temp->height = height;
temp->x = 0;
temp->y = 0;
temp->data = g_new (guchar,
width * height *
......@@ -73,15 +74,31 @@ gimp_temp_buf_copy (GimpTempBuf *src)
return dest;
}
GimpTempBuf *
gimp_temp_buf_ref (GimpTempBuf *buf)
{
g_return_val_if_fail (buf != NULL, NULL);
buf->ref_count++;
return buf;
}
void
gimp_temp_buf_free (GimpTempBuf *buf)
gimp_temp_buf_unref (GimpTempBuf *buf)
{
g_return_if_fail (buf != NULL);
g_return_if_fail (buf->ref_count > 0);
buf->ref_count--;
if (buf->data)
g_free (buf->data);
if (buf->ref_count < 1)
{
if (buf->data)
g_free (buf->data);
g_slice_free (GimpTempBuf, buf);
g_slice_free (GimpTempBuf, buf);
}
}
GimpTempBuf *
......@@ -218,8 +235,7 @@ gimp_temp_buf_get_memsize (GimpTempBuf *buf)
}
GeglBuffer *
gimp_temp_buf_create_buffer (GimpTempBuf *temp_buf,
gboolean take_ownership)
gimp_temp_buf_create_buffer (GimpTempBuf *temp_buf)
{
GeglBuffer *buffer;
......@@ -232,10 +248,8 @@ gimp_temp_buf_create_buffer (GimpTempBuf *temp_buf,
temp_buf->width,
temp_buf->height),
GEGL_AUTO_ROWSTRIDE,
take_ownership ?
(GDestroyNotify) gimp_temp_buf_free : NULL,
take_ownership ?
temp_buf : NULL);
(GDestroyNotify) gimp_temp_buf_unref,
gimp_temp_buf_ref (temp_buf));
g_object_set_data (G_OBJECT (buffer), "gimp-temp-buf", temp_buf);
......
......@@ -21,6 +21,7 @@
struct _GimpTempBuf
{
gint ref_count;
const Babl *format; /* pixel format */
gint width;
gint height;
......@@ -36,7 +37,9 @@ GimpTempBuf * gimp_temp_buf_new (gint width,
gint height,
const Babl *fomat) G_GNUC_WARN_UNUSED_RESULT;
GimpTempBuf * gimp_temp_buf_copy (GimpTempBuf *src) G_GNUC_WARN_UNUSED_RESULT;
void gimp_temp_buf_free (GimpTempBuf *buf);
GimpTempBuf * gimp_temp_buf_ref (GimpTempBuf *buf);
void gimp_temp_buf_unref (GimpTempBuf *buf);
GimpTempBuf * gimp_temp_buf_scale (GimpTempBuf *buf,
gint width,
......@@ -50,8 +53,7 @@ guchar * gimp_temp_buf_data_clear (GimpTempBuf *buf);
gsize gimp_temp_buf_get_memsize (GimpTempBuf *buf);
GeglBuffer * gimp_temp_buf_create_buffer (GimpTempBuf *temp_buf,
gboolean take_ownership) G_GNUC_WARN_UNUSED_RESULT;
GeglBuffer * gimp_temp_buf_create_buffer (GimpTempBuf *temp_buf) G_GNUC_WARN_UNUSED_RESULT;
#endif /* __GIMP_TEMP_BUF_H__ */
......@@ -48,7 +48,7 @@ gimp_brush_transform_boundary_exact (GimpBrush *brush,
GimpBoundSeg *bound_segs;
gint n_bound_segs;
buffer = gimp_temp_buf_create_buffer ((GimpTempBuf *) mask, FALSE);
buffer = gimp_temp_buf_create_buffer ((GimpTempBuf *) mask);
bound_segs = gimp_boundary_find (buffer, NULL,
GIMP_BOUNDARY_WITHIN_BOUNDS,
......
......@@ -342,8 +342,10 @@ gimp_brush_real_transform_mask (GimpBrush *brush,
blur_src = gimp_temp_buf_copy (result);
src_buffer = gimp_temp_buf_create_buffer (blur_src, TRUE);
dest_buffer = gimp_temp_buf_create_buffer (blur_src, FALSE);
src_buffer = gimp_temp_buf_create_buffer (blur_src);
dest_buffer = gimp_temp_buf_create_buffer (result);
gimp_temp_buf_unref (blur_src);
gimp_gegl_convolve (src_buffer,
GEGL_RECTANGLE (0, 0,
......@@ -643,8 +645,10 @@ gimp_brush_real_transform_pixmap (GimpBrush *brush,
blur_src = gimp_temp_buf_copy (result);
src_buffer = gimp_temp_buf_create_buffer (blur_src, TRUE);
dest_buffer = gimp_temp_buf_create_buffer (blur_src, FALSE);
src_buffer = gimp_temp_buf_create_buffer (blur_src);
dest_buffer = gimp_temp_buf_create_buffer (result);
gimp_temp_buf_unref (blur_src);
gimp_gegl_convolve (src_buffer,
GEGL_RECTANGLE (0, 0,
......
......@@ -177,13 +177,13 @@ gimp_brush_finalize (GObject *object)
if (brush->mask)
{
gimp_temp_buf_free (brush->mask);
gimp_temp_buf_unref (brush->mask);
brush->mask = NULL;
}
if (brush->pixmap)
{
gimp_temp_buf_free (brush->pixmap);
gimp_temp_buf_unref (brush->pixmap);
brush->pixmap = NULL;
}
......@@ -283,7 +283,6 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
{
GimpBrush *brush = GIMP_BRUSH (viewable);
const GimpTempBuf *mask_buf = NULL;
gboolean free_mask = FALSE;
const GimpTempBuf *pixmap_buf = NULL;
GimpTempBuf *return_buf = NULL;
gint mask_width;
......@@ -316,7 +315,10 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
{
mask_buf = gimp_temp_buf_new (1, 1, babl_format ("Y u8"));
gimp_temp_buf_data_clear ((GimpTempBuf *) mask_buf);
free_mask = TRUE;
}
else
{
gimp_temp_buf_ref ((GimpTempBuf *) mask_buf);
}
if (pixmap_buf)
......@@ -368,8 +370,7 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
if (scaled)
{
if (free_mask)
gimp_temp_buf_free ((GimpTempBuf *) mask_buf);
gimp_temp_buf_unref ((GimpTempBuf *) mask_buf);
gimp_brush_end_use (brush);
}
......@@ -416,10 +417,10 @@ static void
gimp_brush_real_begin_use (GimpBrush *brush)
{
brush->mask_cache =
gimp_brush_cache_new ((GDestroyNotify) gimp_temp_buf_free, 'M', 'm');
gimp_brush_cache_new ((GDestroyNotify) gimp_temp_buf_unref, 'M', 'm');
brush->pixmap_cache =
gimp_brush_cache_new ((GDestroyNotify) gimp_temp_buf_free, 'P', 'p');
gimp_brush_cache_new ((GDestroyNotify) gimp_temp_buf_unref, 'P', 'p');
brush->boundary_cache =
gimp_brush_cache_new ((GDestroyNotify) gimp_bezier_desc_free, 'B', 'b');
......
......@@ -184,13 +184,13 @@ gimp_brush_clipboard_buffer_changed (Gimp *gimp,
if (brush->mask)
{
gimp_temp_buf_free (brush->mask);
gimp_temp_buf_unref (brush->mask);
brush->mask = NULL;
}
if (brush->pixmap)
{
gimp_temp_buf_free (brush->pixmap);
gimp_temp_buf_unref (brush->pixmap);
brush->pixmap = NULL;
}
......@@ -211,7 +211,7 @@ gimp_brush_clipboard_buffer_changed (Gimp *gimp,
/* copy the alpha channel into the brush's mask */
if (babl_format_has_alpha (format))
{
dest_buffer = gimp_temp_buf_create_buffer (brush->mask, FALSE);
dest_buffer = gimp_temp_buf_create_buffer (brush->mask);
gegl_buffer_set_format (dest_buffer, babl_format ("A u8"));
gegl_buffer_copy (buffer, NULL, dest_buffer, NULL);
......@@ -225,7 +225,7 @@ gimp_brush_clipboard_buffer_changed (Gimp *gimp,
}
/* copy the color channels into the brush's pixmap */
dest_buffer = gimp_temp_buf_create_buffer (brush->pixmap, FALSE);
dest_buffer = gimp_temp_buf_create_buffer (brush->pixmap);
gegl_buffer_copy (buffer, NULL, dest_buffer, NULL);
......
......@@ -254,7 +254,7 @@ gimp_brush_generated_dirty (GimpData *data)
GimpBrush *gbrush = GIMP_BRUSH (brush);
if (gbrush->mask)
gimp_temp_buf_free (gbrush->mask);
gimp_temp_buf_unref (gbrush->mask);
gbrush->mask = gimp_brush_generated_calc (brush,
brush->shape,
......
......@@ -111,7 +111,7 @@ gimp_image_get_preview (GimpViewable *viewable,
{
/* The hard way */
if (private->preview)
gimp_temp_buf_free (private->preview);
gimp_temp_buf_unref (private->preview);
private->preview = gimp_image_get_new_preview (viewable, context,
width, height);
......
......@@ -945,7 +945,7 @@ gimp_image_finalize (GObject *object)
if (private->preview)
{
gimp_temp_buf_free (private->preview);
gimp_temp_buf_unref (private->preview);
private->preview = NULL;
}
......@@ -1098,7 +1098,7 @@ gimp_image_invalidate_preview (GimpViewable *viewable)
if (private->preview)
{
gimp_temp_buf_free (private->preview);
gimp_temp_buf_unref (private->preview);
private->preview = NULL;
}
}
......
......@@ -223,7 +223,7 @@ gimp_pattern_load_pixbuf (GimpContext *context,
gimp_bpp_to_babl_format (gdk_pixbuf_get_n_channels (pixbuf)));
src_buffer = gimp_pixbuf_create_buffer (pixbuf);
dest_buffer = gimp_temp_buf_create_buffer (pattern->mask, FALSE);
dest_buffer = gimp_temp_buf_create_buffer (pattern->mask);
gegl_buffer_copy (src_buffer, NULL, dest_buffer, NULL);
......
......@@ -105,7 +105,7 @@ gimp_pattern_finalize (GObject *object)
if (pattern->mask)
{
gimp_temp_buf_free (pattern->mask);
gimp_temp_buf_unref (pattern->mask);
pattern->mask = NULL;
}
......@@ -157,8 +157,8 @@ gimp_pattern_get_new_preview (GimpViewable *viewable,
temp_buf = gimp_temp_buf_new (copy_width, copy_height,
pattern->mask->format);
src_buffer = gimp_temp_buf_create_buffer (pattern->mask, FALSE);
dest_buffer = gimp_temp_buf_create_buffer (temp_buf, FALSE);
src_buffer = gimp_temp_buf_create_buffer (pattern->mask);
dest_buffer = gimp_temp_buf_create_buffer (temp_buf);
gegl_buffer_copy (src_buffer, GEGL_RECTANGLE (0, 0, copy_width, copy_height),
dest_buffer, GEGL_RECTANGLE (0, 0, 0, 0));
......@@ -279,5 +279,5 @@ gimp_pattern_create_buffer (const GimpPattern *pattern)
{
g_return_val_if_fail (GIMP_IS_PATTERN (pattern), NULL);
return gimp_temp_buf_create_buffer (pattern->mask, FALSE);
return gimp_temp_buf_create_buffer (pattern->mask);
}
......@@ -182,7 +182,7 @@ gimp_pattern_clipboard_buffer_changed (Gimp *gimp,
{
if (pattern->mask)
{
gimp_temp_buf_free (pattern->mask);
gimp_temp_buf_unref (pattern->mask);
pattern->mask = NULL;
}
......
......@@ -126,7 +126,7 @@ preview_cache_remove_smallest (GSList **plist)
smallest->width, smallest->height);
#endif
gimp_temp_buf_free (smallest);
gimp_temp_buf_unref (smallest);
}
}
......@@ -155,7 +155,7 @@ gimp_preview_cache_invalidate (GSList **plist)
preview_cache_print (*plist);
#endif
g_slist_free_full (*plist, (GDestroyNotify) gimp_temp_buf_free);
g_slist_free_full (*plist, (GDestroyNotify) gimp_temp_buf_unref);
*plist = NULL;
}
......
......@@ -199,7 +199,7 @@ gimp_undo_finalize (GObject *object)
if (undo->preview)
{
gimp_temp_buf_free (undo->preview);
gimp_temp_buf_unref (undo->preview);
undo->preview = NULL;
}
......@@ -511,7 +511,7 @@ gimp_undo_refresh_preview (GimpUndo *undo,
if (undo->preview)
{
gimp_temp_buf_free (undo->preview);
gimp_temp_buf_unref (undo->preview);
undo->preview = NULL;
gimp_undo_create_preview (undo, context, FALSE);
}
......
......@@ -211,7 +211,7 @@ gimp_viewable_finalize (GObject *object)
if (private->preview_temp_buf)
{
gimp_temp_buf_free (private->preview_temp_buf);
gimp_temp_buf_unref (private->preview_temp_buf);
private->preview_temp_buf = NULL;
}
......@@ -295,7 +295,7 @@ gimp_viewable_real_invalidate_preview (GimpViewable *viewable)
if (private->preview_temp_buf)
{
gimp_temp_buf_free (private->preview_temp_buf);
gimp_temp_buf_unref (private->preview_temp_buf);
private->preview_temp_buf = NULL;
}
......@@ -364,7 +364,7 @@ gimp_viewable_real_get_new_pixbuf (GimpViewable *viewable,
temp_buf->width,
temp_buf->height);
src_buffer = gimp_temp_buf_create_buffer (temp_buf, FALSE);
src_buffer = gimp_temp_buf_create_buffer (temp_buf);
dest_buffer = gimp_pixbuf_create_buffer (pixbuf);
gegl_buffer_copy (src_buffer, NULL, dest_buffer, NULL);
......@@ -716,7 +716,7 @@ gimp_viewable_get_preview (GimpViewable *viewable,
return private->preview_temp_buf;
}
gimp_temp_buf_free (private->preview_temp_buf);
gimp_temp_buf_unref (private->preview_temp_buf);
private->preview_temp_buf = NULL;
}
......
......@@ -243,7 +243,7 @@ gimp_brush_core_finalize (GObject *object)
if (core->pressure_brush)
{
gimp_temp_buf_free (core->pressure_brush);
gimp_temp_buf_unref (core->pressure_brush);
core->pressure_brush = NULL;
}
......@@ -251,7 +251,7 @@ gimp_brush_core_finalize (GObject *object)
for (j = 0; j < BRUSH_CORE_SOLID_SUBSAMPLE; j++)
if (core->solid_brushes[i][j])
{
gimp_temp_buf_free (core->solid_brushes[i][j]);
gimp_temp_buf_unref (core->solid_brushes[i][j]);
core->solid_brushes[i][j] = NULL;
}
......@@ -265,7 +265,7 @@ gimp_brush_core_finalize (GObject *object)
for (j = 0; j < KERNEL_SUBSAMPLE + 1; j++)
if (core->subsample_brushes[i][j])
{
gimp_temp_buf_free (core->subsample_brushes[i][j]);
gimp_temp_buf_unref (core->subsample_brushes[i][j]);
core->subsample_brushes[i][j] = NULL;
}
......@@ -843,7 +843,9 @@ gimp_brush_core_get_paint_buffer (GimpPaintCore *paint_core,
if (paint_core->paint_buffer)
g_object_unref (paint_core->paint_buffer);
paint_core->paint_buffer = gimp_temp_buf_create_buffer (temp_buf, TRUE);
paint_core->paint_buffer = gimp_temp_buf_create_buffer (temp_buf);
gimp_temp_buf_unref (temp_buf);
return paint_core->paint_buffer;
}
......@@ -950,7 +952,7 @@ gimp_brush_core_paste_canvas (GimpBrushCore *core,
off_x = (x < 0) ? -x : 0;
off_y = (y < 0) ? -y : 0;
paint_mask = gimp_temp_buf_create_buffer ((GimpTempBuf *) brush_mask, FALSE);
paint_mask = gimp_temp_buf_create_buffer ((GimpTempBuf *) brush_mask);
gimp_paint_core_paste (paint_core, paint_mask,
GEGL_RECTANGLE (off_x, off_y,
......@@ -1000,7 +1002,7 @@ gimp_brush_core_replace_canvas (GimpBrushCore *core,
off_x = (x < 0) ? -x : 0;
off_y = (y < 0) ? -y : 0;
paint_mask = gimp_temp_buf_create_buffer ((GimpTempBuf *) brush_mask, FALSE);
paint_mask = gimp_temp_buf_create_buffer ((GimpTempBuf *) brush_mask);
gimp_paint_core_replace (paint_core, paint_mask,
GEGL_RECTANGLE (off_x, off_y,
......@@ -1119,7 +1121,7 @@ gimp_brush_core_subsample_mask (GimpBrushCore *core,
for (j = 0; j < KERNEL_SUBSAMPLE + 1; j++)
if (core->subsample_brushes[i][j])
{
gimp_temp_buf_free (core->subsample_brushes[i][j]);
gimp_temp_buf_unref (core->subsample_brushes[i][j]);
core->subsample_brushes[i][j] = NULL;
}
......@@ -1206,7 +1208,7 @@ gimp_brush_core_pressurize_mask (GimpBrushCore *core,
return subsample_mask;
if (core->pressure_brush)
gimp_temp_buf_free (core->pressure_brush);
gimp_temp_buf_unref (core->pressure_brush);
core->pressure_brush = gimp_temp_buf_new (brush_mask->width + 2,
brush_mask->height + 2,
......@@ -1341,7 +1343,7 @@ gimp_brush_core_solidify_mask (GimpBrushCore *core,
for (j = 0; j < BRUSH_CORE_SOLID_SUBSAMPLE; j++)
if (core->solid_brushes[i][j])
{
gimp_temp_buf_free (core->solid_brushes[i][j]);
gimp_temp_buf_unref (core->solid_brushes[i][j]);
core->solid_brushes[i][j] = NULL;
}
......
......@@ -184,8 +184,8 @@ gimp_convolve_motion (GimpPaintCore *paint_core,
convolve_temp = gimp_temp_buf_new (gegl_buffer_get_width (paint_buffer),
gegl_buffer_get_height (paint_buffer),
gegl_buffer_get_format (paint_buffer));
convolve_buffer = gimp_temp_buf_create_buffer (convolve_temp, TRUE);
convolve_buffer = gimp_temp_buf_create_buffer (convolve_temp);
gimp_temp_buf_unref (convolve_temp);
gegl_buffer_copy (gimp_drawable_get_buffer (drawable),
GEGL_RECTANGLE (paint_buffer_x,
......
......@@ -537,7 +537,7 @@ gimp_heal_motion (GimpSourceCore *source_core,
paint_area_width,
paint_area_height));
mask_buffer = gimp_temp_buf_create_buffer ((GimpTempBuf *) mask_buf, FALSE);
mask_buffer = gimp_temp_buf_create_buffer ((GimpTempBuf *) mask_buf);
gimp_heal (src_copy,
GEGL_RECTANGLE (0, 0,
......
......@@ -231,7 +231,9 @@ gimp_ink_get_paint_buffer (GimpPaintCore *paint_core,
if (paint_core->paint_buffer)
g_object_unref (paint_core->paint_buffer);
paint_core->paint_buffer = gimp_temp_buf_create_buffer (temp_buf, TRUE);
paint_core->paint_buffer = gimp_temp_buf_create_buffer (temp_buf);
gimp_temp_buf_unref (temp_buf);
return paint_core->paint_buffer;
}
......
......@@ -187,8 +187,8 @@ gimp_smudge_start (GimpPaintCore *paint_core,
/* Allocate the accumulation buffer */
accum_temp = gimp_temp_buf_new (accum_size, accum_size,
gimp_drawable_get_format (drawable));
smudge->accum_buffer = gimp_temp_buf_create_buffer (accum_temp, TRUE);
smudge->accum_buffer = gimp_temp_buf_create_buffer (accum_temp);
gimp_temp_buf_unref (accum_temp);
/* adjust the x and y coordinates to the upper left corner of the
* accumulator
......
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