Commit 5642616f authored by Daniel Sabo's avatar Daniel Sabo
Browse files

Add flush-on-destroy property to TileBackend

Use a boolean to control whether or not data gets flushed when a
buffer is destroyed instead of sniffing the object type.
parent ebadaddc
......@@ -36,6 +36,8 @@ struct _GeglTileBackendPrivate
gint px_size; /* size of a single pixel in bytes */
gint tile_size; /* size of an entire tile in bytes */
gboolean flush_on_destroy;
GeglRectangle extent;
gpointer header;
......
......@@ -413,11 +413,7 @@ gegl_buffer_dispose (GObject *object)
{
GeglTileBackend *backend = gegl_buffer_backend (buffer);
/* only flush non-internal backends,. */
if (!(GEGL_IS_TILE_BACKEND_FILE (backend) ||
GEGL_IS_TILE_BACKEND_RAM (backend) ||
GEGL_IS_TILE_BACKEND_TILE_DIR (backend) ||
GEGL_IS_TILE_BACKEND_SWAP (backend)))
if (gegl_tile_backend_get_flush_on_destroy (backend))
gegl_buffer_flush (buffer);
gegl_tile_source_reinit (GEGL_TILE_SOURCE (handler->source));
......
......@@ -1212,6 +1212,8 @@ gegl_tile_backend_file_constructor (GType type,
backend->priv->header = &self->header;
gegl_tile_backend_set_flush_on_destroy (backend, FALSE);
return object;
}
......
......@@ -345,6 +345,8 @@ gegl_tile_backend_ram_constructor (GType type,
NULL,
ram_entry_free_func);
gegl_tile_backend_set_flush_on_destroy (GEGL_TILE_BACKEND (object), FALSE);
return object;
}
......
......@@ -796,6 +796,8 @@ gegl_tile_backend_swap_constructor (GType type,
backend->priv->shared = FALSE;
gegl_tile_backend_set_flush_on_destroy (backend, FALSE);
GEGL_NOTE (GEGL_DEBUG_TILE_BACKEND, "constructing swap backend");
return object;
......
......@@ -356,6 +356,9 @@ gegl_tile_backend_tiledir_constructor (GType type,
gio->buffer_dir = g_file_new_for_commandline_arg (gio->path);
g_file_make_directory (gio->buffer_dir, NULL, NULL);
((GeglTileSource*)(object))->command = gegl_tile_backend_tiledir_command;
gegl_tile_backend_set_flush_on_destroy (GEGL_TILE_BACKEND (object), FALSE);
return object;
}
......
......@@ -39,7 +39,8 @@ enum
PROP_TILE_HEIGHT,
PROP_PX_SIZE,
PROP_TILE_SIZE,
PROP_FORMAT
PROP_FORMAT,
PROP_FLUSH_ON_DESTROY
};
static void
......@@ -72,6 +73,10 @@ get_property (GObject *gobject,
g_value_set_pointer (value, (void*)backend->priv->format);
break;
case PROP_FLUSH_ON_DESTROY:
g_value_set_boolean (value, backend->priv->flush_on_destroy);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
break;
......@@ -100,6 +105,10 @@ set_property (GObject *gobject,
backend->priv->format = g_value_get_pointer (value);
break;
case PROP_FLUSH_ON_DESTROY:
backend->priv->flush_on_destroy = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
break;
......@@ -162,6 +171,12 @@ gegl_tile_backend_class_init (GeglTileBackendClass *klass)
"babl format",
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (gobject_class, PROP_FLUSH_ON_DESTROY,
g_param_spec_boolean ("flush-on-destroy", "flush-on-destroy",
"Cache tiles will be flushed before the backend is destroyed",
TRUE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_type_class_add_private (gobject_class, sizeof (GeglTileBackendPrivate));
}
......@@ -220,6 +235,19 @@ gegl_tile_backend_peek_storage (GeglTileBackend *backend)
return backend->priv->storage;
}
void
gegl_tile_backend_set_flush_on_destroy (GeglTileBackend *tile_backend,
gboolean flush_on_destroy)
{
tile_backend->priv->flush_on_destroy = flush_on_destroy;
}
gboolean
gegl_tile_backend_get_flush_on_destroy (GeglTileBackend *tile_backend)
{
return tile_backend->priv->flush_on_destroy;
}
void
gegl_tile_backend_unlink_swap (gchar *path)
{
......
......@@ -108,6 +108,19 @@ void gegl_tile_backend_set_extent (GeglTileBackend *tile_backend,
GeglRectangle gegl_tile_backend_get_extent (GeglTileBackend *tile_backend);
/**
* gegl_tile_backend_set_flush_on_destroy:
* @tile_backend: a #GeglTileBackend
* @flush_on_destroy: true if the backend needs to be flushed
*
* Control whether cached data will be written to the backend before it
* is destroyed. If false unwritten data will be discarded.
*/
void gegl_tile_backend_set_flush_on_destroy (GeglTileBackend *tile_backend,
gboolean flush_on_destroy);
gboolean gegl_tile_backend_get_flush_on_destroy (GeglTileBackend *tile_backend);
GType gegl_tile_backend_get_type (void) G_GNUC_CONST;
/**
......
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