[gimp/goat-invasion: 50/401] app: added GimpPickable::get_buffer()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/goat-invasion: 50/401] app: added GimpPickable::get_buffer()
- Date: Mon, 2 Apr 2012 11:52:20 +0000 (UTC)
commit c7451b4357b669a180aff6697ae35397e23519a0
Author: Michael Natterer <mitch gimp org>
Date: Thu Mar 15 14:38:54 2012 +0100
app: added GimpPickable::get_buffer()
Add cached buffers to GimpProjection and GimpImageMap, and use
the new API where possible.
app/actions/layers-commands.c | 10 ++++----
app/core/gimpdrawable.c | 1 +
app/core/gimpimagemap.c | 49 +++++++++++++++++++++++++++++++++++++++-
app/core/gimppickable.c | 15 ++++++++++++
app/core/gimppickable.h | 2 +
app/core/gimpprojection.c | 35 ++++++++++++++++++++++++++++-
app/core/gimpprojection.h | 2 +
app/pdb/layer-cmds.c | 10 ++++----
tools/pdbgen/pdb/layer.pdb | 10 ++++----
9 files changed, 116 insertions(+), 18 deletions(-)
---
diff --git a/app/actions/layers-commands.c b/app/actions/layers-commands.c
index 0e72a69..0a19989 100644
--- a/app/actions/layers-commands.c
+++ b/app/actions/layers-commands.c
@@ -350,11 +350,11 @@ layers_new_from_visible_cmd_callback (GtkAction *action,
gimp_pickable_flush (pickable);
- layer = gimp_layer_new_from_tiles (gimp_pickable_get_tiles (pickable),
- image,
- gimp_image_base_type_with_alpha (image),
- _("Visible"),
- GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
+ layer = gimp_layer_new_from_buffer (gimp_pickable_get_buffer (pickable),
+ image,
+ gimp_image_base_type_with_alpha (image),
+ _("Visible"),
+ GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
gimp_image_add_layer (image, layer,
GIMP_IMAGE_ACTIVE_PARENT, -1, TRUE);
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index 5c03540..c154d56 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -273,6 +273,7 @@ gimp_drawable_pickable_iface_init (GimpPickableInterface *iface)
iface->get_image = (GimpImage * (*) (GimpPickable *pickable)) gimp_item_get_image;
iface->get_image_type = (GimpImageType (*) (GimpPickable *pickable)) gimp_drawable_type;
iface->get_bytes = (gint (*) (GimpPickable *pickable)) gimp_drawable_bytes;
+ iface->get_buffer = (GeglBuffer * (*) (GimpPickable *pickable)) gimp_drawable_get_read_buffer;
iface->get_tiles = (TileManager * (*) (GimpPickable *pickable)) gimp_drawable_get_tiles;
iface->get_pixel_at = gimp_drawable_get_pixel_at;
}
diff --git a/app/core/gimpimagemap.c b/app/core/gimpimagemap.c
index 1566358..528f58a 100644
--- a/app/core/gimpimagemap.c
+++ b/app/core/gimpimagemap.c
@@ -71,6 +71,7 @@ struct _GimpImageMap
gchar *undo_desc;
TileManager *undo_tiles;
+ GeglBuffer *undo_buffer;
gint undo_offset_x;
gint undo_offset_y;
@@ -102,6 +103,7 @@ static void gimp_image_map_finalize (GObject *objec
static GimpImage * gimp_image_map_get_image (GimpPickable *pickable);
static GimpImageType gimp_image_map_get_image_type (GimpPickable *pickable);
static gint gimp_image_map_get_bytes (GimpPickable *pickable);
+static GeglBuffer * gimp_image_map_get_buffer (GimpPickable *pickable);
static TileManager * gimp_image_map_get_tiles (GimpPickable *pickable);
static gboolean gimp_image_map_get_pixel_at (GimpPickable *pickable,
gint x,
@@ -154,6 +156,7 @@ gimp_image_map_pickable_iface_init (GimpPickableInterface *iface)
iface->get_image = gimp_image_map_get_image;
iface->get_image_type = gimp_image_map_get_image_type;
iface->get_bytes = gimp_image_map_get_bytes;
+ iface->get_buffer = gimp_image_map_get_buffer;
iface->get_tiles = gimp_image_map_get_tiles;
iface->get_pixel_at = gimp_image_map_get_pixel_at;
}
@@ -211,6 +214,12 @@ gimp_image_map_finalize (GObject *object)
image_map->undo_tiles = NULL;
}
+ if (image_map->undo_buffer)
+ {
+ g_object_unref (image_map->undo_buffer);
+ image_map->undo_buffer = NULL;
+ }
+
gimp_image_map_cancel_any_idle_jobs (image_map);
if (image_map->gegl)
@@ -269,6 +278,24 @@ gimp_image_map_get_bytes (GimpPickable *pickable)
return gimp_pickable_get_bytes (GIMP_PICKABLE (image_map->drawable));
}
+static GeglBuffer *
+gimp_image_map_get_buffer (GimpPickable *pickable)
+{
+ GimpImageMap *image_map = GIMP_IMAGE_MAP (pickable);
+
+ if (image_map->undo_tiles)
+ {
+ if (! image_map->undo_buffer)
+ image_map->undo_buffer =
+ gimp_tile_manager_create_buffer (image_map->undo_tiles,
+ FALSE);
+
+ return image_map->undo_buffer;
+ }
+ else
+ return gimp_pickable_get_buffer (GIMP_PICKABLE (image_map->drawable));
+}
+
static TileManager *
gimp_image_map_get_tiles (GimpPickable *pickable)
{
@@ -542,6 +569,12 @@ gimp_image_map_commit (GimpImageMap *image_map)
tile_manager_unref (image_map->undo_tiles);
image_map->undo_tiles = NULL;
+
+ if (image_map->undo_buffer)
+ {
+ g_object_unref (image_map->undo_buffer);
+ image_map->undo_buffer = NULL;
+ }
}
}
@@ -589,6 +622,12 @@ gimp_image_map_clear (GimpImageMap *image_map)
/* Free the undo_tiles tile manager */
tile_manager_unref (image_map->undo_tiles);
image_map->undo_tiles = NULL;
+
+ if (image_map->undo_buffer)
+ {
+ g_object_unref (image_map->undo_buffer);
+ image_map->undo_buffer = NULL;
+ }
}
}
@@ -632,7 +671,7 @@ gimp_image_map_update_undo_tiles (GimpImageMap *image_map,
undo_height = 0;
}
- if (! image_map->undo_tiles ||
+ if (! image_map->undo_tiles ||
undo_offset_x != rect->x ||
undo_offset_y != rect->y ||
undo_width != rect->width ||
@@ -645,7 +684,7 @@ gimp_image_map_update_undo_tiles (GimpImageMap *image_map,
/* If either the extents changed or the tiles don't exist,
* allocate new
*/
- if (! image_map->undo_tiles ||
+ if (! image_map->undo_tiles ||
undo_width != rect->width ||
undo_height != rect->height)
{
@@ -671,6 +710,12 @@ gimp_image_map_update_undo_tiles (GimpImageMap *image_map,
image_map->undo_offset_x = rect->x;
image_map->undo_offset_y = rect->y;
}
+
+ if (image_map->undo_buffer)
+ {
+ g_object_unref (image_map->undo_buffer);
+ image_map->undo_buffer = NULL;
+ }
}
static gboolean
diff --git a/app/core/gimppickable.c b/app/core/gimppickable.c
index 9f4e320..052e816 100644
--- a/app/core/gimppickable.c
+++ b/app/core/gimppickable.c
@@ -121,6 +121,21 @@ gimp_pickable_get_bytes (GimpPickable *pickable)
return 0;
}
+GeglBuffer *
+gimp_pickable_get_buffer (GimpPickable *pickable)
+{
+ GimpPickableInterface *pickable_iface;
+
+ g_return_val_if_fail (GIMP_IS_PICKABLE (pickable), NULL);
+
+ pickable_iface = GIMP_PICKABLE_GET_INTERFACE (pickable);
+
+ if (pickable_iface->get_buffer)
+ return pickable_iface->get_buffer (pickable);
+
+ return NULL;
+}
+
TileManager *
gimp_pickable_get_tiles (GimpPickable *pickable)
{
diff --git a/app/core/gimppickable.h b/app/core/gimppickable.h
index 29014ef..96f4e2e 100644
--- a/app/core/gimppickable.h
+++ b/app/core/gimppickable.h
@@ -39,6 +39,7 @@ struct _GimpPickableInterface
GimpImage * (* get_image) (GimpPickable *pickable);
GimpImageType (* get_image_type) (GimpPickable *pickable);
gint (* get_bytes) (GimpPickable *pickable);
+ GeglBuffer * (* get_buffer) (GimpPickable *pickable);
TileManager * (* get_tiles) (GimpPickable *pickable);
gboolean (* get_pixel_at) (GimpPickable *pickable,
gint x,
@@ -56,6 +57,7 @@ void gimp_pickable_flush (GimpPickable *pickable);
GimpImage * gimp_pickable_get_image (GimpPickable *pickable);
GimpImageType gimp_pickable_get_image_type (GimpPickable *pickable);
gint gimp_pickable_get_bytes (GimpPickable *pickable);
+GeglBuffer * gimp_pickable_get_buffer (GimpPickable *pickable);
TileManager * gimp_pickable_get_tiles (GimpPickable *pickable);
gboolean gimp_pickable_get_pixel_at (GimpPickable *pickable,
gint x,
diff --git a/app/core/gimpprojection.c b/app/core/gimpprojection.c
index 39f2566..57cf01a 100644
--- a/app/core/gimpprojection.c
+++ b/app/core/gimpprojection.c
@@ -64,6 +64,7 @@ static void gimp_projection_pickable_flush (GimpPickable *picka
static GimpImage * gimp_projection_get_image (GimpPickable *pickable);
static GimpImageType gimp_projection_get_image_type (GimpPickable *pickable);
static gint gimp_projection_get_bytes (GimpPickable *pickable);
+static GeglBuffer * gimp_projection_get_buffer (GimpPickable *pickable);
static TileManager * gimp_projection_get_tiles (GimpPickable *pickable);
static gboolean gimp_projection_get_pixel_at (GimpPickable *pickable,
gint x,
@@ -150,6 +151,7 @@ gimp_projection_init (GimpProjection *proj)
{
proj->projectable = NULL;
proj->pyramid = NULL;
+ proj->buffer = NULL;
proj->update_areas = NULL;
proj->idle_render.idle_id = 0;
proj->idle_render.update_areas = NULL;
@@ -163,6 +165,7 @@ gimp_projection_pickable_iface_init (GimpPickableInterface *iface)
iface->get_image = gimp_projection_get_image;
iface->get_image_type = gimp_projection_get_image_type;
iface->get_bytes = gimp_projection_get_bytes;
+ iface->get_buffer = gimp_projection_get_buffer;
iface->get_tiles = gimp_projection_get_tiles;
iface->get_pixel_at = gimp_projection_get_pixel_at;
iface->get_opacity_at = gimp_projection_get_opacity_at;
@@ -191,6 +194,12 @@ gimp_projection_finalize (GObject *object)
proj->pyramid = NULL;
}
+ if (proj->buffer)
+ {
+ g_object_unref (proj->buffer);
+ proj->buffer = NULL;
+ }
+
if (proj->graph)
{
g_object_unref (proj->graph);
@@ -312,6 +321,21 @@ gimp_projection_get_bytes (GimpPickable *pickable)
return GIMP_IMAGE_TYPE_BYTES (gimp_projection_get_image_type (pickable));
}
+static GeglBuffer *
+gimp_projection_get_buffer (GimpPickable *pickable)
+{
+ GimpProjection *proj = GIMP_PROJECTION (pickable);
+
+ if (! proj->buffer)
+ {
+ TileManager *tiles = gimp_projection_get_tiles (pickable);
+
+ proj->buffer = gimp_tile_manager_create_buffer (tiles, FALSE);
+ }
+
+ return proj->buffer;
+}
+
static TileManager *
gimp_projection_get_tiles (GimpPickable *pickable)
{
@@ -780,7 +804,10 @@ gimp_projection_invalidate (GimpProjection *proj,
if (proj->sink_node)
{
GeglBuffer *buffer;
- gegl_node_get (proj->sink_node, "buffer", &buffer, NULL);
+
+ gegl_node_get (proj->sink_node,
+ "buffer", &buffer,
+ NULL);
/* makes the buffer drop all GimpTiles */
gegl_tile_source_reinit ((void*)buffer);
@@ -898,6 +925,12 @@ gimp_projection_projectable_changed (GimpProjectable *projectable,
proj->pyramid = NULL;
}
+ if (proj->buffer)
+ {
+ g_object_unref (proj->buffer);
+ proj->buffer = NULL;
+ }
+
gimp_projectable_get_offset (proj->projectable, &off_x, &off_y);
gimp_projectable_get_size (projectable, &width, &height);
diff --git a/app/core/gimpprojection.h b/app/core/gimpprojection.h
index ca697b5..c367cd9 100644
--- a/app/core/gimpprojection.h
+++ b/app/core/gimpprojection.h
@@ -55,6 +55,8 @@ struct _GimpProjection
GimpProjectable *projectable;
TilePyramid *pyramid;
+ GeglBuffer *buffer;
+
GeglNode *graph;
GeglNode *sink_node;
GeglProcessor *processor;
diff --git a/app/pdb/layer-cmds.c b/app/pdb/layer-cmds.c
index 4cc2556..fe8511a 100644
--- a/app/pdb/layer-cmds.c
+++ b/app/pdb/layer-cmds.c
@@ -116,11 +116,11 @@ layer_new_from_visible_invoker (GimpProcedure *procedure,
gimp_pickable_flush (pickable);
- layer = gimp_layer_new_from_tiles (gimp_pickable_get_tiles (pickable),
- dest_image,
- gimp_image_base_type_with_alpha (dest_image),
- name,
- GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
+ layer = gimp_layer_new_from_buffer (gimp_pickable_get_buffer (pickable),
+ dest_image,
+ gimp_image_base_type_with_alpha (dest_image),
+ name,
+ GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
}
return_vals = gimp_procedure_get_return_values (procedure, success,
diff --git a/tools/pdbgen/pdb/layer.pdb b/tools/pdbgen/pdb/layer.pdb
index a463017..b655b13 100644
--- a/tools/pdbgen/pdb/layer.pdb
+++ b/tools/pdbgen/pdb/layer.pdb
@@ -99,11 +99,11 @@ HELP
gimp_pickable_flush (pickable);
- layer = gimp_layer_new_from_tiles (gimp_pickable_get_tiles (pickable),
- dest_image,
- gimp_image_base_type_with_alpha (dest_image),
- name,
- GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
+ layer = gimp_layer_new_from_buffer (gimp_pickable_get_buffer (pickable),
+ dest_image,
+ gimp_image_base_type_with_alpha (dest_image),
+ name,
+ GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
}
CODE
);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]