2000-05-31 14:15:06 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimptile.c
|
1998-01-25 18:26:47 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
1999-11-18 05:13:50 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1998-01-25 18:26:47 +08:00
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-18 06:28:01 +08:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2000-05-31 14:15:06 +08:00
|
|
|
*
|
|
|
|
* This library 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
|
1998-01-25 18:26:47 +08:00
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
1999-11-18 05:13:50 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
2000-05-31 14:15:06 +08:00
|
|
|
*/
|
|
|
|
|
2002-05-14 07:30:23 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <string.h>
|
2000-05-31 14:15:06 +08:00
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gio/gio.h>
|
2001-05-21 21:58:46 +08:00
|
|
|
|
2012-05-03 07:50:14 +08:00
|
|
|
#define GIMP_DISABLE_DEPRECATION_WARNINGS
|
|
|
|
|
2001-05-21 21:58:46 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
#include "libgimpbase/gimpprotocol.h"
|
|
|
|
#include "libgimpbase/gimpwire.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "gimp.h"
|
|
|
|
|
|
|
|
|
2010-07-07 17:48:10 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimptile
|
|
|
|
* @title: gimptile
|
|
|
|
* @short_description: Functions for working with tiles.
|
|
|
|
*
|
|
|
|
* Functions for working with tiles.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2003-10-14 00:52:49 +08:00
|
|
|
/* This is the percentage of the maximum cache size that
|
|
|
|
* should be cleared from the cache when an eviction is
|
2000-05-31 14:15:06 +08:00
|
|
|
* necessary.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
#define FREE_QUANTUM 0.1
|
|
|
|
|
2004-02-16 06:18:17 +08:00
|
|
|
|
2005-12-13 22:11:56 +08:00
|
|
|
void gimp_read_expect_msg (GimpWireMessage *msg,
|
2006-04-12 18:53:28 +08:00
|
|
|
gint type);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-12-13 22:11:56 +08:00
|
|
|
static void gimp_tile_get (GimpTile *tile);
|
|
|
|
static void gimp_tile_put (GimpTile *tile);
|
|
|
|
static void gimp_tile_cache_insert (GimpTile *tile);
|
|
|
|
static void gimp_tile_cache_flush (GimpTile *tile);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
2004-02-16 06:18:17 +08:00
|
|
|
/* private variables */
|
|
|
|
|
2003-10-14 00:52:49 +08:00
|
|
|
static GHashTable * tile_hash_table = NULL;
|
|
|
|
static GList * tile_list_head = NULL;
|
|
|
|
static GList * tile_list_tail = NULL;
|
|
|
|
static gulong max_tile_size = 0;
|
|
|
|
static gulong cur_cache_size = 0;
|
|
|
|
static gulong max_cache_size = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
2004-02-16 06:18:17 +08:00
|
|
|
/* public functions */
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
void
|
2000-05-31 14:15:06 +08:00
|
|
|
gimp_tile_ref (GimpTile *tile)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-16 06:18:17 +08:00
|
|
|
g_return_if_fail (tile != NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-16 06:18:17 +08:00
|
|
|
tile->ref_count++;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-16 06:18:17 +08:00
|
|
|
if (tile->ref_count == 1)
|
|
|
|
{
|
|
|
|
gimp_tile_get (tile);
|
|
|
|
tile->dirty = FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2004-02-16 06:18:17 +08:00
|
|
|
|
|
|
|
gimp_tile_cache_insert (tile);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-05-31 14:15:06 +08:00
|
|
|
gimp_tile_ref_zero (GimpTile *tile)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-10-14 00:52:49 +08:00
|
|
|
g_return_if_fail (tile != NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-10-14 00:52:49 +08:00
|
|
|
tile->ref_count++;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-10-14 00:52:49 +08:00
|
|
|
if (tile->ref_count == 1)
|
|
|
|
tile->data = g_new0 (guchar, tile->ewidth * tile->eheight * tile->bpp);
|
|
|
|
|
|
|
|
gimp_tile_cache_insert (tile);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-05-31 14:15:06 +08:00
|
|
|
gimp_tile_unref (GimpTile *tile,
|
2006-04-12 18:53:28 +08:00
|
|
|
gboolean dirty)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-10-14 00:52:49 +08:00
|
|
|
g_return_if_fail (tile != NULL);
|
2004-02-16 06:18:17 +08:00
|
|
|
g_return_if_fail (tile->ref_count > 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-10-14 00:52:49 +08:00
|
|
|
tile->ref_count--;
|
|
|
|
tile->dirty |= dirty;
|
|
|
|
|
|
|
|
if (tile->ref_count == 0)
|
|
|
|
{
|
|
|
|
gimp_tile_flush (tile);
|
|
|
|
g_free (tile->data);
|
|
|
|
tile->data = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-05-31 14:15:06 +08:00
|
|
|
gimp_tile_flush (GimpTile *tile)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-10-14 00:52:49 +08:00
|
|
|
g_return_if_fail (tile != NULL);
|
|
|
|
|
|
|
|
if (tile->data && tile->dirty)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
gimp_tile_put (tile);
|
|
|
|
tile->dirty = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-14 00:52:49 +08:00
|
|
|
/**
|
|
|
|
* gimp_tile_cache_size:
|
|
|
|
* @kilobytes: new cache size in kilobytes
|
|
|
|
*
|
|
|
|
* Sets the size of the tile cache on the plug-in side. The tile cache
|
|
|
|
* is used to reduce the number of tiles exchanged between the GIMP core
|
|
|
|
* and the plug-in. See also gimp_tile_cache_ntiles().
|
|
|
|
**/
|
1997-11-25 06:05:25 +08:00
|
|
|
void
|
|
|
|
gimp_tile_cache_size (gulong kilobytes)
|
|
|
|
{
|
|
|
|
max_cache_size = kilobytes * 1024;
|
|
|
|
}
|
|
|
|
|
2003-10-14 00:52:49 +08:00
|
|
|
/**
|
|
|
|
* gimp_tile_cache_ntiles:
|
|
|
|
* @ntiles: number of tiles that should fit into the cache
|
|
|
|
*
|
|
|
|
* Sets the size of the tile cache on the plug-in side. This function
|
2012-11-11 22:50:25 +08:00
|
|
|
* is similar to gimp_tile_cache_size() but supports specifying the
|
2003-10-14 00:52:49 +08:00
|
|
|
* number of tiles directly.
|
|
|
|
*
|
|
|
|
* If your plug-in access pixels tile-by-tile, it doesn't need a tile
|
|
|
|
* cache at all. If however the plug-in accesses drawable pixel data
|
|
|
|
* row-by-row, it should set the tile cache large enough to hold the
|
|
|
|
* number of tiles per row. Double this size if your plug-in uses
|
|
|
|
* shadow tiles.
|
|
|
|
**/
|
1997-11-25 06:05:25 +08:00
|
|
|
void
|
|
|
|
gimp_tile_cache_ntiles (gulong ntiles)
|
|
|
|
{
|
2003-10-14 00:52:49 +08:00
|
|
|
gimp_tile_cache_size ((ntiles *
|
|
|
|
gimp_tile_width () *
|
|
|
|
gimp_tile_height () * 4 + 1023) / 1024);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2004-02-17 05:57:01 +08:00
|
|
|
void
|
|
|
|
_gimp_tile_cache_flush_drawable (GimpDrawable *drawable)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
g_return_if_fail (drawable != NULL);
|
|
|
|
|
|
|
|
list = tile_list_head;
|
|
|
|
while (list)
|
|
|
|
{
|
|
|
|
GimpTile *tile = list->data;
|
|
|
|
|
|
|
|
list = list->next;
|
|
|
|
|
|
|
|
if (tile->drawable == drawable)
|
|
|
|
gimp_tile_cache_flush (tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-16 06:18:17 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2000-05-31 14:15:06 +08:00
|
|
|
gimp_tile_get (GimpTile *tile)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-03-07 20:56:03 +08:00
|
|
|
extern GIOChannel *_writechannel;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-12-13 22:11:56 +08:00
|
|
|
GPTileReq tile_req;
|
|
|
|
GPTileData *tile_data;
|
|
|
|
GimpWireMessage msg;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-06-15 04:07:38 +08:00
|
|
|
tile_req.drawable_ID = tile->drawable->drawable_id;
|
2004-02-17 02:00:25 +08:00
|
|
|
tile_req.tile_num = tile->tile_num;
|
|
|
|
tile_req.shadow = tile->shadow;
|
|
|
|
|
2002-05-17 01:41:38 +08:00
|
|
|
if (! gp_tile_req_write (_writechannel, &tile_req, NULL))
|
1997-11-25 06:05:25 +08:00
|
|
|
gimp_quit ();
|
|
|
|
|
2002-05-17 01:41:38 +08:00
|
|
|
gimp_read_expect_msg (&msg, GP_TILE_DATA);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
tile_data = msg.data;
|
2003-10-14 00:52:49 +08:00
|
|
|
if (tile_data->drawable_ID != tile->drawable->drawable_id ||
|
|
|
|
tile_data->tile_num != tile->tile_num ||
|
|
|
|
tile_data->shadow != tile->shadow ||
|
|
|
|
tile_data->width != tile->ewidth ||
|
|
|
|
tile_data->height != tile->eheight ||
|
|
|
|
tile_data->bpp != tile->bpp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-10-14 00:52:49 +08:00
|
|
|
g_message ("received tile info did not match computed tile info");
|
1997-11-25 06:05:25 +08:00
|
|
|
gimp_quit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tile_data->use_shm)
|
|
|
|
{
|
2003-10-14 00:52:49 +08:00
|
|
|
tile->data = g_memdup (gimp_shm_addr (),
|
|
|
|
tile->ewidth * tile->eheight * tile->bpp);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tile->data = tile_data->data;
|
|
|
|
tile_data->data = NULL;
|
|
|
|
}
|
|
|
|
|
2002-05-17 01:41:38 +08:00
|
|
|
if (! gp_tile_ack_write (_writechannel, NULL))
|
1997-11-25 06:05:25 +08:00
|
|
|
gimp_quit ();
|
1998-03-01 09:18:45 +08:00
|
|
|
|
2005-12-13 22:11:56 +08:00
|
|
|
gimp_wire_destroy (&msg);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-05-31 14:15:06 +08:00
|
|
|
gimp_tile_put (GimpTile *tile)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-03-07 20:56:03 +08:00
|
|
|
extern GIOChannel *_writechannel;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-12-13 22:11:56 +08:00
|
|
|
GPTileReq tile_req;
|
|
|
|
GPTileData tile_data;
|
|
|
|
GPTileData *tile_info;
|
|
|
|
GimpWireMessage msg;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
tile_req.drawable_ID = -1;
|
2004-02-17 02:00:25 +08:00
|
|
|
tile_req.tile_num = 0;
|
|
|
|
tile_req.shadow = 0;
|
|
|
|
|
2002-05-17 01:41:38 +08:00
|
|
|
if (! gp_tile_req_write (_writechannel, &tile_req, NULL))
|
1997-11-25 06:05:25 +08:00
|
|
|
gimp_quit ();
|
|
|
|
|
2002-05-17 01:41:38 +08:00
|
|
|
gimp_read_expect_msg (&msg, GP_TILE_DATA);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
tile_info = msg.data;
|
|
|
|
|
2001-06-15 04:07:38 +08:00
|
|
|
tile_data.drawable_ID = tile->drawable->drawable_id;
|
2002-05-17 01:41:38 +08:00
|
|
|
tile_data.tile_num = tile->tile_num;
|
|
|
|
tile_data.shadow = tile->shadow;
|
|
|
|
tile_data.bpp = tile->bpp;
|
|
|
|
tile_data.width = tile->ewidth;
|
|
|
|
tile_data.height = tile->eheight;
|
|
|
|
tile_data.use_shm = tile_info->use_shm;
|
|
|
|
tile_data.data = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (tile_info->use_shm)
|
2003-10-14 00:52:49 +08:00
|
|
|
memcpy (gimp_shm_addr (),
|
|
|
|
tile->data,
|
Changed the semantics of GIMP_EXTENSION and (to some extent) of
2003-06-19 Michael Natterer <mitch@gimp.org>
Changed the semantics of GIMP_EXTENSION and (to some extent)
of GIMP_PLUGIN:
The old meaning of EXTENSION was "I live in the toolbox" and
PLUGIN meant "I take RUN-MODE,IMAGE,DRAWABLE args (but only if I
am invoked interactively)". This is completely useless, since
living in the toolbox means having "<Toolbox>" in the menu_path
and taking RUN-MODE,IMAGE,DRAWABLE means just that, regardless of
what type of procedure we are.
The new meaning of GIMP_PLUGIN is just "I am an ordinary procedure,
I am invoked, do my job and finish", while GIMP_EXTENSION means
"I will install temporary procedures and I will keep running to
keep them available".
(A GIMP_EXTENSION *must* call gimp_extension_ack() now to tell the
core that it's ready to run, or the core will block waiting for
the message !!!).
* configure.in: bumped version number to 1.3.16.
* libgimpbase/gimpprotocol.h: increased protocol version number so
old extensions will refuse to load.
* app/gui/plug-in-commands.c (plug_in_run_cmd_callback): don't
blindly pass RUN-MODE,IMAGE,DRAWABLE to GIMP_PLUGIN procedures but
look at their parameters and pass them either RUN-MODE, or
RUN-MODE,IMAGE, or RUN-MODE,IMAGE,DRAWABLE.
* app/pdb/procedural_db.c: cleaned up, better error reporting,
replaced an impossible error message by g_return_if_fail()
* app/plug-in/plug-in-message.c (plug_in_handle_proc_install):
better error messages.
* app/plug-in/plug-in-params.c: allocate parameter arrays using
g_new0() so we don't have to worry about uninitialized stuff
later.
* app/plug-in/plug-in-run.c (plug_in_run): wait for
gimp_extension_ack() installation confirmation for ALL extensions,
not just for automatically started ones.
* app/plug-in/plug-ins.c: cleanup.
* libgimp/gimp.[ch]: cleaned up and API-documented massively. Made
all magic values given in the GPConfig message static and added
accessor functions for them. Added gimp_tile_width()/height().
Added new function gimp_extension_enable() which turns on
asynchronous processing of temp_proc run requests without having
to enter an endless gimp_extension_process() loop. Moved all
private functions to the end of the file. Added tons of
g_return_if_fail() all over the place. Call gimp_run_procedure2()
from gimp_run_procedure() instead of duplicating the
code. Indentation, spacing, stuff...
* libgimp/gimptile.[ch]: removed gimp_tile_width()/height().
* libgimp/gimpdrawable.c
* libgimp/gimppixelrgn.c
* libgimp/gimptile.c: use the gimp_tile_width()/height() accessor
functions.
* libgimp/gimp.def: added gimp_extension_enable.
* libgimp/gimpmenu.c: removed evil code which connected to
_readchannel manually and use gimp_extension_enable() for watching
temp_procs.
* plug-ins/helpbrowser/helpbrowser.c: removed the same evil code
here and call gimp_extension_enable(). Call gimp_extension_ack()
to let the core know that the temp_proc is installed.
* plug-ins/script-fu/script-fu.c: made all procedures except the
permanently running "extension_script_fu" ordinary GIMP_PLUGIN
procedures.
* plug-ins/common/curve_bend.c
* plug-ins/common/plugindetails.c
* plug-ins/common/screenshot.c
* plug-ins/common/uniteditor.c
* plug-ins/common/winclipboard.c
* plug-ins/dbbrowser/dbbrowser.c
* plug-ins/gfli/gfli.c
* plug-ins/twain/twain.c
* plug-ins/webbrowser/webbrowser.c
* plug-ins/winsnap/winsnap.c: made them all ordinary GIMP_PLUGIN
procedures and renamed them from "extension_*" to "plug_in_*".
Random cleanups.
* app/widgets/gimphelp.c
* plug-ins/maze/maze_face.c: call "plug_in_web_browser" now.
2003-06-20 01:12:00 +08:00
|
|
|
tile->ewidth * tile->eheight * tile->bpp);
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
tile_data.data = tile->data;
|
|
|
|
|
2002-05-17 01:41:38 +08:00
|
|
|
if (! gp_tile_data_write (_writechannel, &tile_data, NULL))
|
1997-11-25 06:05:25 +08:00
|
|
|
gimp_quit ();
|
|
|
|
|
2012-10-23 01:03:00 +08:00
|
|
|
if (! tile_info->use_shm)
|
|
|
|
tile_data.data = NULL;
|
|
|
|
|
2005-12-13 22:11:56 +08:00
|
|
|
gimp_wire_destroy (&msg);
|
1998-03-01 09:18:45 +08:00
|
|
|
|
2005-01-15 20:09:25 +08:00
|
|
|
gimp_read_expect_msg (&msg, GP_TILE_ACK);
|
2005-12-13 22:11:56 +08:00
|
|
|
gimp_wire_destroy (&msg);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This function is nearly identical to the function 'tile_cache_insert'
|
|
|
|
* in the file 'tile_cache.c' which is part of the main gimp application.
|
|
|
|
*/
|
|
|
|
static void
|
2000-05-31 14:15:06 +08:00
|
|
|
gimp_tile_cache_insert (GimpTile *tile)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-17 02:00:25 +08:00
|
|
|
GList *list;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (!tile_hash_table)
|
|
|
|
{
|
2003-10-14 00:52:49 +08:00
|
|
|
tile_hash_table = g_hash_table_new (g_direct_hash, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
max_tile_size = gimp_tile_width () * gimp_tile_height () * 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* First check and see if the tile is already
|
|
|
|
* in the cache. In that case we will simply place
|
|
|
|
* it at the end of the tile list to indicate that
|
|
|
|
* it was the most recently accessed tile.
|
|
|
|
*/
|
2004-02-17 02:00:25 +08:00
|
|
|
list = g_hash_table_lookup (tile_hash_table, tile);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-17 02:00:25 +08:00
|
|
|
if (list)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
/* The tile was already in the cache. Place it at
|
|
|
|
* the end of the tile list.
|
|
|
|
*/
|
|
|
|
|
2004-02-17 02:00:25 +08:00
|
|
|
/* If the tile is already at the end of the list, we are done */
|
|
|
|
if (list == tile_list_tail)
|
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-17 02:00:25 +08:00
|
|
|
/* At this point we have at least two elements in our list */
|
|
|
|
g_assert (tile_list_head != tile_list_tail);
|
|
|
|
|
|
|
|
tile_list_head = g_list_remove_link (tile_list_head, list);
|
|
|
|
|
2006-04-03 00:12:03 +08:00
|
|
|
tile_list_tail = g_list_last (g_list_concat (tile_list_tail, list));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The tile was not in the cache. First check and see
|
|
|
|
* if there is room in the cache. If not then we'll have
|
|
|
|
* to make room first. Note: it might be the case that the
|
|
|
|
* cache is smaller than the size of a tile in which case
|
|
|
|
* it won't be possible to put it in the cache.
|
|
|
|
*/
|
2004-02-17 02:00:25 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if ((cur_cache_size + max_tile_size) > max_cache_size)
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
while (tile_list_head &&
|
2003-10-14 00:52:49 +08:00
|
|
|
(cur_cache_size +
|
|
|
|
max_cache_size * FREE_QUANTUM) > max_cache_size)
|
|
|
|
{
|
|
|
|
gimp_tile_cache_flush ((GimpTile *) tile_list_head->data);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
if ((cur_cache_size + max_tile_size) > max_cache_size)
|
|
|
|
return;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Place the tile at the end of the tile list.
|
|
|
|
*/
|
|
|
|
tile_list_tail = g_list_append (tile_list_tail, tile);
|
2004-02-17 02:00:25 +08:00
|
|
|
|
|
|
|
if (! tile_list_head)
|
2006-04-12 18:53:28 +08:00
|
|
|
tile_list_head = tile_list_tail;
|
2004-02-17 02:00:25 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
tile_list_tail = g_list_last (tile_list_tail);
|
|
|
|
|
|
|
|
/* Add the tiles list node to the tile hash table.
|
|
|
|
*/
|
|
|
|
g_hash_table_insert (tile_hash_table, tile, tile_list_tail);
|
|
|
|
|
|
|
|
/* Note the increase in the number of bytes the cache
|
|
|
|
* is referencing.
|
|
|
|
*/
|
|
|
|
cur_cache_size += max_tile_size;
|
|
|
|
|
|
|
|
/* Reference the tile so that it won't be returned to
|
|
|
|
* the main gimp application immediately.
|
|
|
|
*/
|
2003-10-14 00:52:49 +08:00
|
|
|
tile->ref_count++;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-05-31 14:15:06 +08:00
|
|
|
gimp_tile_cache_flush (GimpTile *tile)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-17 02:00:25 +08:00
|
|
|
GList *list;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-17 02:00:25 +08:00
|
|
|
if (! tile_hash_table)
|
2003-10-14 00:52:49 +08:00
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Find where the tile is in the cache.
|
|
|
|
*/
|
2004-02-17 02:00:25 +08:00
|
|
|
list = g_hash_table_lookup (tile_hash_table, tile);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-17 02:00:25 +08:00
|
|
|
if (list)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
/* If the tile is in the cache, then remove it from the
|
|
|
|
* tile list.
|
|
|
|
*/
|
2004-02-17 02:00:25 +08:00
|
|
|
if (list == tile_list_tail)
|
1997-11-25 06:05:25 +08:00
|
|
|
tile_list_tail = tile_list_tail->prev;
|
2004-02-17 02:00:25 +08:00
|
|
|
|
|
|
|
tile_list_head = g_list_remove_link (tile_list_head, list);
|
|
|
|
|
|
|
|
if (! tile_list_head)
|
1997-11-25 06:05:25 +08:00
|
|
|
tile_list_tail = NULL;
|
|
|
|
|
|
|
|
/* Remove the tile from the tile hash table.
|
|
|
|
*/
|
|
|
|
g_hash_table_remove (tile_hash_table, tile);
|
2004-02-17 02:00:25 +08:00
|
|
|
g_list_free (list);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Note the decrease in the number of bytes the cache
|
|
|
|
* is referencing.
|
|
|
|
*/
|
|
|
|
cur_cache_size -= max_tile_size;
|
|
|
|
|
|
|
|
/* Unreference the tile.
|
|
|
|
*/
|
|
|
|
gimp_tile_unref (tile, FALSE);
|
|
|
|
}
|
|
|
|
}
|