[gimp] app: maintain drawable bounding box separately from its logical boundary
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: maintain drawable bounding box separately from its logical boundary
- Date: Thu, 1 Aug 2019 21:41:55 +0000 (UTC)
commit 153cb33eecc611201588a97a7b6de4f51a4cbb09
Author: Ell <ell_se yahoo com>
Date: Thu Aug 1 21:52:40 2019 +0300
app: maintain drawable bounding box separately from its logical boundary
Maintain the bounding box of drawables (i.e., the bounds of their
actual rendered content) separately from their logical boundary (as
shown in the UI).
The bounding box is calculated through the new
GimpDrawable::get_bounding_box() virtual function, which has a
corresponding gimp_drawable_get_bounding_box() function; the
default implementation simply returns the drawable's logical
boundary. The bounding box is specified in drawable coordinates,
i.e., it's not affected by the drawable's offset.
The bounding box is recalculated through
gimp_drawable_update_bounding_box(), which should be called
whenever a change may affect the bounding box (for example, when
setting a new buffer, as done implicitly by GimpDrawable's
::set_buffer() implementation, or when a drawable filter's
properties change, as will be done by GimpDrawableFilter in a
following commit). When the bounding box changes, the affected
regions of the drawable are updated, and the
GimpDrawable::bounding-box-changed signal is emitted.
When gimp_drawable_update() is called with negative width/height
values, the entire drawable's bounding box is updated, rather than
only its logical boundary.
Likewise, GimpDrawableStack and GimpLayerStack are adapted to use
the bounding box, instead of the logical bounds, when updating the
drawable's area.
app/core/gimpdrawable-private.h | 1 +
app/core/gimpdrawable.c | 118 ++++++++++++++++++++++++++++++++++++++--
app/core/gimpdrawable.h | 6 ++
app/core/gimpdrawablestack.c | 13 +++--
app/core/gimplayerstack.c | 13 +++--
5 files changed, 135 insertions(+), 16 deletions(-)
---
diff --git a/app/core/gimpdrawable-private.h b/app/core/gimpdrawable-private.h
index c32e23a9c8..07b6899e56 100644
--- a/app/core/gimpdrawable-private.h
+++ b/app/core/gimpdrawable-private.h
@@ -28,6 +28,7 @@ struct _GimpDrawablePrivate
GeglNode *source_node;
GeglNode *buffer_source_node;
GimpContainer *filter_stack;
+ GeglRectangle bounding_box;
GimpLayer *floating_selection;
GimpFilter *fs_filter;
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index 834e8b2a18..b29a8a94c7 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -65,6 +65,7 @@ enum
UPDATE,
FORMAT_CHANGED,
ALPHA_CHANGED,
+ BOUNDING_BOX_CHANGED,
LAST_SIGNAL
};
@@ -188,6 +189,9 @@ static void gimp_drawable_real_set_buffer (GimpDrawable *drawable,
GeglBuffer *buffer,
const GeglRectangle *bounds);
+static GeglRectangle gimp_drawable_real_get_bounding_box
+ (GimpDrawable *drawable);
+
static void gimp_drawable_real_push_undo (GimpDrawable *drawable,
const gchar *undo_desc,
GeglBuffer *buffer,
@@ -257,6 +261,15 @@ gimp_drawable_class_init (GimpDrawableClass *klass)
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+ gimp_drawable_signals[BOUNDING_BOX_CHANGED] =
+ g_signal_new ("bounding-box-changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GimpDrawableClass, bounding_box_changed),
+ NULL, NULL,
+ gimp_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
object_class->dispose = gimp_drawable_dispose;
object_class->finalize = gimp_drawable_finalize;
object_class->set_property = gimp_drawable_set_property;
@@ -283,6 +296,7 @@ gimp_drawable_class_init (GimpDrawableClass *klass)
klass->update = gimp_drawable_real_update;
klass->format_changed = NULL;
klass->alpha_changed = NULL;
+ klass->bounding_box_changed = NULL;
klass->estimate_memsize = gimp_drawable_real_estimate_memsize;
klass->update_all = gimp_drawable_real_update_all;
klass->invalidate_boundary = NULL;
@@ -292,6 +306,7 @@ gimp_drawable_class_init (GimpDrawableClass *klass)
klass->apply_buffer = gimp_drawable_real_apply_buffer;
klass->get_buffer = gimp_drawable_real_get_buffer;
klass->set_buffer = gimp_drawable_real_set_buffer;
+ klass->get_bounding_box = gimp_drawable_real_get_bounding_box;
klass->push_undo = gimp_drawable_real_push_undo;
klass->swap_pixels = gimp_drawable_real_swap_pixels;
klass->get_source_node = gimp_drawable_real_get_source_node;
@@ -900,6 +915,8 @@ gimp_drawable_real_set_buffer (GimpDrawable *drawable,
bounds->height ? bounds->height :
gegl_buffer_get_height (buffer));
+ gimp_drawable_update_bounding_box (drawable);
+
if (gimp_drawable_get_format (drawable) != old_format)
gimp_drawable_format_changed (drawable);
@@ -911,6 +928,20 @@ gimp_drawable_real_set_buffer (GimpDrawable *drawable,
g_object_thaw_notify (G_OBJECT (drawable));
}
+static GeglRectangle
+gimp_drawable_real_get_bounding_box (GimpDrawable *drawable)
+{
+ GimpItem *item = GIMP_ITEM (drawable);
+ GeglRectangle bounding_box;
+
+ bounding_box.x = 0;
+ bounding_box.y = 0;
+ bounding_box.width = gimp_item_get_width (item);
+ bounding_box.height = gimp_item_get_height (item);
+
+ return bounding_box;
+}
+
static void
gimp_drawable_real_push_undo (GimpDrawable *drawable,
const gchar *undo_desc,
@@ -1069,11 +1100,25 @@ gimp_drawable_update (GimpDrawable *drawable,
{
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
- if (width == -1)
- width = gimp_item_get_width (GIMP_ITEM (drawable));
+ if (width < 0)
+ {
+ GeglRectangle bounding_box;
+
+ bounding_box = gimp_drawable_get_bounding_box (drawable);
+
+ x = bounding_box.x;
+ width = bounding_box.width;
+ }
+
+ if (height < 0)
+ {
+ GeglRectangle bounding_box;
- if (height == -1)
- height = gimp_item_get_height (GIMP_ITEM (drawable));
+ bounding_box = gimp_drawable_get_bounding_box (drawable);
+
+ y = bounding_box.y;
+ height = bounding_box.height;
+ }
if (drawable->private->paint_count == 0)
{
@@ -1513,6 +1558,71 @@ gimp_drawable_get_mode_node (GimpDrawable *drawable)
return drawable->private->mode_node;
}
+GeglRectangle
+gimp_drawable_get_bounding_box (GimpDrawable *drawable)
+{
+ g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable),
+ *GEGL_RECTANGLE (0, 0, 0, 0));
+
+ if (gegl_rectangle_is_empty (&drawable->private->bounding_box))
+ gimp_drawable_update_bounding_box (drawable);
+
+ return drawable->private->bounding_box;
+}
+
+gboolean
+gimp_drawable_update_bounding_box (GimpDrawable *drawable)
+{
+ GeglRectangle bounding_box;
+
+ g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
+
+ bounding_box =
+ GIMP_DRAWABLE_GET_CLASS (drawable)->get_bounding_box (drawable);
+
+ if (! gegl_rectangle_equal (&bounding_box, &drawable->private->bounding_box))
+ {
+ GeglRectangle old_bounding_box = drawable->private->bounding_box;
+ GeglRectangle diff_rects[4];
+ gint n_diff_rects;
+ gint i;
+
+ n_diff_rects = gegl_rectangle_subtract (diff_rects,
+ &old_bounding_box,
+ &bounding_box);
+
+ for (i = 0; i < n_diff_rects; i++)
+ {
+ gimp_drawable_update (drawable,
+ diff_rects[i].x,
+ diff_rects[i].y,
+ diff_rects[i].width,
+ diff_rects[i].height);
+ }
+
+ drawable->private->bounding_box = bounding_box;
+
+ g_signal_emit (drawable, gimp_drawable_signals[BOUNDING_BOX_CHANGED], 0);
+
+ n_diff_rects = gegl_rectangle_subtract (diff_rects,
+ &bounding_box,
+ &old_bounding_box);
+
+ for (i = 0; i < n_diff_rects; i++)
+ {
+ gimp_drawable_update (drawable,
+ diff_rects[i].x,
+ diff_rects[i].y,
+ diff_rects[i].width,
+ diff_rects[i].height);
+ }
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
void
gimp_drawable_swap_pixels (GimpDrawable *drawable,
GeglBuffer *buffer,
diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h
index 4921a870f1..b18f8dfc0f 100644
--- a/app/core/gimpdrawable.h
+++ b/app/core/gimpdrawable.h
@@ -52,6 +52,7 @@ struct _GimpDrawableClass
gint height);
void (* format_changed) (GimpDrawable *drawable);
void (* alpha_changed) (GimpDrawable *drawable);
+ void (* bounding_box_changed) (GimpDrawable *drawable);
/* virtual functions */
gint64 (* estimate_memsize) (GimpDrawable *drawable,
@@ -91,6 +92,7 @@ struct _GimpDrawableClass
const gchar *undo_desc,
GeglBuffer *buffer,
const GeglRectangle *bounds);
+ GeglRectangle (* get_bounding_box) (GimpDrawable *drawable);
void (* push_undo) (GimpDrawable *drawable,
const gchar *undo_desc,
GeglBuffer *buffer,
@@ -183,6 +185,10 @@ void gimp_drawable_set_format (GimpDrawable *drawable,
GeglNode * gimp_drawable_get_source_node (GimpDrawable *drawable);
GeglNode * gimp_drawable_get_mode_node (GimpDrawable *drawable);
+GeglRectangle gimp_drawable_get_bounding_box (GimpDrawable *drawable);
+gboolean gimp_drawable_update_bounding_box
+ (GimpDrawable *drawable);
+
void gimp_drawable_swap_pixels (GimpDrawable *drawable,
GeglBuffer *buffer,
gint x,
diff --git a/app/core/gimpdrawablestack.c b/app/core/gimpdrawablestack.c
index db86512956..c8e706a594 100644
--- a/app/core/gimpdrawablestack.c
+++ b/app/core/gimpdrawablestack.c
@@ -211,13 +211,14 @@ static void
gimp_drawable_stack_drawable_active (GimpItem *item,
GimpDrawableStack *stack)
{
- gint offset_x;
- gint offset_y;
+ GeglRectangle bounding_box;
- gimp_item_get_offset (item, &offset_x, &offset_y);
+ bounding_box = gimp_drawable_get_bounding_box (GIMP_DRAWABLE (item));
+
+ bounding_box.x += gimp_item_get_offset_x (item);
+ bounding_box.y += gimp_item_get_offset_y (item);
gimp_drawable_stack_update (stack,
- offset_x, offset_y,
- gimp_item_get_width (item),
- gimp_item_get_height (item));
+ bounding_box.x, bounding_box.y,
+ bounding_box.width, bounding_box.height);
}
diff --git a/app/core/gimplayerstack.c b/app/core/gimplayerstack.c
index 3762e6787e..1540189252 100644
--- a/app/core/gimplayerstack.c
+++ b/app/core/gimplayerstack.c
@@ -228,15 +228,16 @@ gimp_layer_stack_update_range (GimpLayerStack *stack,
if (gimp_filter_get_active (GIMP_FILTER (item)))
{
- gint offset_x;
- gint offset_y;
+ GeglRectangle bounding_box;
- gimp_item_get_offset (item, &offset_x, &offset_y);
+ bounding_box = gimp_drawable_get_bounding_box (GIMP_DRAWABLE (item));
+
+ bounding_box.x += gimp_item_get_offset_x (item);
+ bounding_box.y += gimp_item_get_offset_y (item);
gimp_drawable_stack_update (GIMP_DRAWABLE_STACK (stack),
- offset_x, offset_y,
- gimp_item_get_width (item),
- gimp_item_get_height (item));
+ bounding_box.x, bounding_box.y,
+ bounding_box.width, bounding_box.height);
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]