mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-22 12:32:37 +00:00
4ba6db4e94
2001-12-03 Sven Neumann <sven@gimp.org> Michael Natterer <mitch@gimp.org> * app/paint-funcs/paint-funcs-mmx.h: removed redefiniton of HAS_ALPHA macro. * app/core/gimp.c: reverted Daniel's change; it doesn't make the code simpler, only more error-prone. * app/gui/info-dialog.h * app/gui/resize-dialog.h * app/core/gimp.h * app/core/gimpbrushgenerated.h * app/core/gimpbrushpipe.h * app/core/gimpchannel.[ch] * app/core/gimpcontainer.h * app/core/gimpcoreconfig.h * app/core/gimpdata.h * app/core/gimpdatafactory.[ch] * app/core/gimpdrawable-blend.c * app/core/gimpdrawable.[ch] * app/core/gimpimage.h * app/core/gimpimagefile.h * app/core/gimplayer.h * app/core/gimplayermask.h * app/core/gimpmoduleinfo.h * app/core/gimppalette.h * app/core/gimpundo.h * app/widgets/gimpbrushfactoryview.h * app/widgets/gimpconstrainedhwrapbox.h * app/widgets/gimpcontainermenu.h * app/widgets/gimpcontainerview.h * app/widgets/gimpdialogfactory.h * app/widgets/gimpimagedock.h * app/widgets/gimplistitem.h * app/widgets/gimpmenuitem.h * app/widgets/gimpnavigationpreview.h * app/widgets/gimppreview.h * app/gimprc.h * app/pathP.h * app/tools/gimpbezierselecttool.h * app/tools/gimpcolorbalancetool.h * app/tools/gimpcurvestool.h * app/tools/gimpdodgeburntool.c * app/tools/gimpfreeselecttool.h * app/tools/gimphuesaturationtool.h * app/tools/gimpinktool-blob.h * app/tools/gimpinktool.h * app/tools/gimpiscissorstool.h * app/tools/gimpmagnifytool.h * app/tools/gimpmeasuretool.h * app/tools/gimppainttool.h * app/tools/gimppathtool.h * app/tools/gimprectselecttool.h * app/tools/gimpthresholdtool.h * app/tools/gimptool.h * app/tools/gimptransformtool.h * app/base/base-config.h * app/base/gimplut.[ch] * app/base/pixel-region.h * app/base/pixel-surround.[ch] * app/base/temp-buf.[ch] * app/base/tile-manager-private.h * app/base/tile-manager.[ch] * app/base/tile-private.h * app/base/tile.[ch] * app/display/gimpdisplay.h * app/display/gimpdisplayshell-selection.h * app/display/gimpdisplayshell.h * app/gui/brush-select.h * app/gui/gradient-editor.h * app/gui/gradient-select.h: reverted most of Daniel's changes. There's no reason to use unsigned integers here and in lots of places it is even wrong. Then it's way too early to convert gbooleans into bitfields. This change may make sense in a few places but can happen later when the API has settled and the code is more stable. * app/gimprc.c: reverted Daniel's change. This is a GCC-ism and this code is about to die soon anyway.
404 lines
7.4 KiB
C
404 lines
7.4 KiB
C
/* The GIMP -- an image manipulation program
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include <glib.h>
|
|
|
|
#include "base-types.h"
|
|
|
|
#include "tile.h"
|
|
#include "tile-private.h"
|
|
#include "tile-cache.h"
|
|
#include "tile-manager.h"
|
|
#include "tile-swap.h"
|
|
|
|
|
|
static void tile_destroy (Tile *tile);
|
|
|
|
|
|
gint tile_count = 0;
|
|
|
|
|
|
void
|
|
tile_sanitize_rowhints (Tile *tile)
|
|
{
|
|
gint height, y;
|
|
|
|
/* If tile has rowhints array already, do nothing. */
|
|
if (tile->rowhint)
|
|
return;
|
|
|
|
height = tile->eheight;
|
|
|
|
tile->rowhint = g_new (TileRowHint, height);
|
|
|
|
for (y=0; y<height; y++)
|
|
{
|
|
tile->rowhint[y] = TILEROWHINT_UNKNOWN;
|
|
}
|
|
}
|
|
|
|
TileRowHint
|
|
tile_get_rowhint (Tile *tile,
|
|
gint yoff)
|
|
{
|
|
#ifdef HINTS_SANITY
|
|
if (yoff < tile_eheight(tile) && yoff>=0)
|
|
{
|
|
return tile->rowhint[yoff];
|
|
}
|
|
else
|
|
g_error("GET_ROWHINT OUT OF RANGE");
|
|
return TILEROWHINT_OUTOFRANGE;
|
|
#else
|
|
return tile->rowhint[yoff];
|
|
#endif
|
|
}
|
|
|
|
void
|
|
tile_set_rowhint (Tile *tile,
|
|
gint yoff,
|
|
TileRowHint rowhint)
|
|
{
|
|
#ifdef HINTS_SANITY
|
|
if (yoff < tile_eheight(tile) && yoff>=0)
|
|
{
|
|
tile->rowhint[yoff] = rowhint;
|
|
}
|
|
else
|
|
g_error("SET_ROWHINT OUT OF RANGE");
|
|
#else
|
|
tile->rowhint[yoff] = rowhint;
|
|
#endif
|
|
}
|
|
|
|
void
|
|
tile_init (Tile *tile,
|
|
gint bpp)
|
|
{
|
|
tile->ref_count = 0;
|
|
tile->write_count = 0;
|
|
tile->share_count = 0;
|
|
tile->dirty = FALSE;
|
|
tile->valid = FALSE;
|
|
tile->data = NULL;
|
|
tile->ewidth = TILE_WIDTH;
|
|
tile->eheight = TILE_HEIGHT;
|
|
tile->bpp = bpp;
|
|
tile->swap_num = 1;
|
|
tile->swap_offset = -1;
|
|
tile->tlink = NULL;
|
|
tile->next = NULL;
|
|
tile->prev = NULL;
|
|
tile->listhead = NULL;
|
|
tile->rowhint = NULL;
|
|
|
|
#ifdef USE_PTHREADS
|
|
{
|
|
pthread_mutex_init (&tile->mutex, NULL);
|
|
}
|
|
#endif
|
|
|
|
tile_count++;
|
|
}
|
|
|
|
gint tile_ref_count = 0;
|
|
gint tile_share_count = 0;
|
|
gint tile_active_count = 0;
|
|
|
|
#ifdef HINTS_SANITY
|
|
gint tile_exist_peak = 0;
|
|
gint tile_exist_count = 0;
|
|
#endif
|
|
|
|
void
|
|
tile_lock (Tile *tile)
|
|
{
|
|
/* Increment the global reference count.
|
|
*/
|
|
tile_ref_count++;
|
|
|
|
/* Increment this tile's reference count.
|
|
*/
|
|
|
|
TILE_MUTEX_LOCK (tile);
|
|
tile->ref_count++;
|
|
|
|
if (tile->ref_count == 1)
|
|
{
|
|
if (tile->listhead)
|
|
{
|
|
/* remove from cache, move to main store */
|
|
tile_cache_flush (tile);
|
|
}
|
|
tile_active_count++;
|
|
}
|
|
if (tile->data == NULL)
|
|
{
|
|
/* There is no data, so the tile must be swapped out */
|
|
tile_swap_in (tile);
|
|
}
|
|
|
|
TILE_MUTEX_UNLOCK (tile);
|
|
|
|
/* Call 'tile_manager_validate' if the tile was invalid.
|
|
*/
|
|
if (!tile->valid)
|
|
{
|
|
/* an invalid tile should never be shared, so this should work */
|
|
tile_manager_validate ((TileManager*) tile->tlink->tm, tile);
|
|
}
|
|
}
|
|
|
|
void
|
|
tile_release (Tile *tile,
|
|
gboolean dirty)
|
|
{
|
|
/* Decrement the global reference count.
|
|
*/
|
|
tile_ref_count--;
|
|
|
|
TILE_MUTEX_LOCK (tile);
|
|
|
|
/* Decrement this tile's reference count.
|
|
*/
|
|
tile->ref_count--;
|
|
|
|
/* Decrement write ref count if dirtying
|
|
*/
|
|
if (dirty)
|
|
{
|
|
gint y;
|
|
|
|
tile->write_count--;
|
|
|
|
if (tile->rowhint)
|
|
{
|
|
for (y = 0; y < tile->eheight; y++)
|
|
{
|
|
tile->rowhint[y] = TILEROWHINT_UNKNOWN;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (tile->ref_count == 0)
|
|
{
|
|
tile_active_count--;
|
|
|
|
if (tile->share_count == 0)
|
|
{
|
|
/* tile is truly dead */
|
|
tile_destroy (tile);
|
|
return; /* skip terminal unlock */
|
|
}
|
|
else
|
|
{
|
|
/* last reference was just released, so move the tile to the
|
|
tile cache */
|
|
tile_cache_insert (tile);
|
|
}
|
|
}
|
|
|
|
TILE_MUTEX_UNLOCK (tile);
|
|
}
|
|
|
|
void
|
|
tile_alloc (Tile *tile)
|
|
{
|
|
if (tile->data)
|
|
return;
|
|
|
|
/* Allocate the data for the tile.
|
|
*/
|
|
tile->data = g_new (guchar, tile_size (tile));
|
|
|
|
#ifdef HINTS_SANITY
|
|
tile_exist_count++;
|
|
if (tile_exist_count > tile_exist_peak)
|
|
tile_exist_peak = tile_exist_count;
|
|
#endif
|
|
}
|
|
|
|
static void
|
|
tile_destroy (Tile *tile)
|
|
{
|
|
if (tile->ref_count)
|
|
{
|
|
g_warning ("tried to destroy a ref'd tile");
|
|
return;
|
|
}
|
|
if (tile->share_count)
|
|
{
|
|
g_warning ("tried to destroy an attached tile");
|
|
return;
|
|
}
|
|
if (tile->data)
|
|
{
|
|
g_free (tile->data);
|
|
tile->data = NULL;
|
|
}
|
|
if (tile->rowhint)
|
|
{
|
|
g_free (tile->rowhint);
|
|
tile->rowhint = 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);
|
|
|
|
tile_count--;
|
|
|
|
#ifdef HINTS_SANITY
|
|
tile_exist_count--;
|
|
#endif
|
|
}
|
|
|
|
gint
|
|
tile_size (Tile *tile)
|
|
{
|
|
/* Return the actual size of the tile data.
|
|
* (Based on its effective width and height).
|
|
*/
|
|
return tile->ewidth * tile->eheight * tile->bpp;
|
|
}
|
|
|
|
gint
|
|
tile_ewidth (Tile *tile)
|
|
{
|
|
return tile->ewidth;
|
|
}
|
|
|
|
gint
|
|
tile_eheight (Tile *tile)
|
|
{
|
|
return tile->eheight;
|
|
}
|
|
|
|
gint
|
|
tile_bpp (Tile *tile)
|
|
{
|
|
return tile->bpp;
|
|
}
|
|
|
|
gint
|
|
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);
|
|
}
|
|
|
|
void
|
|
tile_attach (Tile *tile,
|
|
void *tm,
|
|
gint tile_num)
|
|
{
|
|
TileLink *tmp;
|
|
|
|
if ((tile->share_count > 0) && (!tile->valid))
|
|
{
|
|
/* trying to share invalid tiles is problematic, not to mention silly */
|
|
tile_manager_validate ((TileManager*) tile->tlink->tm, tile);
|
|
}
|
|
|
|
tile->share_count++;
|
|
tile_share_count++;
|
|
|
|
#ifdef TILE_DEBUG
|
|
g_print("tile_attach: %p -> (%p,%d) *%d\n", tile, tm, tile_num, tile->share_count);
|
|
#endif
|
|
|
|
/* 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;
|
|
}
|
|
|
|
void
|
|
tile_detach (Tile *tile,
|
|
void *tm,
|
|
gint tile_num)
|
|
{
|
|
TileLink **link;
|
|
TileLink *tmp;
|
|
|
|
#ifdef TILE_DEBUG
|
|
g_print("tile_detach: %p ~> (%p,%d) r%d *%d\n", tile, tm, tile_num,
|
|
tile->ref_count, tile->share_count);
|
|
#endif
|
|
|
|
for (link = &tile->tlink;
|
|
*link != NULL;
|
|
link = &(*link)->next)
|
|
{
|
|
if (((*link)->tm == tm) && ((*link)->tile_num == tile_num))
|
|
break;
|
|
}
|
|
|
|
if (*link == NULL)
|
|
{
|
|
g_warning ("Tried to detach a nonattached tile -- TILE BUG!");
|
|
return;
|
|
}
|
|
|
|
tmp = *link;
|
|
*link = tmp->next;
|
|
g_free (tmp);
|
|
|
|
tile_share_count--;
|
|
tile->share_count--;
|
|
|
|
if (tile->share_count == 0 && tile->ref_count == 0)
|
|
{
|
|
tile_destroy (tile);
|
|
return;
|
|
}
|
|
TILE_MUTEX_UNLOCK (tile);
|
|
}
|
|
|
|
gpointer
|
|
tile_data_pointer (Tile *tile,
|
|
gint xoff,
|
|
gint yoff)
|
|
{
|
|
gint offset;
|
|
|
|
offset = yoff * tile->ewidth + xoff;
|
|
|
|
return (gpointer) (tile->data + offset * tile->bpp);
|
|
}
|