Commit 889e2e26 authored by Ell's avatar Ell

app: remove gimp-scratch; replace with gegl-scratch

The scratch allocator has been moved to GEGL (commit
gegl@b99032d7).  Remove gimp-
scratch, and replace all its uses with gegl-scratch.
parent 5fffadba
......@@ -149,8 +149,7 @@ AM_LDFLAGS = \
-Wl,-u,$(SYMPREFIX)gimp_layer_mode_is_legacy \
-Wl,-u,$(SYMPREFIX)gimp_parallel_init \
-Wl,-u,$(SYMPREFIX)gimp_async_set_new \
-Wl,-u,$(SYMPREFIX)gimp_uncancelable_waitable_new \
-Wl,-u,$(SYMPREFIX)gimp_scratch_block_new
-Wl,-u,$(SYMPREFIX)gimp_uncancelable_waitable_new
gimpconsoleldadd = \
xcf/libappxcf.a \
......
......@@ -95,8 +95,7 @@ test_config_LDFLAGS = \
-Wl,-u,$(SYMPREFIX)gimp_pdb_compat_param_spec \
-Wl,-u,$(SYMPREFIX)gimp_layer_mode_is_legacy \
-Wl,-u,$(SYMPREFIX)gimp_async_set_new \
-Wl,-u,$(SYMPREFIX)gimp_uncancelable_waitable_new \
-Wl,-u,$(SYMPREFIX)gimp_scratch_block_new
-Wl,-u,$(SYMPREFIX)gimp_uncancelable_waitable_new
test_config_LDADD = \
../xcf/libappxcf.a \
......
......@@ -72,8 +72,6 @@ libappcore_a_sources = \
gimp-parallel.h \
gimp-parasites.c \
gimp-parasites.h \
gimp-scratch.c \
gimp-scratch.h \
gimp-spawn.c \
gimp-spawn.h \
gimp-tags.c \
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimp-scratch.c
* Copyright (C) 2018 Ell
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "core-types.h"
#include "gimp-scratch.h"
/* local variables */
GPrivate gimp_scratch_context =
G_PRIVATE_INIT ((GDestroyNotify) gimp_scratch_context_free);
static volatile guintptr gimp_scratch_total;
/* private functions */
GimpScratchBlock *
gimp_scratch_block_new (gsize size)
{
GimpScratchBlock *block;
gint offset;
g_atomic_pointer_add (&gimp_scratch_total, +size);
block = g_malloc ((GIMP_SCRATCH_ALIGNMENT - 1) +
sizeof (GimpScratchBlock) +
size);
offset = GIMP_SCRATCH_ALIGNMENT -
((guintptr) block) % GIMP_SCRATCH_ALIGNMENT;
offset %= GIMP_SCRATCH_ALIGNMENT;
block = (GimpScratchBlock *) ((guint8 *) block + offset);
block->size = size;
block->offset = offset;
return block;
}
void
gimp_scratch_block_free (GimpScratchBlock *block)
{
g_atomic_pointer_add (&gimp_scratch_total, -block->size);
g_free ((guint8 *) block - block->offset);
}
GimpScratchContext *
gimp_scratch_context_new (void)
{
return g_slice_new0 (GimpScratchContext);
}
void
gimp_scratch_context_free (GimpScratchContext *context)
{
gint i;
for (i = 0; i < context->n_available_blocks; i++)
gimp_scratch_block_free (context->blocks[i]);
g_free (context->blocks);
g_slice_free (GimpScratchContext, context);
}
/* public functions (stats) */
guint64
gimp_scratch_get_total (void)
{
return gimp_scratch_total;
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimp-scratch.h
* Copyright (C) 2018 Ell
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_SCRATCH_H__
#define __GIMP_SCRATCH_H__
#include <string.h>
#define GIMP_SCRATCH_ALIGNMENT 16
#define GIMP_SCRATCH_MAX_BLOCK_SIZE (1 << 20)
/* private types */
typedef struct
{
gsize size;
guint8 offset;
guint8 padding[GIMP_SCRATCH_ALIGNMENT - (sizeof (gsize) + 1)];
guint8 data[];
} GimpScratchBlock;
typedef struct
{
GimpScratchBlock **blocks;
gint n_blocks;
gint n_available_blocks;
} GimpScratchContext;
/* private variables */
extern GPrivate gimp_scratch_context;
/* private functions */
GimpScratchBlock * gimp_scratch_block_new (gsize size);
void gimp_scratch_block_free (GimpScratchBlock *block);
GimpScratchContext * gimp_scratch_context_new (void);
void gimp_scratch_context_free (GimpScratchContext *context);
/* public functions */
inline gpointer
gimp_scratch_alloc (gsize size)
{
GimpScratchContext *context;
GimpScratchBlock *block;
if (G_UNLIKELY (! size))
return NULL;
if (G_UNLIKELY (size > GIMP_SCRATCH_MAX_BLOCK_SIZE))
{
block = gimp_scratch_block_new (size);
block->size = 0;
return block->data;
}
context = g_private_get (&gimp_scratch_context);
if (G_UNLIKELY (! context))
{
context = gimp_scratch_context_new ();
g_private_set (&gimp_scratch_context, context);
}
if (G_LIKELY (context->n_available_blocks))
{
block = context->blocks[--context->n_available_blocks];
if (G_LIKELY (size <= block->size))
return block->data;
gimp_scratch_block_free (block);
}
block = gimp_scratch_block_new (size);
return block->data;
}
inline gpointer
gimp_scratch_alloc0 (gsize size)
{
gpointer ptr;
if (G_UNLIKELY (! size))
return NULL;
ptr = gimp_scratch_alloc (size);
memset (ptr, 0, size);
return ptr;
}
inline void
gimp_scratch_free (gpointer ptr)
{
GimpScratchContext *context;
GimpScratchBlock *block;
if (G_UNLIKELY (! ptr))
return;
block = (GimpScratchBlock *) ((guint8 *) ptr - GIMP_SCRATCH_ALIGNMENT);
if (G_UNLIKELY (! block->size))
{
gimp_scratch_block_free (block);
return;
}
context = g_private_get (&gimp_scratch_context);
if (G_UNLIKELY (context->n_available_blocks == context->n_blocks))
{
context->n_blocks = MAX (2 * context->n_blocks, 1);
context->blocks = g_renew (GimpScratchBlock *, context->blocks,
context->n_blocks);
}
context->blocks[context->n_available_blocks++] = block;
}
#define gimp_scratch_new(type, n) \
((type *) (gimp_scratch_alloc (sizeof (type) * (n))))
#define gimp_scratch_new0(type, n) \
((type *) (gimp_scratch_alloc0 (sizeof (type) * (n))))
/* stats */
guint64 gimp_scratch_get_total (void);
#endif /* __GIMP_SCRATCH_H__ */
......@@ -32,8 +32,6 @@
#include "../operations-types.h"
#include "core/gimp-scratch.h"
#include "gimpoperationlayermode-blend.h"
......@@ -876,7 +874,7 @@ gimp_operation_layer_mode_blend_luminance (const gfloat *in,
if (! fish)
fish = babl_fish ("RGBA float", "Y float");
scratch = gimp_scratch_new (gfloat, 2 * samples);
scratch = gegl_scratch_new (gfloat, 2 * samples);
in_Y = scratch;
layer_Y = scratch + samples;
......@@ -904,7 +902,7 @@ gimp_operation_layer_mode_blend_luminance (const gfloat *in,
layer_Y ++;
}
gimp_scratch_free (scratch);
gegl_scratch_free (scratch);
}
void
......
......@@ -91,8 +91,7 @@ AM_LDFLAGS = \
-Wl,-u,$(SYMPREFIX)gimp_layer_mode_is_legacy \
-Wl,-u,$(SYMPREFIX)gui_init \
-Wl,-u,$(SYMPREFIX)gimp_tool_cursors_get_resource \
-Wl,-u,$(SYMPREFIX)gimp_lebl_dialog \
-Wl,-u,$(SYMPREFIX)gimp_scratch_block_new
-Wl,-u,$(SYMPREFIX)gimp_lebl_dialog
# Note that we have some duplicate entries here too to work around
# circular dependencies and systems on the same architectural layer as
......
......@@ -57,7 +57,6 @@
#include "core/gimp-gui.h"
#include "core/gimp-utils.h"
#include "core/gimp-parallel.h"
#include "core/gimp-scratch.h"
#include "core/gimpasync.h"
#include "core/gimpbacktrace.h"
#include "core/gimpwaitable.h"
......@@ -695,8 +694,8 @@ static const VariableInfo variables[] =
.title = NC_("dashboard-variable", "Scratch"),
.description = N_("Total size of scratch memory"),
.type = VARIABLE_TYPE_SIZE,
.sample_func = gimp_dashboard_sample_function,
.data = gimp_scratch_get_total
.sample_func = gimp_dashboard_sample_gegl_stats,
.data = "scratch-total"
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment