buffer: add a command to the tile architecture for reiniting

This is meant to be called from a tile backend to cause GeglBuffer to drop all
cached tiles.
parent adf09aa3
......@@ -174,6 +174,7 @@ struct _GeglTile
gpointer unlock_notify_data;
};
#ifndef __GEGL_TILE_C
#define gegl_tile_get_data(tile) ((guchar*)((tile)->data))
#endif // __GEGL_TILE_C
......
......@@ -789,14 +789,12 @@ gegl_tile_backend_file_load_index (GeglTileBackendFile *self,
}
else
{
GeglTileStorage *storage =
(void*)gegl_tile_backend_peek_storage (backend);
GeglRectangle rect;
g_hash_table_remove (self->index, existing);
/* XXX: this refetch, depends on knowing the storage, the
* storage should not be public information/API to maintain
* proper encapsulation
*/
gegl_tile_source_refetch (GEGL_TILE_SOURCE (backend->priv->storage),
gegl_tile_source_refetch (GEGL_TILE_SOURCE (storage),
existing->tile.x,
existing->tile.y,
existing->tile.z);
......@@ -810,10 +808,7 @@ gegl_tile_backend_file_load_index (GeglTileBackendFile *self,
}
g_free (existing);
/* XXX: this emitting of changed depends on knowing the storage,
* which is icky..
*/
g_signal_emit_by_name (backend->priv->storage, "changed", &rect, NULL);
g_signal_emit_by_name (storage, "changed", &rect, NULL);
}
}
g_hash_table_insert (self->index, iter->data, iter->data);
......
......@@ -22,6 +22,7 @@
#include <babl/babl.h>
#include "gegl-buffer-types.h"
#include "gegl-buffer-private.h"
#include "gegl-tile-source.h"
#include "gegl-tile-backend.h"
......@@ -193,3 +194,8 @@ GeglRectangle gegl_tile_backend_get_extent (GeglTileBackend *tile_backend)
{
return tile_backend->priv->extent;
}
GeglTileSource *gegl_tile_backend_peek_storage (GeglTileBackend *backend)
{
return backend->priv->storage;
}
......@@ -54,6 +54,9 @@ struct _GeglTileBackendClass
gint gegl_tile_backend_get_tile_size (GeglTileBackend *tile_backend);
Babl *gegl_tile_backend_get_format (GeglTileBackend *tile_backend);
/* gets a pointer to the GeglTileStorage that uses the backend */
GeglTileSource *gegl_tile_backend_peek_storage (GeglTileBackend *backend);
/* specify the extent of the backend, can be used to
* pre-prime the backend with the width/height information when
* constructing proxy GeglBuffers to interact with other systems
......
......@@ -111,6 +111,48 @@ gegl_tile_handler_cache_init (GeglTileHandlerCache *cache)
gegl_tile_cache_init ();
}
static void
gegl_tile_handler_cache_reinit_buffer_tiles (gpointer itm,
gpointer userdata)
{
CacheItem *item;
item = itm;
if (item->handler == userdata)
{
GeglTileHandlerCache *cache = userdata;
cache->free_list = g_slist_prepend (cache->free_list, item);
}
}
static void
gegl_tile_handler_cache_reinit (GeglTileHandlerCache *cache)
{
CacheItem *item;
GSList *iter;
g_static_mutex_lock (&mutex);
/* only throw out items belonging to this cache instance */
cache->free_list = NULL;
g_queue_foreach (cache_queue, gegl_tile_handler_cache_reinit_buffer_tiles, cache);
for (iter = cache->free_list; iter; iter = g_slist_next (iter))
{
item = iter->data;
if (item->tile)
{
cache_total -= item->tile->size;
gegl_tile_mark_as_stored (item->tile); /* to avoid saving */
gegl_tile_unref (item->tile);
}
g_queue_remove (cache_queue, item);
g_hash_table_remove (cache_ht, item);
g_slice_free (CacheItem, item);
}
g_slist_free (cache->free_list);
cache->free_list = NULL;
g_static_mutex_unlock (&mutex);
}
static void
gegl_tile_handler_cache_dispose_buffer_tiles (gpointer itm,
gpointer userdata)
......@@ -251,6 +293,9 @@ gegl_tile_handler_cache_command (GeglTileSource *tile_store,
case GEGL_TILE_VOID:
gegl_tile_handler_cache_void (cache, x, y, z);
break;
case GEGL_TILE_REINIT:
gegl_tile_handler_cache_reinit (cache);
break;
default:
break;
}
......
......@@ -81,6 +81,7 @@ enum _GeglTileCommand
GEGL_TILE_VOID,
GEGL_TILE_FLUSH,
GEGL_TILE_REFETCH,
GEGL_TILE_REINIT,
GEGL_TILE_LAST_COMMAND
};
......@@ -149,6 +150,15 @@ gboolean gegl_tile_source_exist (GeglTileSource *source,
gint x,
gint y,
gint z);
/**
* gegl_tile_source_reinit:
* @source: a GeglTileSource *
*
* Causes all tiles in cache to be refetched.
*/
void gegl_tile_source_reinit (GeglTileSource *source);
/**
* gegl_tile_source_void:
* @source: a GeglTileSource *
......@@ -206,6 +216,8 @@ gboolean gegl_tile_source_idle (GeglTileSource *source);
gegl_tile_source_command(source,GEGL_TILE_VOID,x,y,z,NULL)
#define gegl_tile_source_refetch(source,x,y,z) \
gegl_tile_source_command(source,GEGL_TILE_REFETCH,x,y,z,NULL)
#define gegl_tile_source_reinit(source) \
gegl_tile_source_command(source,GEGL_TILE_REINIT,0,0,0,NULL)
#define gegl_tile_source_idle(source) \
(gboolean)GPOINTER_TO_INT(gegl_tile_source_command(source,GEGL_TILE_IDLE,0,0,0,NULL))
......
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