Commit bb9dd049 authored by Ell's avatar Ell

app: align drawable undo rectangle to tile grid

When creating a drawable undo from the drawable's buffer, align the
copied rectangle to the buffer's tile grid, so that all the copied
tiles are COWed, saving memory and gaining speed.

Add applied_x and applied_y fields to GimpDrawableUndo, specifying
the position at which to apply the applied_buffer, so that we apply
it in the right place, even if the undo rect has changed due to
parent ce3a6c4f
......@@ -43,9 +43,11 @@
#include "gimpdrawable-private.h"
#include "gimpdrawable-shadow.h"
#include "gimpdrawable-transform.h"
#include "gimpdrawableundo.h"
#include "gimpfilterstack.h"
#include "gimpimage.h"
#include "gimpimage-colormap.h"
#include "gimpimage-undo.h"
#include "gimpimage-undo-push.h"
#include "gimpmarshal.h"
#include "gimppickable.h"
......@@ -898,14 +900,32 @@ gimp_drawable_real_push_undo (GimpDrawable *drawable,
gint width,
gint height)
GimpImage *image;
GimpDrawableUndo *undo;
gint applied_x = x;
gint applied_y = y;
if (! buffer)
GeglBuffer *drawable_buffer = gimp_drawable_get_buffer (drawable);
GeglRectangle drawable_rect;
gimp_gegl_rectangle_align_to_tile_grid (
GEGL_RECTANGLE (x, y, width, height),
x = drawable_rect.x;
y = drawable_rect.y;
width = drawable_rect.width;
height = drawable_rect.height;
buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, width, height),
gimp_drawable_get_format (drawable));
gimp_gegl_buffer_copy (
gimp_drawable_get_buffer (drawable),
GEGL_RECTANGLE (x, y, width, height), GEGL_ABYSS_NONE,
&drawable_rect, GEGL_ABYSS_NONE,
GEGL_RECTANGLE (0, 0, 0, 0));
......@@ -914,10 +934,20 @@ gimp_drawable_real_push_undo (GimpDrawable *drawable,
g_object_ref (buffer);
gimp_image_undo_push_drawable (gimp_item_get_image (GIMP_ITEM (drawable)),
image = gimp_item_get_image (GIMP_ITEM (drawable));
gimp_image_undo_push_drawable (image,
undo_desc, drawable,
buffer, x, y);
undo = GIMP_DRAWABLE_UNDO (gimp_image_undo_get_fadeable (image));
if (undo)
undo->applied_x = applied_x;
undo->applied_y = applied_y;
g_object_unref (buffer);
......@@ -43,6 +43,8 @@ struct _GimpDrawableUndo
/* stuff for "Fade" */
GeglBuffer *applied_buffer;
gint applied_x;
gint applied_y;
GimpLayerMode paint_mode;
GimpLayerColorSpace blend_space;
GimpLayerColorSpace composite_space;
......@@ -58,9 +58,7 @@ gimp_image_fade (GimpImage *image,
gimp_image_undo (image);
gimp_drawable_apply_buffer (drawable, buffer,
gegl_buffer_get_width (undo->buffer),
gegl_buffer_get_height (undo->buffer)),
gegl_buffer_get_extent (buffer),
gimp_object_get_name (undo),
gimp_context_get_opacity (context),
......@@ -69,7 +67,7 @@ gimp_image_fade (GimpImage *image,
gimp_layer_mode_get_paint_composite_mode (
gimp_context_get_paint_mode (context)),
NULL, undo->x, undo->y);
NULL, undo->applied_x, undo->applied_y);
g_object_unref (buffer);
g_object_unref (undo);
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