Commit c1363db8 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

Removed "stingy-memory-use" all over the place. This feature was really

2005-06-08  Sven Neumann  <sven@gimp.org>

	Removed "stingy-memory-use" all over the place. This feature was
	really not that useful anymore. The GUI for the preference option
	was already removed for GIMP 2.2.  Fixes bug #306617.

	* app/config/gimpbaseconfig.[ch]: set IGNORE flag on
	"stingy-memory-use".

	* app/config/gimpcoreconfig.h: added a comment that the
	font_path_writable variable is unused.

	* app/base/temp-buf.[ch]: removed code that used to deal with
	swapping temp-bufs to disk.

	* app/base/base.c: made base_config a static variable.

	* app/core/gimpdata.[ch]
	* app/core/gimpdatafactory.[ch]: removed stingy_memory_use
	parameter from data construction methods.

	* app/core/gimp-gradients.c
	* app/core/gimpbrush-load.[ch]
	* app/core/gimpbrush.[ch]
	* app/core/gimpbrushgenerated.[ch]
	* app/core/gimpbrushpipe.[ch]
	* app/core/gimpcontext.c
	* app/core/gimpgradient-load.[ch]
	* app/core/gimpgradient.[ch]
	* app/core/gimppalette-import.c
	* app/core/gimppalette.[ch]
	* app/core/gimppattern.[ch]: changed accordingly.
