1998-06-21 01:09:32 +08:00
|
|
|
#include <gtk/gtkmain.h>
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <glib.h>
|
|
|
|
#include "gimprc.h"
|
1998-07-03 07:29:44 +08:00
|
|
|
#include "tile.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "tile_cache.h"
|
|
|
|
#include "tile_swap.h"
|
1998-06-21 01:09:32 +08:00
|
|
|
#ifdef USE_PTHREADS
|
|
|
|
#include <pthread.h>
|
|
|
|
#endif
|
|
|
|
|
1998-07-08 14:41:58 +08:00
|
|
|
#include "tile_pvt.h" /* ick. */
|
|
|
|
|
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-06-21 01:09:32 +08:00
|
|
|
#include "stdio.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* This is the percentage of the maximum cache size that should be cleared
|
|
|
|
* from the cache when an eviction is necessary
|
|
|
|
*/
|
|
|
|
#define FREE_QUANTUM 0.1
|
|
|
|
|
1998-06-21 01:09:32 +08:00
|
|
|
static void tile_cache_init (void);
|
|
|
|
static gint tile_cache_zorch_next (void);
|
|
|
|
static void tile_cache_flush_internal (Tile *tile);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-06-21 01:09:32 +08:00
|
|
|
#ifdef USE_PTHREADS
|
|
|
|
static void* tile_idle_thread (void *);
|
|
|
|
#else
|
|
|
|
static gint tile_idle_preswap (gpointer);
|
|
|
|
#endif
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static int initialize = TRUE;
|
1998-06-21 01:09:32 +08:00
|
|
|
|
|
|
|
typedef struct _TileList {
|
|
|
|
Tile* first;
|
|
|
|
Tile* last;
|
|
|
|
} TileList;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static unsigned long max_tile_size = TILE_WIDTH * TILE_HEIGHT * 4;
|
|
|
|
static unsigned long cur_cache_size = 0;
|
|
|
|
static unsigned long max_cache_size = 0;
|
1998-06-21 01:09:32 +08:00
|
|
|
static unsigned long cur_cache_dirty = 0;
|
|
|
|
static TileList clean_list = { NULL, NULL };
|
|
|
|
static TileList dirty_list = { NULL, NULL };
|
|
|
|
|
|
|
|
#ifdef USE_PTHREADS
|
|
|
|
static pthread_t preswap_thread;
|
|
|
|
static pthread_mutex_t dirty_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
static pthread_cond_t dirty_signal = PTHREAD_COND_INITIALIZER;
|
|
|
|
static pthread_mutex_t tile_mutex = PTHREAD_MUTEX_INITIALIZER;
|
1998-07-10 10:43:12 +08:00
|
|
|
#define CACHE_LOCK pthread_mutex_lock(&tile_mutex)
|
|
|
|
#define CACHE_UNLOCK pthread_mutex_unlock(&tile_mutex)
|
1998-06-21 01:09:32 +08:00
|
|
|
#else
|
|
|
|
static gint idle_swapper = 0;
|
1998-07-10 10:43:12 +08:00
|
|
|
#define CACHE_LOCK /*nothing*/
|
|
|
|
#define CACHE_UNLOCK /*nothing*/
|
1998-06-21 01:09:32 +08:00
|
|
|
#endif
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
tile_cache_insert (Tile *tile)
|
|
|
|
{
|
1998-06-21 01:09:32 +08:00
|
|
|
TileList *list;
|
|
|
|
TileList *newlist;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (initialize)
|
|
|
|
tile_cache_init ();
|
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
CACHE_LOCK;
|
1998-06-21 01:09:32 +08:00
|
|
|
if (tile->data == NULL) goto out;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
1998-06-21 01:09:32 +08:00
|
|
|
list = (TileList*)(tile->listhead);
|
|
|
|
newlist = (tile->dirty || tile->swap_offset == -1) ? &dirty_list : &clean_list;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-06-21 01:09:32 +08:00
|
|
|
/* if list is NULL, the tile is not in the cache */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-06-21 01:09:32 +08:00
|
|
|
if (list)
|
|
|
|
{
|
|
|
|
/* Tile is in the cache. Remove it from its current list and
|
|
|
|
put it at the tail of the proper list (clean or dirty) */
|
|
|
|
|
|
|
|
if (tile->next)
|
|
|
|
tile->next->prev = tile->prev;
|
|
|
|
else
|
|
|
|
list->last = tile->prev;
|
|
|
|
|
|
|
|
if (tile->prev)
|
|
|
|
tile->prev->next = tile->next;
|
|
|
|
else
|
|
|
|
list->first = tile->next;
|
|
|
|
|
|
|
|
tile->listhead = NULL;
|
|
|
|
if (list == &dirty_list) cur_cache_dirty -= tile_size (tile);
|
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
|
1998-07-10 10:43:12 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
* it won't be possible to put it in the cache.
|
|
|
|
*/
|
1998-06-21 01:09:32 +08:00
|
|
|
while ((cur_cache_size + max_tile_size) > max_cache_size)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-07-12 01:23:03 +08:00
|
|
|
if (!tile_cache_zorch_next())
|
|
|
|
{
|
1999-06-06 07:41:45 +08:00
|
|
|
g_warning ("cache: unable to find room for a tile");
|
1998-07-12 01:23:03 +08:00
|
|
|
goto out;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1998-06-21 01:09:32 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Note the increase in the number of bytes the cache
|
|
|
|
* is referencing.
|
|
|
|
*/
|
|
|
|
cur_cache_size += tile_size (tile);
|
|
|
|
}
|
1998-06-21 01:09:32 +08:00
|
|
|
|
|
|
|
/* Put the tile at the end of the proper list */
|
|
|
|
|
|
|
|
tile->next = NULL;
|
|
|
|
tile->prev = newlist->last;
|
|
|
|
tile->listhead = newlist;
|
|
|
|
|
|
|
|
if (newlist->last) newlist->last->next = tile;
|
|
|
|
else newlist->first = tile;
|
|
|
|
newlist->last = tile;
|
|
|
|
|
|
|
|
if (tile->dirty)
|
|
|
|
{
|
|
|
|
cur_cache_dirty += tile_size (tile);
|
1998-07-13 06:35:01 +08:00
|
|
|
if (1)
|
|
|
|
{
|
1998-06-21 01:09:32 +08:00
|
|
|
#ifdef USE_PTHREADS
|
1998-07-13 06:35:01 +08:00
|
|
|
pthread_mutex_lock(&dirty_mutex);
|
|
|
|
pthread_cond_signal(&dirty_signal);
|
|
|
|
pthread_mutex_unlock(&dirty_mutex);
|
1998-06-21 01:09:32 +08:00
|
|
|
#endif
|
1998-07-13 06:35:01 +08:00
|
|
|
}
|
1998-06-21 01:09:32 +08:00
|
|
|
}
|
|
|
|
out:
|
1998-07-10 10:43:12 +08:00
|
|
|
CACHE_UNLOCK;
|
1998-06-21 01:09:32 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tile_cache_flush (Tile *tile)
|
|
|
|
{
|
|
|
|
if (initialize)
|
|
|
|
tile_cache_init ();
|
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
CACHE_LOCK;
|
1998-06-21 01:09:32 +08:00
|
|
|
tile_cache_flush_internal (tile);
|
1998-07-10 10:43:12 +08:00
|
|
|
CACHE_UNLOCK;
|
1998-06-21 01:09:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tile_cache_flush_internal (Tile *tile)
|
|
|
|
{
|
|
|
|
TileList *list;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Find where the tile is in the cache.
|
|
|
|
*/
|
1998-06-21 01:09:32 +08:00
|
|
|
|
|
|
|
list = (TileList*)(tile->listhead);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-06-21 01:09:32 +08:00
|
|
|
if (list)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
/* Note the decrease in the number of bytes the cache
|
|
|
|
* is referencing.
|
|
|
|
*/
|
|
|
|
cur_cache_size -= tile_size (tile);
|
1998-06-21 01:09:32 +08:00
|
|
|
if (list == &dirty_list) cur_cache_dirty -= tile_size (tile);
|
|
|
|
|
|
|
|
if (tile->next)
|
|
|
|
tile->next->prev = tile->prev;
|
|
|
|
else
|
|
|
|
list->last = tile->prev;
|
|
|
|
|
|
|
|
if (tile->prev)
|
|
|
|
tile->prev->next = tile->next;
|
|
|
|
else
|
|
|
|
list->first = tile->next;
|
|
|
|
|
|
|
|
tile->listhead = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tile_cache_set_size (unsigned long cache_size)
|
|
|
|
{
|
|
|
|
if (initialize)
|
|
|
|
tile_cache_init ();
|
|
|
|
|
|
|
|
max_cache_size = cache_size;
|
1998-07-10 10:43:12 +08:00
|
|
|
CACHE_LOCK;
|
1998-06-21 01:09:32 +08:00
|
|
|
while (cache_size >= max_cache_size)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-06-21 01:09:32 +08:00
|
|
|
if (!tile_cache_zorch_next ()) break;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1998-07-10 10:43:12 +08:00
|
|
|
CACHE_UNLOCK;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
tile_cache_init ()
|
|
|
|
{
|
|
|
|
if (initialize)
|
|
|
|
{
|
|
|
|
initialize = FALSE;
|
|
|
|
|
1998-06-21 01:09:32 +08:00
|
|
|
clean_list.first = clean_list.last = NULL;
|
|
|
|
dirty_list.first = dirty_list.last = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
max_cache_size = tile_cache_size;
|
1998-06-21 01:09:32 +08:00
|
|
|
|
|
|
|
#ifdef USE_PTHREADS
|
|
|
|
pthread_create (&preswap_thread, NULL, &tile_idle_thread, NULL);
|
|
|
|
#else
|
|
|
|
idle_swapper = gtk_timeout_add (250,
|
|
|
|
(GtkFunction) tile_idle_preswap,
|
|
|
|
(gpointer) 0);
|
|
|
|
#endif
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-06-21 01:09:32 +08:00
|
|
|
static gint
|
1997-11-25 06:05:25 +08:00
|
|
|
tile_cache_zorch_next ()
|
|
|
|
{
|
1998-06-21 01:09:32 +08:00
|
|
|
Tile *tile;
|
|
|
|
|
1998-07-12 01:23:03 +08:00
|
|
|
/* printf("cache zorch: %u/%u\n", cur_cache_size, cur_cache_dirty); */
|
|
|
|
|
1998-06-21 01:09:32 +08:00
|
|
|
if (clean_list.first) tile = clean_list.first;
|
|
|
|
else if (dirty_list.first) tile = dirty_list.first;
|
|
|
|
else return FALSE;
|
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
CACHE_UNLOCK;
|
|
|
|
TILE_MUTEX_LOCK (tile);
|
|
|
|
CACHE_LOCK;
|
1998-06-21 01:09:32 +08:00
|
|
|
tile_cache_flush_internal (tile);
|
1998-07-24 11:58:16 +08:00
|
|
|
if (tile->dirty || tile->swap_offset == -1)
|
1998-07-13 06:35:01 +08:00
|
|
|
{
|
|
|
|
tile_swap_out (tile);
|
|
|
|
}
|
|
|
|
g_free (tile->data);
|
|
|
|
tile->data = NULL;
|
1998-07-10 10:43:12 +08:00
|
|
|
TILE_MUTEX_UNLOCK (tile);
|
1998-06-21 01:09:32 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if USE_PTHREADS
|
|
|
|
static void *
|
|
|
|
tile_idle_thread (void *data)
|
|
|
|
{
|
|
|
|
Tile *tile;
|
|
|
|
TileList *list;
|
1998-07-13 06:35:01 +08:00
|
|
|
int count;
|
1998-06-21 01:09:32 +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
|
|
|
fprintf (stderr,_("starting tile preswapper\n"));
|
1998-06-21 01:09:32 +08:00
|
|
|
|
1998-07-13 06:35:01 +08:00
|
|
|
count = 0;
|
1998-06-21 01:09:32 +08:00
|
|
|
while(1)
|
|
|
|
{
|
1998-07-12 08:59:37 +08:00
|
|
|
CACHE_LOCK;
|
1998-07-13 06:35:01 +08:00
|
|
|
if (count > 5 || dirty_list.first == NULL) {
|
1998-07-12 08:59:37 +08:00
|
|
|
CACHE_UNLOCK;
|
1998-07-13 06:35:01 +08:00
|
|
|
count = 0;
|
1998-06-21 01:09:32 +08:00
|
|
|
pthread_mutex_lock(&dirty_mutex);
|
|
|
|
pthread_cond_wait(&dirty_signal,&dirty_mutex);
|
|
|
|
pthread_mutex_unlock(&dirty_mutex);
|
1998-07-12 08:59:37 +08:00
|
|
|
CACHE_LOCK;
|
1998-06-21 01:09:32 +08:00
|
|
|
}
|
1998-07-10 10:43:12 +08:00
|
|
|
if ((tile = dirty_list.first))
|
1998-06-21 01:09:32 +08:00
|
|
|
{
|
1998-07-12 08:59:37 +08:00
|
|
|
CACHE_UNLOCK;
|
1998-07-10 10:43:12 +08:00
|
|
|
TILE_MUTEX_LOCK (tile);
|
|
|
|
CACHE_LOCK;
|
1998-06-21 01:09:32 +08:00
|
|
|
|
1998-07-12 08:59:37 +08:00
|
|
|
if (tile->dirty)
|
|
|
|
{
|
|
|
|
list = tile->listhead;
|
|
|
|
|
|
|
|
if (list == &dirty_list) cur_cache_dirty -= tile_size (tile);
|
|
|
|
|
|
|
|
if (tile->next)
|
|
|
|
tile->next->prev = tile->prev;
|
|
|
|
else
|
|
|
|
list->last = tile->prev;
|
|
|
|
|
|
|
|
if (tile->prev)
|
|
|
|
tile->prev->next = tile->next;
|
|
|
|
else
|
|
|
|
list->first = tile->next;
|
|
|
|
|
|
|
|
tile->next = NULL;
|
|
|
|
tile->prev = clean_list.last;
|
|
|
|
tile->listhead = &clean_list;
|
|
|
|
|
|
|
|
if (clean_list.last) clean_list.last->next = tile;
|
|
|
|
else clean_list.first = tile;
|
|
|
|
clean_list.last = tile;
|
|
|
|
|
|
|
|
CACHE_UNLOCK;
|
|
|
|
|
|
|
|
tile_swap_out(tile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CACHE_UNLOCK;
|
|
|
|
}
|
1998-07-10 10:43:12 +08:00
|
|
|
|
|
|
|
TILE_MUTEX_UNLOCK (tile);
|
1998-06-21 01:09:32 +08:00
|
|
|
}
|
1998-07-12 08:59:37 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
CACHE_UNLOCK;
|
|
|
|
}
|
1998-07-13 06:35:01 +08:00
|
|
|
count++;
|
1998-06-21 01:09:32 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-06-21 01:09:32 +08:00
|
|
|
#else
|
|
|
|
static gint
|
|
|
|
tile_idle_preswap (gpointer data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-06-21 01:09:32 +08:00
|
|
|
Tile *tile;
|
|
|
|
if (cur_cache_dirty*2 < max_cache_size) return TRUE;
|
|
|
|
if ((tile = dirty_list.first))
|
|
|
|
{
|
|
|
|
tile_swap_out(tile);
|
|
|
|
|
|
|
|
dirty_list.first = tile->next;
|
|
|
|
if (tile->next)
|
|
|
|
tile->next->prev = NULL;
|
|
|
|
else
|
|
|
|
dirty_list.last = NULL;
|
|
|
|
|
|
|
|
tile->next = NULL;
|
|
|
|
tile->prev = clean_list.last;
|
|
|
|
tile->listhead = &clean_list;
|
|
|
|
if (clean_list.last) clean_list.last->next = tile;
|
|
|
|
else clean_list.first = tile;
|
|
|
|
clean_list.last = tile;
|
|
|
|
cur_cache_dirty -= tile_size (tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1998-06-21 01:09:32 +08:00
|
|
|
#endif
|
1998-07-10 10:43:12 +08:00
|
|
|
|