libgimp: remove GimpTile from the public API, and kill the tile cache

This commit is contained in:
Michael Natterer 2019-07-19 22:44:22 +02:00
parent e22fcc8942
commit 6a59ccf840
9 changed files with 3 additions and 259 deletions

View file

@ -321,7 +321,6 @@ gimpinclude_HEADERS = \
gimpproceduraldb.h \
gimpprogress.h \
gimpselection.h \
gimptile.h \
\
gimpui.h \
gimpuitypes.h \

View file

@ -683,7 +683,6 @@ EXPORTS
gimp_text_layer_set_letter_spacing
gimp_text_layer_set_line_spacing
gimp_text_layer_set_text
gimp_tile_cache_ntiles
gimp_tile_height
gimp_tile_width
gimp_uninstall_temp_proc

View file

@ -51,7 +51,6 @@
#include <libgimp/gimpproceduraldb.h>
#include <libgimp/gimpprogress.h>
#include <libgimp/gimpselection.h>
#include <libgimp/gimptile.h>
#include <libgimp/gimp_pdb_headers.h>

View file

@ -23,6 +23,7 @@
#define GIMP_DISABLE_DEPRECATION_WARNINGS
#include "gimp.h"
#include "gimptile.h"
#include "gimptilebackendplugin.h"
@ -92,8 +93,6 @@ gimp_drawable_detach (GimpDrawable *drawable)
{
g_return_if_fail (drawable != NULL);
gimp_drawable_flush (drawable);
if (drawable->tiles)
g_free (drawable->tiles);
@ -103,50 +102,6 @@ gimp_drawable_detach (GimpDrawable *drawable)
g_slice_free (GimpDrawable, drawable);
}
/**
* gimp_drawable_flush:
* @drawable: The #GimpDrawable whose tile data is to be transferred
* to the core.
*
* This function causes all tile data in the tile list of @drawable to be
* transferred to the core. It is usually called in situations where a
* plug-in acts on a drawable, and then needs to read the results of its
* actions. Data transferred back from the core will not generally be valid
* unless gimp_drawable_flush() has been called beforehand.
**/
void
gimp_drawable_flush (GimpDrawable *drawable)
{
GimpTile *tiles;
gint n_tiles;
gint i;
g_return_if_fail (drawable != NULL);
if (drawable->tiles)
{
tiles = drawable->tiles;
n_tiles = drawable->ntile_rows * drawable->ntile_cols;
for (i = 0; i < n_tiles; i++)
if ((tiles[i].ref_count > 0) && tiles[i].dirty)
_gimp_tile_flush (&tiles[i]);
}
if (drawable->shadow_tiles)
{
tiles = drawable->shadow_tiles;
n_tiles = drawable->ntile_rows * drawable->ntile_cols;
for (i = 0; i < n_tiles; i++)
if ((tiles[i].ref_count > 0) && tiles[i].dirty)
_gimp_tile_flush (&tiles[i]);
}
/* nuke all references to this drawable from the cache */
_gimp_tile_cache_flush_drawable (drawable);
}
GimpTile *
gimp_drawable_get_tile (GimpDrawable *drawable,
gboolean shadow,

View file

@ -52,8 +52,6 @@ GIMP_DEPRECATED_FOR(gimp_drawable_get_buffer)
GimpDrawable * gimp_drawable_get (gint32 drawable_ID);
GIMP_DEPRECATED
void gimp_drawable_detach (GimpDrawable *drawable);
GIMP_DEPRECATED_FOR(gegl_buffer_flush)
void gimp_drawable_flush (GimpDrawable *drawable);
GIMP_DEPRECATED_FOR(gimp_drawable_get_buffer)
GimpTile * gimp_drawable_get_tile (GimpDrawable *drawable,
gboolean shadow,

View file

@ -31,6 +31,7 @@
#include "libgimpbase/gimpwire.h"
#include "gimp.h"
#include "gimptile.h"
/**
@ -54,38 +55,10 @@ void gimp_read_expect_msg (GimpWireMessage *msg,
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);
/* private variables */
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;
/* public functions */
void
_gimp_tile_ref (GimpTile *tile)
{
g_return_if_fail (tile != NULL);
tile->ref_count++;
if (tile->ref_count == 1)
{
gimp_tile_get (tile);
tile->dirty = FALSE;
}
gimp_tile_cache_insert (tile);
}
void
_gimp_tile_ref_nocache (GimpTile *tile,
gboolean init)
@ -138,47 +111,6 @@ _gimp_tile_flush (GimpTile *tile)
}
}
/**
* 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
* is similar to gimp_tile_cache_size() but supports specifying the
* 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.
**/
void
gimp_tile_cache_ntiles (gulong ntiles)
{
max_cache_size = (ntiles *
gimp_tile_width () *
gimp_tile_height () * 4);
}
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);
}
}
/* private functions */
@ -281,129 +213,3 @@ gimp_tile_put (GimpTile *tile)
gp_unlock ();
gimp_wire_destroy (&msg);
}
/* 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
gimp_tile_cache_insert (GimpTile *tile)
{
GList *list;
if (!tile_hash_table)
{
tile_hash_table = g_hash_table_new (g_direct_hash, NULL);
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.
*/
list = g_hash_table_lookup (tile_hash_table, tile);
if (list)
{
/* The tile was already in the cache. Place it at
* the end of the tile list.
*/
/* If the tile is already at the end of the list, we are done */
if (list == tile_list_tail)
return;
/* 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);
tile_list_tail = g_list_last (g_list_concat (tile_list_tail, list));
}
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.
*/
if ((cur_cache_size + max_tile_size) > max_cache_size)
{
while (tile_list_head &&
(cur_cache_size +
max_cache_size * FREE_QUANTUM) > max_cache_size)
{
gimp_tile_cache_flush ((GimpTile *) tile_list_head->data);
}
if ((cur_cache_size + max_tile_size) > max_cache_size)
return;
}
/* Place the tile at the end of the tile list.
*/
tile_list_tail = g_list_append (tile_list_tail, tile);
if (! tile_list_head)
tile_list_head = tile_list_tail;
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.
*/
tile->ref_count++;
}
}
static void
gimp_tile_cache_flush (GimpTile *tile)
{
GList *list;
if (! tile_hash_table)
return;
/* Find where the tile is in the cache.
*/
list = g_hash_table_lookup (tile_hash_table, tile);
if (list)
{
/* If the tile is in the cache, then remove it from the
* tile list.
*/
if (list == tile_list_tail)
tile_list_tail = tile_list_tail->prev;
tile_list_head = g_list_remove_link (tile_list_head, list);
if (! tile_list_head)
tile_list_tail = NULL;
/* Remove the tile from the tile hash table.
*/
g_hash_table_remove (tile_hash_table, tile);
g_list_free (list);
/* 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);
}
}

View file

@ -44,13 +44,8 @@ struct _GimpTile
};
GIMP_DEPRECATED
void gimp_tile_cache_ntiles (gulong ntiles);
/* private function */
G_GNUC_INTERNAL void _gimp_tile_ref (GimpTile *tile);
G_GNUC_INTERNAL void _gimp_tile_unref (GimpTile *tile,
gboolean dirty);
G_GNUC_INTERNAL void _gimp_tile_ref_nocache (GimpTile *tile,
@ -58,8 +53,6 @@ G_GNUC_INTERNAL void _gimp_tile_ref_nocache (GimpTile *tile,
G_GNUC_INTERNAL void _gimp_tile_flush (GimpTile *tile);
G_GNUC_INTERNAL void _gimp_tile_cache_flush_drawable (GimpDrawable *drawable);
G_END_DECLS

View file

@ -25,6 +25,7 @@
#define GIMP_DISABLE_DEPRECATION_WARNINGS
#include "gimp.h"
#include "gimptile.h"
#include "gimptilebackendplugin.h"
@ -158,11 +159,6 @@ gimp_tile_backend_plugin_command (GeglTileSource *tile_store,
break;
case GEGL_TILE_FLUSH:
g_mutex_lock (&backend_plugin_mutex);
gimp_drawable_flush (backend_plugin->priv->drawable);
g_mutex_unlock (&backend_plugin_mutex);
break;
default:

View file

@ -31,7 +31,6 @@ G_BEGIN_DECLS
typedef struct _GimpPlugInInfo GimpPlugInInfo;
typedef struct _GimpTile GimpTile;
typedef struct _GimpDrawable GimpDrawable;
typedef struct _GimpPixelRgn GimpPixelRgn;
typedef struct _GimpParamDef GimpParamDef;
typedef struct _GimpParamRegion GimpParamRegion;
typedef union _GimpParamData GimpParamData;