parent 78e6016a
2005-06-08 Sven Neumann <sven@gimp.org>
Removed "stingy-memory-use" all over the place. This feature was
really not that useful anymore. The GUI for the preference option
was already removed for GIMP 2.2. Fixes bug #306617.
* app/config/gimpbaseconfig.[ch]: set IGNORE flag on
"stingy-memory-use".
* app/config/gimpcoreconfig.h: added a comment that the
font_path_writable variable is unused.
* app/base/temp-buf.[ch]: removed code that used to deal with
swapping temp-bufs to disk.
* app/base/base.c: made base_config a static variable.
* app/core/gimpdata.[ch]
* app/core/gimpdatafactory.[ch]: removed stingy_memory_use
parameter from data construction methods.
* app/core/gimp-gradients.c
* app/core/gimpbrush-load.[ch]
* app/core/gimpbrush.[ch]
* app/core/gimpbrushgenerated.[ch]
* app/core/gimpbrushpipe.[ch]
* app/core/gimpcontext.c
* app/core/gimpgradient-load.[ch]
* app/core/gimpgradient.[ch]
* app/core/gimppalette-import.c
* app/core/gimppalette.[ch]
* app/core/gimppattern.[ch]: changed accordingly.
2005-06-05 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* app/tools/gimpaligntool.[ch]: improve layout of controls. Add
......
......@@ -47,14 +47,10 @@
#include "base.h"
#include "pixel-processor.h"
#include "temp-buf.h"
#include "tile-cache.h"
#include "tile-swap.h"
GimpBaseConfig *base_config = NULL;
static void base_toast_old_swap_files (const gchar *swap_path);
static void base_tile_cache_size_notify (GObject *config,
......@@ -65,6 +61,9 @@ static void base_num_processors_notify (GObject *config,
gpointer data);
static GimpBaseConfig *base_config = NULL;
/* public functions */
gboolean
......@@ -126,7 +125,6 @@ base_exit (void)
g_return_if_fail (base_config != NULL);
pixel_processor_exit ();
swapping_free ();
paint_funcs_free ();
tile_swap_exit ();
tile_cache_exit ();
......
......@@ -18,30 +18,15 @@
#include "config.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <glib-object.h>
#include <glib/gstdio.h>
#ifdef G_OS_WIN32
#include <process.h> /* For _getpid() */
#endif
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "libgimpconfig/gimpconfig.h"
#include "base-types.h"
#include "config/gimpbaseconfig.h"
#include "pixel-region.h"
#include "temp-buf.h"
......@@ -55,12 +40,6 @@ static void temp_buf_to_gray (TempBuf *src_buf,
TempBuf *dest_buf);
#ifdef __GNUC__
#warning FIXME: extern GimpBaseConfig *base_config;
#endif
extern GimpBaseConfig *base_config;
/* Memory management */
static guchar *
......@@ -180,13 +159,11 @@ temp_buf_new (gint width,
temp = g_new (TempBuf, 1);
temp->width = width;
temp->height = height;
temp->bytes = bytes;
temp->x = x;
temp->y = y;
temp->swapped = FALSE;
temp->filename = NULL;
temp->width = width;
temp->height = height;
temp->bytes = bytes;
temp->x = x;
temp->y = y;
temp->data = data = temp_buf_allocate (width * height * bytes);
......@@ -356,10 +333,6 @@ temp_buf_resize (TempBuf *buf,
{
if (size != (buf->width * buf->height * buf->bytes))
{
/* Make sure the temp buf is unswapped */
temp_buf_unswap (buf);
/* Reallocate the data for it */
buf->data = g_renew (guchar, buf->data, size);
}
......@@ -500,18 +473,12 @@ temp_buf_free (TempBuf *temp_buf)
if (temp_buf->data)
g_free (temp_buf->data);
if (temp_buf->swapped)
temp_buf_swap_free (temp_buf);
g_free (temp_buf);
}
guchar *
temp_buf_data (TempBuf *temp_buf)
{
if (temp_buf->swapped)
temp_buf_unswap (temp_buf);
return temp_buf->data;
}
......@@ -520,9 +487,6 @@ temp_buf_data_clear (TempBuf *temp_buf)
{
g_return_val_if_fail (temp_buf != NULL, NULL);
if (temp_buf->swapped)
temp_buf_unswap (temp_buf);
memset (temp_buf->data, 0,
temp_buf->height * temp_buf->width * temp_buf->bytes);
......@@ -536,18 +500,8 @@ temp_buf_get_memsize (TempBuf *temp_buf)
g_return_val_if_fail (temp_buf != NULL, 0);
memsize += sizeof (TempBuf);
if (temp_buf->swapped)
{
memsize += strlen (temp_buf->filename) + 1;
}
else
{
memsize += ((gsize) temp_buf->bytes *
temp_buf->width *
temp_buf->height);
}
memsize += (sizeof (TempBuf)
+ (gsize) temp_buf->bytes * temp_buf->width * temp_buf->height);
return memsize;
}
......@@ -584,235 +538,3 @@ mask_buf_data_clear (MaskBuf *mask_buf)
{
return temp_buf_data_clear ((TempBuf *) mask_buf);
}
/******************************************************************
* temp buffer disk caching functions *
******************************************************************/
/* NOTES:
* Disk caching is setup as follows:
* On a call to temp_buf_swap, the TempBuf parameter is stored
* in a temporary variable called cached_in_memory.
* On the next call to temp_buf_swap, if cached_in_memory is non-null,
* cached_in_memory is moved to disk, and the latest TempBuf parameter
* is stored in cached_in_memory. This method keeps the latest TempBuf
* structure in memory instead of moving it directly to disk as requested.
* On a call to temp_buf_unswap, if cached_in_memory is non-null, it is
* compared against the requested TempBuf. If they are the same, nothing
* must be moved in from disk since it still resides in memory. However,
* if the two pointers are different, the requested TempBuf is retrieved
* from disk. In the former case, cached_in_memory is set to NULL;
* in the latter case, cached_in_memory is left unchanged.
* If temp_buf_swap_free is called, cached_in_memory must be checked
* against the temp buf being freed. If they are the same, then
* cached_in_memory must be set to NULL;
*
* In the case where memory usage is set to "stingy":
* temp bufs are not cached in memory at all, they go right to disk.
*/
/* a static counter for generating unique filenames
*/
static gint tmp_file_index = 0;
/* a static pointer which keeps track of the last request for
* a swapped buffer
*/
static TempBuf *cached_in_memory = NULL;
static gchar *
generate_unique_tmp_filename (GimpBaseConfig *config)
{
gchar *tmpdir;
gchar *tmpfile;
gchar *path;
tmpdir = gimp_config_path_expand (config->temp_path, TRUE, NULL);
tmpfile = g_strdup_printf ("gimp%d.%d",
(gint) getpid (), tmp_file_index++);
path = g_build_filename (tmpdir, tmpfile, NULL);
g_free (tmpfile);
g_free (tmpdir);
return path;
}
void
temp_buf_swap (TempBuf *buf)
{
TempBuf *swap;
gchar *filename;
FILE *fp;
if (!buf || buf->swapped)
return;
/* Set the swapped flag */
buf->swapped = TRUE;
if (base_config->stingy_memory_use)
{
swap = buf;
}
else
{
swap = cached_in_memory;
cached_in_memory = buf;
}
/* For the case where there is no temp buf ready
* to be moved to disk, return
*/
if (! swap)
return;
/* Get a unique filename for caching the data to a UNIX file */
filename = generate_unique_tmp_filename (base_config);
/* Check if generated filename is valid */
if (g_file_test (filename, G_FILE_TEST_IS_DIR))
{
g_message ("Error in temp buf caching: \"%s\" is a directory (cannot overwrite)",
gimp_filename_to_utf8 (filename));
g_free (filename);
return;
}
/* Open file for overwrite */
fp = g_fopen (filename, "wb");
if (fp)
{
gsize blocks_written;
blocks_written = fwrite (swap->data,
swap->width * swap->height * swap->bytes, 1,
fp);
/* Check whether all bytes were written and fclose() was able
to flush its buffers */
if ((0 != fclose (fp)) || (1 != blocks_written))
{
g_unlink (filename);
perror ("Write error on temp buf");
g_message ("Cannot write \"%s\"", gimp_filename_to_utf8 (filename));
g_free (filename);
return;
}
}
else
{
g_unlink (filename);
perror ("Error in temp buf caching");
g_message ("Cannot write \"%s\"", gimp_filename_to_utf8 (filename));
g_free (filename);
return;
}
/* Finally, free the buffer's data */
g_free (swap->data);
swap->data = NULL;
swap->filename = filename;
}
void
temp_buf_unswap (TempBuf *buf)
{
FILE *fp;
gboolean succ = FALSE;
if (!buf || !buf->swapped)
return;
/* Set the swapped flag */
buf->swapped = FALSE;
/* If the requested temp buf is still in memory, simply return */
if (cached_in_memory == buf)
{
cached_in_memory = NULL;
return;
}
/* Allocate memory for the buffer's data */
buf->data = temp_buf_allocate (buf->width * buf->height * buf->bytes);
if (g_file_test (buf->filename, G_FILE_TEST_IS_REGULAR))
{
fp = g_fopen (buf->filename, "rb");
if (fp)
{
gsize blocks_read;
blocks_read = fread (buf->data,
buf->width * buf->height * buf->bytes, 1,
fp);
fclose (fp);
if (blocks_read != 1)
perror ("Read error on temp buf");
else
succ = TRUE;
}
else
{
perror ("Error in temp buf caching");
}
/* Delete the swap file */
g_unlink (buf->filename);
}
if (!succ)
g_message ("Error in temp buf caching: "
"information swapped to disk was lost!");
g_free (buf->filename); /* free filename */
buf->filename = NULL;
}
void
temp_buf_swap_free (TempBuf *buf)
{
if (!buf->swapped)
return;
/* Set the swapped flag */
buf->swapped = FALSE;
/* If the requested temp buf is cached in memory... */
if (cached_in_memory == buf)
{
cached_in_memory = NULL;
return;
}
/* Find out if the filename of the swapped data is an existing file... */
if (g_file_test (buf->filename, G_FILE_TEST_IS_REGULAR))
{
/* Delete the swap file */
g_unlink (buf->filename);
}
else
g_message ("Error in temp buf disk swapping: "
"information swapped to disk was lost!");
if (buf->filename)
{
g_free (buf->filename);
buf->filename = NULL;
}
}
void
swapping_free (void)
{
if (cached_in_memory)
temp_buf_free (cached_in_memory);
}
......@@ -22,16 +22,12 @@
struct _TempBuf
{
gint bytes; /* the necessary info */
gint width;
gint height;
gint x, y; /* origin of data source */
gboolean swapped; /* flag indicating whether buf is cached to disk */
gchar *filename; /* filename of cached information */
guchar *data; /* The data buffer. Do never access this field
directly, use temp_buf_data() instead !! */
gint bytes; /* the necessary info */
gint width;
gint height;
gint x, y; /* origin of data source */
guchar *data; /* The data buffer. Do never access this field
directly, use temp_buf_data() instead !! */
};
......@@ -82,16 +78,4 @@ guchar * mask_buf_data (MaskBuf *mask_buf);
guchar * mask_buf_data_clear (MaskBuf *mask_buf);
/* The disk caching functions */
void temp_buf_swap (TempBuf *buf);
void temp_buf_unswap (TempBuf *buf);
void temp_buf_swap_free (TempBuf *buf);
/* Called by app_procs:exit() to free up the cached undo buffer */
void swapping_free (void);
#endif /* __TEMP_BUF_H__ */
......@@ -116,7 +116,7 @@ gimp_base_config_class_init (GimpBaseConfigClass *klass)
"stingy-memory-use",
STINGY_MEMORY_USE_BLURB,
FALSE,
GIMP_CONFIG_PARAM_RESTART);
GIMP_CONFIG_PARAM_IGNORE);
GIMP_CONFIG_INSTALL_PROP_UINT (object_class, PROP_NUM_PROCESSORS,
"num-processors", NUM_PROCESSORS_BLURB,
1, GIMP_MAX_NUM_THREADS, 2,
......
......@@ -40,7 +40,7 @@ struct _GimpBaseConfig
gchar *temp_path;
gchar *swap_path;
gboolean stingy_memory_use;
gboolean stingy_memory_use; /* unused */
guint num_processors;
guint64 tile_cache_size;
};
......
......@@ -54,7 +54,7 @@ struct _GimpCoreConfig
gchar *gradient_path;
gchar *gradient_path_writable;
gchar *font_path;
gchar *font_path_writable;
gchar *font_path_writable; /* unused */
gchar *default_brush;
gchar *default_pattern;
gchar *default_palette;
......
......@@ -27,8 +27,6 @@
#include "core-types.h"
#include "config/gimpbaseconfig.h"
#include "gimp.h"
#include "gimpcontainer.h"
#include "gimpcontext.h"
......@@ -106,13 +104,9 @@ gimp_gradients_add_gradient (Gimp *gimp,
const gchar *name,
const gchar *id)
{
GimpBaseConfig *base_config;
GimpGradient *gradient;
base_config = GIMP_BASE_CONFIG (gimp->config);
GimpGradient *gradient;
gradient = GIMP_GRADIENT (gimp_gradient_new (name,
base_config->stingy_memory_use));
gradient = GIMP_GRADIENT (gimp_gradient_new (name));
gimp_data_make_internal (GIMP_DATA (gradient));
......
......@@ -99,7 +99,6 @@ static gint32 abr_read_long (FILE *file);
GList *
gimp_brush_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
{
GimpBrush *brush;
......@@ -125,15 +124,6 @@ gimp_brush_load (const gchar *filename,
if (! brush)
return NULL;
/* Swap the brush to disk (if we're being stingy with memory) */
if (stingy_memory_use)
{
temp_buf_swap (brush->mask);
if (brush->pixmap)
temp_buf_swap (brush->pixmap);
}
return g_list_prepend (NULL, brush);
}
......@@ -387,7 +377,6 @@ gimp_brush_load_brush (gint fd,
GList *
gimp_brush_load_abr (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
{
FILE *file;
......@@ -438,10 +427,6 @@ gimp_brush_load_abr (const gchar *filename,
break;
}
/* Swap the brush to disk (if we're being stingy with memory) */
if (stingy_memory_use)
temp_buf_swap (brush->mask);
brush_list = g_list_prepend (brush_list, brush);
}
}
......
......@@ -27,14 +27,12 @@
GList * gimp_brush_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error);
GimpBrush * gimp_brush_load_brush (gint fd,
const gchar *filename,
GError **error);
GList * gimp_brush_load_abr (const gchar *filename,
gboolean stingy_memory_use,
GError **error);
......
......@@ -27,8 +27,6 @@
#include "base/brush-scale.h"
#include "base/temp-buf.h"
#include "config/gimpbaseconfig.h"
#include "gimpbrush.h"
#include "gimpbrush-load.h"
#include "gimpbrushgenerated.h"
......@@ -316,15 +314,13 @@ gimp_brush_get_extension (GimpData *data)
}
GimpData *
gimp_brush_new (const gchar *name,
gboolean stingy_memory_use)
gimp_brush_new (const gchar *name)
{
g_return_val_if_fail (name != NULL, NULL);
return gimp_brush_generated_new (name,
GIMP_BRUSH_GENERATED_CIRCLE,
5.0, 2, 0.5, 1.0, 0.0,
stingy_memory_use);
5.0, 2, 0.5, 1.0, 0.0);
}
GimpData *
......@@ -334,7 +330,7 @@ gimp_brush_get_standard (void)
if (! standard_brush)
{
standard_brush = gimp_brush_new ("Standard", FALSE);
standard_brush = gimp_brush_new ("Standard");
standard_brush->dirty = FALSE;
gimp_data_make_internal (standard_brush);
......
......@@ -64,8 +64,7 @@ struct _GimpBrushClass
GType gimp_brush_get_type (void) G_GNUC_CONST;
GimpData * gimp_brush_new (const gchar *name,
gboolean stingy_memory_use);
GimpData * gimp_brush_new (const gchar *name);
GimpData * gimp_brush_get_standard (void);
GimpBrush * gimp_brush_select_brush (GimpBrush *brush,
......
......@@ -75,8 +75,7 @@ static gboolean gimp_brush_generated_save (GimpData *data,
GError **error);
static void gimp_brush_generated_dirty (GimpData *data);
static gchar * gimp_brush_generated_get_extension (GimpData *data);
static GimpData * gimp_brush_generated_duplicate (GimpData *data,
gboolean stingy_memory_use);
static GimpData * gimp_brush_generated_duplicate (GimpData *data);
static GimpBrushClass *parent_class = NULL;
......@@ -330,8 +329,7 @@ gimp_brush_generated_get_extension (GimpData *data)
}
static GimpData *
gimp_brush_generated_duplicate (GimpData *data,
gboolean stingy_memory_use)
gimp_brush_generated_duplicate (GimpData *data)
{
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data);
......@@ -341,8 +339,7 @@ gimp_brush_generated_duplicate (GimpData *data,
brush->spikes,
brush->hardness,
brush->aspect_ratio,
brush->angle,
stingy_memory_use);
brush->angle);
}
static gdouble
......@@ -542,8 +539,7 @@ gimp_brush_generated_new (const gchar *name,
gint spikes,
gfloat hardness,
gfloat aspect_ratio,
gfloat angle,
gboolean stingy_memory_use)
gfloat angle)
{
GimpBrushGenerated *brush;
......@@ -566,15 +562,11 @@ gimp_brush_generated_new (const gchar *name,
/* render brush mask */
gimp_data_dirty (GIMP_DATA (brush));
if (stingy_memory_use)
temp_buf_swap (GIMP_BRUSH (brush)->mask);
return GIMP_DATA (brush);
}
GList *
gimp_brush_generated_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
{
GimpBrushGenerated *brush;
......@@ -734,9 +726,6 @@ gimp_brush_generated_load (const gchar *filename,
/* render brush mask */
gimp_data_dirty (GIMP_DATA (brush));
if (stingy_memory_use)
temp_buf_swap (GIMP_BRUSH (brush)->mask);
return g_list_prepend (NULL, brush);
failed:
......
......@@ -75,8 +75,7 @@ static gboolean gimp_brush_generated_save (GimpData *data,
GError **error);
static void gimp_brush_generated_dirty (GimpData *data);
static gchar * gimp_brush_generated_get_extension (GimpData *data);
static GimpData * gimp_brush_generated_duplicate (GimpData *data,
gboolean stingy_memory_use);
static GimpData * gimp_brush_generated_duplicate (GimpData *data);
static GimpBrushClass *parent_class = NULL;
......@@ -330,8 +329,7 @@ gimp_brush_generated_get_extension (GimpData *data)
}
static GimpData *
gimp_brush_generated_duplicate (GimpData *data,
gboolean stingy_memory_use)
gimp_brush_generated_duplicate (GimpData *data)
{
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data);
......@@ -341,8 +339,7 @@ gimp_brush_generated_duplicate (GimpData *data,
brush->spikes,
brush->hardness,
brush->aspect_ratio,
brush->angle,
stingy_memory_use);
brush->angle);
}
static gdouble
......@@ -542,8 +539,7 @@ gimp_brush_generated_new (const gchar *name,
gint spikes,
gfloat hardness,
gfloat aspect_ratio,
gfloat angle,
gboolean stingy_memory_use)
gfloat angle)
{
GimpBrushGenerated *brush;
......@@ -566,15 +562,11 @@ gimp_brush_generated_new (const gchar *name,
/* render brush mask */
gimp_data_dirty (GIMP_DATA (brush));
if (stingy_memory_use)
temp_buf_swap (GIMP_BRUSH (brush)->mask);
return GIMP_DATA (brush);
}
GList *
gimp_brush_generated_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
{
GimpBrushGenerated *brush;
......@@ -734,9 +726,6 @@ gimp_brush_generated_load (const gchar *filename,
/* render brush mask */
gimp_data_dirty (GIMP_DATA (brush));
if (stingy_memory_use)
temp_buf_swap (GIMP_BRUSH (brush)->mask);
return g_list_prepend (NULL, brush);
failed:
......