1998-07-03 07:29:44 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "tile.h"
|
1998-07-08 14:41:58 +08:00
|
|
|
#include "tile_pvt.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "tile_cache.h"
|
|
|
|
#include "tile_manager.h"
|
|
|
|
#include "tile_swap.h"
|
|
|
|
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
1998-07-08 14:41:58 +08:00
|
|
|
|
1998-07-03 07:29:44 +08:00
|
|
|
/* EXPERIMENTAL Copy-On-Write goodies
|
|
|
|
* by Adam D. Moss
|
|
|
|
* adam@gimp.org
|
|
|
|
* adam@foxbox.org
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* C.O.W. Revisions:
|
|
|
|
*
|
|
|
|
* 97.10.05 - Initial release
|
|
|
|
* 97.10.06 - Much faster tile invalidation +
|
|
|
|
* Better swap interaction (should no longer
|
|
|
|
* crash GIMP when GIMP swapfile is full).
|
|
|
|
* 97.10.18 - Very stable now, and even more efficient.
|
|
|
|
* 98.06.16 - Revised from GIMP 0.99.14 for 1.[01].0 - no
|
|
|
|
* longer so sure about stability until
|
|
|
|
* more comprehensive testing is done.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* MISC TODO:
|
|
|
|
*
|
|
|
|
* tile_invalidate: (tile_manager) - don't let a tile become
|
|
|
|
* invalidated if its ref-count >1, but move it to a delete-on-last-unref
|
|
|
|
* list instead...
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
static void tile_destroy (Tile *tile);
|
1998-07-03 07:29:44 +08:00
|
|
|
|
1998-07-12 08:59:37 +08:00
|
|
|
int tile_count = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
tile_init (Tile *tile,
|
|
|
|
int bpp)
|
|
|
|
{
|
|
|
|
tile->ref_count = 0;
|
1998-07-10 10:43:12 +08:00
|
|
|
tile->write_count = 0;
|
|
|
|
tile->share_count = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
tile->dirty = FALSE;
|
|
|
|
tile->valid = FALSE;
|
1998-07-03 07:29:44 +08:00
|
|
|
tile->data = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
tile->ewidth = TILE_WIDTH;
|
|
|
|
tile->eheight = TILE_HEIGHT;
|
|
|
|
tile->bpp = bpp;
|
|
|
|
tile->swap_num = 1;
|
|
|
|
tile->swap_offset = -1;
|
1998-07-10 10:43:12 +08:00
|
|
|
tile->tlink = NULL;
|
1998-06-21 01:09:32 +08:00
|
|
|
tile->next = tile->prev = NULL;
|
|
|
|
tile->listhead = NULL;
|
|
|
|
#ifdef USE_PTHREADS
|
|
|
|
{
|
|
|
|
pthread_mutex_init(&tile->mutex, NULL);
|
|
|
|
}
|
1998-07-12 08:59:37 +08:00
|
|
|
tile_count++;
|
1998-06-21 01:09:32 +08:00
|
|
|
#endif
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int tile_ref_count = 0;
|
1998-07-12 01:23:03 +08:00
|
|
|
int tile_share_count = 0;
|
|
|
|
int tile_active_count = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-07-03 07:29:44 +08:00
|
|
|
void
|
1998-07-10 10:43:12 +08:00
|
|
|
tile_lock (Tile *tile)
|
1998-07-03 07:29:44 +08:00
|
|
|
{
|
|
|
|
/* Increment the global reference count.
|
|
|
|
*/
|
1997-11-25 06:05:25 +08:00
|
|
|
tile_ref_count += 1;
|
|
|
|
|
1998-07-03 07:29:44 +08:00
|
|
|
/* Increment this tile's reference count.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
TILE_MUTEX_LOCK (tile);
|
|
|
|
tile->ref_count += 1;
|
1998-07-03 07:29:44 +08:00
|
|
|
|
1998-07-10 12:33:21 +08:00
|
|
|
if (tile->ref_count == 1)
|
1998-07-03 07:29:44 +08:00
|
|
|
{
|
1998-07-10 10:43:12 +08:00
|
|
|
if (tile->listhead)
|
1998-07-03 07:29:44 +08:00
|
|
|
{
|
1998-07-10 10:43:12 +08:00
|
|
|
/* remove from cache, move to main store */
|
|
|
|
tile_cache_flush (tile);
|
|
|
|
}
|
1998-07-12 01:23:03 +08:00
|
|
|
tile_active_count ++;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1998-07-22 07:34:28 +08:00
|
|
|
if (tile->data == NULL)
|
|
|
|
{
|
|
|
|
/* There is no data, so the tile must be swapped out */
|
|
|
|
tile_swap_in (tile);
|
|
|
|
}
|
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
TILE_MUTEX_UNLOCK (tile);
|
1998-06-28 13:34:46 +08:00
|
|
|
|
1998-07-03 07:29:44 +08:00
|
|
|
/* Call 'tile_manager_validate' if the tile was invalid.
|
|
|
|
*/
|
1998-06-28 13:34:46 +08:00
|
|
|
if (!tile->valid)
|
1998-07-10 10:43:12 +08:00
|
|
|
{
|
|
|
|
/* an invalid tile should never be shared, so this should work */
|
|
|
|
tile_manager_validate ((TileManager*) tile->tlink->tm, tile);
|
|
|
|
}
|
1998-07-22 07:34:28 +08:00
|
|
|
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-07-03 07:29:44 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
void
|
1998-07-10 10:43:12 +08:00
|
|
|
tile_release (Tile *tile, int dirty)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-07-03 07:29:44 +08:00
|
|
|
/* Decrement the global reference count.
|
|
|
|
*/
|
1997-11-25 06:05:25 +08:00
|
|
|
tile_ref_count -= 1;
|
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
TILE_MUTEX_LOCK(tile);
|
|
|
|
|
1998-07-03 07:29:44 +08:00
|
|
|
/* Decrement this tile's reference count.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
tile->ref_count -= 1;
|
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
/* Decrement write ref count if dirtying
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
1998-07-10 10:43:12 +08:00
|
|
|
if (dirty)
|
|
|
|
tile->write_count -= 1;
|
1998-07-03 07:29:44 +08:00
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
if (tile->ref_count == 0)
|
1998-07-03 07:29:44 +08:00
|
|
|
{
|
1998-07-10 10:43:12 +08:00
|
|
|
if (tile->share_count == 0)
|
1998-07-03 07:29:44 +08:00
|
|
|
{
|
1998-07-10 10:43:12 +08:00
|
|
|
/* tile is dead */
|
|
|
|
tile_destroy (tile);
|
|
|
|
return; /* skip terminal unlock */
|
1998-07-03 07:29:44 +08:00
|
|
|
}
|
1998-07-10 10:43:12 +08:00
|
|
|
else
|
1998-07-03 07:29:44 +08:00
|
|
|
{
|
1998-07-10 10:43:12 +08:00
|
|
|
/* last reference was just released, so move the tile to the
|
|
|
|
tile cache */
|
|
|
|
tile_cache_insert (tile);
|
1998-07-03 07:29:44 +08:00
|
|
|
}
|
1998-07-12 01:23:03 +08:00
|
|
|
tile_active_count--;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1998-07-10 10:43:12 +08:00
|
|
|
|
|
|
|
TILE_MUTEX_UNLOCK (tile);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tile_alloc (Tile *tile)
|
|
|
|
{
|
|
|
|
if (tile->data)
|
1998-07-12 01:23:03 +08:00
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Allocate the data for the tile.
|
|
|
|
*/
|
|
|
|
tile->data = g_new (guchar, tile_size (tile));
|
|
|
|
}
|
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
static void
|
|
|
|
tile_destroy (Tile *tile)
|
|
|
|
{
|
1998-07-12 01:23:03 +08:00
|
|
|
if (tile->ref_count)
|
|
|
|
{
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
|
|
|
g_warning (_("tried to destroy a ref'd tile"));
|
1998-07-12 01:23:03 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (tile->share_count)
|
|
|
|
{
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
|
|
|
g_warning (_("tried to destroy an attached tile"));
|
1998-07-12 01:23:03 +08:00
|
|
|
return;
|
|
|
|
}
|
1998-07-10 10:43:12 +08:00
|
|
|
if (tile->data)
|
|
|
|
{
|
|
|
|
g_free (tile->data);
|
|
|
|
tile->data = NULL;
|
|
|
|
}
|
|
|
|
if (tile->swap_offset != -1)
|
|
|
|
{
|
|
|
|
/* If the tile is on disk, then delete its
|
|
|
|
* presence there.
|
|
|
|
*/
|
|
|
|
tile_swap_delete (tile);
|
|
|
|
}
|
|
|
|
if (tile->listhead)
|
|
|
|
tile_cache_flush (tile);
|
|
|
|
|
|
|
|
TILE_MUTEX_UNLOCK (tile);
|
|
|
|
g_free (tile);
|
1998-07-12 08:59:37 +08:00
|
|
|
tile_count --;
|
1998-07-10 10:43:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
int
|
|
|
|
tile_size (Tile *tile)
|
|
|
|
{
|
1998-06-21 01:09:32 +08:00
|
|
|
int size;
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Return the actual size of the tile data.
|
|
|
|
* (Based on its effective width and height).
|
|
|
|
*/
|
1998-06-21 01:09:32 +08:00
|
|
|
size = tile->ewidth * tile->eheight * tile->bpp;
|
|
|
|
return size;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
|
1998-08-12 01:35:34 +08:00
|
|
|
int
|
|
|
|
tile_ewidth (Tile *tile)
|
|
|
|
{
|
|
|
|
return tile->ewidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
tile_eheight (Tile *tile)
|
|
|
|
{
|
|
|
|
return tile->eheight;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
tile_bpp (Tile *tile)
|
|
|
|
{
|
|
|
|
return tile->bpp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
tile_is_valid (Tile *tile)
|
|
|
|
{
|
|
|
|
return tile->valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
tile_mark_valid (Tile *tile)
|
|
|
|
{
|
|
|
|
TILE_MUTEX_LOCK (tile);
|
|
|
|
tile->valid = TRUE;
|
|
|
|
TILE_MUTEX_UNLOCK (tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
void
|
1998-07-10 10:43:12 +08:00
|
|
|
tile_attach (Tile *tile, void *tm, int tile_num)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-07-10 10:43:12 +08:00
|
|
|
TileLink *tmp;
|
|
|
|
|
|
|
|
if (tile->share_count > 0 && !tile->valid)
|
1998-07-03 07:29:44 +08:00
|
|
|
{
|
1998-07-10 10:43:12 +08:00
|
|
|
/* trying to share invalid tiles is problematic, not to mention silly */
|
|
|
|
tile_manager_validate ((TileManager*) tile->tlink->tm, tile);
|
1998-07-03 07:29:44 +08:00
|
|
|
}
|
1998-07-10 10:43:12 +08:00
|
|
|
tile->share_count++;
|
1998-07-12 01:23:03 +08:00
|
|
|
tile_share_count++;
|
1998-07-10 10:43:12 +08:00
|
|
|
#ifdef TILE_DEBUG
|
|
|
|
g_print("tile_attach: %p -> (%p,%d) *%d\n", tile, tm, tile_num, tile->share_count);
|
1998-07-03 07:29:44 +08:00
|
|
|
#endif
|
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
/* link this tile into the tile's tilelink chain */
|
|
|
|
tmp = g_new (TileLink, 1);
|
|
|
|
tmp->tm = tm;
|
|
|
|
tmp->tile_num = tile_num;
|
|
|
|
tmp->next = tile->tlink;
|
|
|
|
tile->tlink = tmp;
|
|
|
|
}
|
1998-07-03 07:29:44 +08:00
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
void
|
|
|
|
tile_detach (Tile *tile, void *tm, int tile_num)
|
|
|
|
{
|
|
|
|
TileLink **link;
|
|
|
|
TileLink *tmp;
|
|
|
|
|
|
|
|
#ifdef TILE_DEBUG
|
|
|
|
g_print("tile_detach: %p ~> (%p,%d) *%d\n", tile, tm, tile_num, tile->share_count);
|
1998-07-03 07:29:44 +08:00
|
|
|
#endif
|
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
for (link = &tile->tlink; *link; link = &(*link)->next)
|
|
|
|
if ((*link)->tm == tm && (*link)->tile_num == tile_num)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (*link == NULL)
|
1998-07-03 07:29:44 +08:00
|
|
|
{
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
|
|
|
g_warning (_("Tried to detach a nonattached tile"));
|
1998-07-03 07:29:44 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
tmp = *link;
|
|
|
|
*link = tmp->next;
|
|
|
|
g_free (tmp);
|
1998-07-03 07:29:44 +08:00
|
|
|
|
1998-07-12 01:23:03 +08:00
|
|
|
tile_share_count--;
|
1998-07-10 10:43:12 +08:00
|
|
|
tile->share_count--;
|
|
|
|
|
|
|
|
if (tile->share_count == 0 && tile->ref_count == 0)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-07-10 10:43:12 +08:00
|
|
|
tile_destroy (tile);
|
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1998-07-10 10:43:12 +08:00
|
|
|
TILE_MUTEX_UNLOCK (tile);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1998-07-03 07:29:44 +08:00
|
|
|
|
|
|
|
|
1998-08-12 01:35:34 +08:00
|
|
|
void *
|
|
|
|
tile_data_pointer (Tile *tile, int xoff, int yoff)
|
|
|
|
{
|
|
|
|
int offset = yoff * tile->ewidth + xoff;
|
|
|
|
return (void *)(tile->data + offset * tile->bpp);
|
|
|
|
}
|