Commit 23690346 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

Improved undo memory calculation for paint operations (bug #153035):

2004-09-19  Sven Neumann  <sven@gimp.org>

	Improved undo memory calculation for paint operations (bug #153035):

	* app/base/tile-manager.[ch] (tile_manager_get_memsize): added a
	"gboolean sparse" parameter to get more accurate results for
	sparse tile-managers.

	* app/core/gimpbuffer.c
	* app/core/gimpdrawable.c
	* app/core/gimpimage-undo-push.c
	* app/core/gimpimage.c
	* app/core/gimplayer.c
	* app/core/gimpprojection.c: changed accordingly.
parent d3473974
2004-09-19 Sven Neumann <sven@gimp.org>
Improved undo memory calculation for paint operations (bug #153035):
* app/base/tile-manager.[ch] (tile_manager_get_memsize): added a
"gboolean sparse" parameter to get more accurate results for
sparse tile-managers.
* app/core/gimpbuffer.c
* app/core/gimpdrawable.c
* app/core/gimpimage-undo-push.c
* app/core/gimpimage.c
* app/core/gimplayer.c
* app/core/gimpprojection.c: changed accordingly.
2004-09-19 Sven Neumann <sven@gimp.org>
* app/dialogs/Makefile.am (libappdialogs_a_SOURCES): added authors.h.
......
......@@ -441,11 +441,11 @@ tile_manager_map (TileManager *tm,
{
Tile **tiles;
Tile **tile_ptr;
gint ntiles;
gint nrows, ncols;
gint right_tile;
gint bottom_tile;
gint i, j, k;
gint ntiles;
gint nrows, ncols;
gint right_tile;
gint bottom_tile;
gint i, j, k;
g_return_if_fail (tm != NULL);
g_return_if_fail (srctile != NULL);
......@@ -616,16 +616,41 @@ tile_manager_set_offsets (TileManager *tm,
}
gint64
tile_manager_get_memsize (const TileManager *tm)
tile_manager_get_memsize (const TileManager *tm,
gboolean sparse)
{
gint64 memsize = 0;
gint64 memsize;
g_return_val_if_fail (tm != NULL, 0);
memsize += (sizeof (TileManager) +
(gint64) tm->ntile_rows * tm->ntile_cols *
(sizeof (Tile) + sizeof (gpointer)) +
(gint64) tm->width * tm->height * tm->bpp);
/* the tile manager itself */
memsize = sizeof (TileManager);
/* the array of tiles */
memsize += (gint64) tm->ntile_rows * tm->ntile_cols * (sizeof (Tile) +
sizeof (gpointer));
/* the memory allocated for the tiles */
if (sparse)
{
if (tm->tiles)
{
Tile **tiles = tm->tiles;
gint64 size = TILE_WIDTH * TILE_HEIGHT * tm->bpp;
gint i, j;
for (i = 0; i < tm->ntile_rows; i++)
for (j = 0; j < tm->ntile_cols; j++, tiles++)
{
if ((*tiles)->dirty)
memsize += size;
}
}
}
else
{
memsize += (gint64) tm->width * tm->height * tm->bpp;
}
return memsize;
}
......
......@@ -123,7 +123,8 @@ void tile_manager_set_offsets (TileManager *tm,
gint x,
gint y);
gint64 tile_manager_get_memsize (const TileManager *tm);
gint64 tile_manager_get_memsize (const TileManager *tm,
gboolean sparse);
void tile_manager_get_tile_coordinates (TileManager *tm,
Tile *tile,
......
......@@ -141,7 +141,7 @@ gimp_buffer_get_memsize (GimpObject *object,
buffer = GIMP_BUFFER (object);
if (buffer->tiles)
memsize += tile_manager_get_memsize (buffer->tiles);
memsize += tile_manager_get_memsize (buffer->tiles, FALSE);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
......
......@@ -295,7 +295,7 @@ gimp_drawable_get_memsize (GimpObject *object,
gint64 memsize = 0;
if (drawable->tiles)
memsize += tile_manager_get_memsize (drawable->tiles);
memsize += tile_manager_get_memsize (drawable->tiles, FALSE);
if (drawable->preview_cache)
*gui_size += gimp_preview_cache_get_memsize (drawable->preview_cache);
......
......@@ -619,7 +619,7 @@ gimp_image_undo_push_drawable (GimpImage *gimage,
tile_manager_height (tiles) == gimp_item_height (item),
FALSE);
size = sizeof (DrawableUndo) + tile_manager_get_memsize (tiles);
size = sizeof (DrawableUndo) + tile_manager_get_memsize (tiles, sparse);
if ((new = gimp_image_undo_push (gimage, GIMP_TYPE_ITEM_UNDO,
size, sizeof (DrawableUndo),
......@@ -652,7 +652,8 @@ undo_pop_drawable (GimpUndo *undo,
{
DrawableUndo *drawable_undo = undo->data;
undo->size -= tile_manager_get_memsize (drawable_undo->tiles);
undo->size -= tile_manager_get_memsize (drawable_undo->tiles,
drawable_undo->sparse);
gimp_drawable_swap_pixels (GIMP_DRAWABLE (GIMP_ITEM_UNDO (undo)->item),
drawable_undo->tiles,
......@@ -662,7 +663,8 @@ undo_pop_drawable (GimpUndo *undo,
drawable_undo->width,
drawable_undo->height);
undo->size += tile_manager_get_memsize (drawable_undo->tiles);
undo->size += tile_manager_get_memsize (drawable_undo->tiles,
drawable_undo->sparse);
return TRUE;
}
......@@ -709,7 +711,8 @@ gimp_image_undo_push_drawable_mod (GimpImage *gimage,
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
size = sizeof (DrawableModUndo) + tile_manager_get_memsize (drawable->tiles);
size = sizeof (DrawableModUndo) + tile_manager_get_memsize (drawable->tiles,
FALSE);
if ((new = gimp_image_undo_push (gimage, GIMP_TYPE_ITEM_UNDO,
size, sizeof (DrawableModUndo),
......@@ -744,7 +747,7 @@ undo_pop_drawable_mod (GimpUndo *undo,
GimpImageType drawable_type;
gint offset_x, offset_y;
undo->size -= tile_manager_get_memsize (drawable_undo->tiles);
undo->size -= tile_manager_get_memsize (drawable_undo->tiles, FALSE);
tiles = drawable_undo->tiles;
drawable_type = drawable_undo->type;
......@@ -760,7 +763,7 @@ undo_pop_drawable_mod (GimpUndo *undo,
tiles, drawable_type, offset_x, offset_y);
tile_manager_unref (tiles);
undo->size += tile_manager_get_memsize (drawable_undo->tiles);
undo->size += tile_manager_get_memsize (drawable_undo->tiles, FALSE);
return TRUE;
}
......@@ -824,7 +827,7 @@ gimp_image_undo_push_mask (GimpImage *gimage,
copy_region (&srcPR, &destPR);
size += tile_manager_get_memsize (undo_tiles);
size += tile_manager_get_memsize (undo_tiles, FALSE);
}
if ((new = gimp_image_undo_push (gimage, GIMP_TYPE_ITEM_UNDO,
......@@ -868,7 +871,7 @@ undo_pop_mask (GimpUndo *undo,
guchar empty = 0;
if (mu->tiles)
undo->size -= tile_manager_get_memsize (mu->tiles);
undo->size -= tile_manager_get_memsize (mu->tiles, FALSE);
if (gimp_channel_bounds (channel, &x1, &y1, &x2, &y2))
{
......@@ -940,7 +943,7 @@ undo_pop_mask (GimpUndo *undo,
GIMP_ITEM (channel)->height);
if (mu->tiles)
undo->size += tile_manager_get_memsize (mu->tiles);
undo->size += tile_manager_get_memsize (mu->tiles, FALSE);
return TRUE;
}
......
......@@ -906,7 +906,7 @@ gimp_image_get_memsize (GimpObject *object,
memsize += GIMP_IMAGE_COLORMAP_SIZE;
if (gimage->shadow)
memsize += tile_manager_get_memsize (gimage->shadow);
memsize += tile_manager_get_memsize (gimage->shadow, FALSE);
if (gimage->projection)
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimage->projection),
......
......@@ -352,7 +352,7 @@ gimp_layer_get_memsize (GimpObject *object,
memsize += gimp_object_get_memsize (GIMP_OBJECT (layer->mask), gui_size);
if (layer->fs.backing_store)
*gui_size += tile_manager_get_memsize (layer->fs.backing_store);
*gui_size += tile_manager_get_memsize (layer->fs.backing_store, FALSE);
*gui_size += layer->fs.num_segs * sizeof (BoundSeg);
......
......@@ -224,7 +224,7 @@ gimp_projection_get_memsize (GimpObject *object,
gint64 memsize = 0;
if (projection->tiles)
memsize += tile_manager_get_memsize (projection->tiles);
memsize += tile_manager_get_memsize (projection->tiles, FALSE);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
......
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