[gimp/gimp-2-10] app: in GimpDrawable::set_buffer(), take bounds rect instead of offset only



commit c217876a47e484f22d6e2c24bde592a73fc9f17c
Author: Ell <ell_se yahoo com>
Date:   Thu Aug 1 21:41:47 2019 +0300

    app: in GimpDrawable::set_buffer(), take bounds rect instead of offset only
    
    In GimpDrawable::set_buffer(), and the corresponding
    gimp_drawable_set_buffer_full() function, take a bounds rectangle,
    which specifies both the drawable's new offset and its new size,
    instead of only taking the new offset.  In
    gimp_drawable_real_set_buffer(), set the item size according to the
    rect dimensions, instead of the buffer dimensions.  The rect's
    width/height may be 0, in which case the buffer's dimensions are
    used.
    
    Adapt the rest of the code.
    
    We do this in preparation for maintaining the drawable's bounding
    box separately from its logical bounds, allowing the drawable
    content to extend beyond its bounds.
    
    (cherry picked from commit 3afdd7c5c2bbaebe088cd021be1b1d1b89f996c4)

 app/core/gimpchannel.c            | 26 ++++++------
 app/core/gimpdrawable-transform.c |  2 +-
 app/core/gimpdrawable.c           | 87 +++++++++++++++++++++++----------------
 app/core/gimpdrawable.h           |  6 +--
 app/core/gimpdrawablemodundo.c    |  4 +-
 app/core/gimpgrouplayer.c         |  9 ++--
 app/core/gimpgrouplayerundo.c     |  3 +-
 app/core/gimplayer.c              | 17 ++++----
 app/text/gimptextlayer.c          | 17 ++++----
 9 files changed, 89 insertions(+), 82 deletions(-)
---
diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c
index 373efb10fb..141602731d 100644
--- a/app/core/gimpchannel.c
+++ b/app/core/gimpchannel.c
@@ -163,8 +163,7 @@ static void      gimp_channel_set_buffer     (GimpDrawable        *drawable,
                                               gboolean             push_undo,
                                               const gchar         *undo_desc,
                                               GeglBuffer          *buffer,
-                                              gint                 offset_x,
-                                              gint                 offset_y);
+                                              const GeglRectangle *bounds);
 
 static gdouble   gimp_channel_get_opacity_at (GimpPickable        *pickable,
                                               gint                 x,
@@ -601,8 +600,10 @@ gimp_channel_convert (GimpItem  *item,
 
       gimp_drawable_set_buffer_full (drawable, FALSE, NULL,
                                      new_buffer,
-                                     gimp_item_get_offset_x (item),
-                                     gimp_item_get_offset_y (item),
+                                     GEGL_RECTANGLE (
+                                       gimp_item_get_offset_x (item),
+                                       gimp_item_get_offset_y (item),
+                                       0, 0),
                                      TRUE);
       g_object_unref (new_buffer);
     }
@@ -733,7 +734,8 @@ gimp_channel_scale (GimpItem              *item,
       gimp_drawable_set_buffer_full (drawable,
                                      gimp_item_is_attached (item), NULL,
                                      new_buffer,
-                                     new_offset_x, new_offset_y,
+                                     GEGL_RECTANGLE (new_offset_x, new_offset_y,
+                                                     0,            0),
                                      TRUE);
       g_object_unref (new_buffer);
 
@@ -998,12 +1000,11 @@ gimp_channel_get_active_components (GimpDrawable *drawable,
 }
 
 static void
-gimp_channel_set_buffer (GimpDrawable *drawable,
-                         gboolean      push_undo,
-                         const gchar  *undo_desc,
-                         GeglBuffer   *buffer,
-                         gint          offset_x,
-                         gint          offset_y)
+gimp_channel_set_buffer (GimpDrawable        *drawable,
+                         gboolean             push_undo,
+                         const gchar         *undo_desc,
+                         GeglBuffer          *buffer,
+                         const GeglRectangle *bounds)
 {
   GimpChannel *channel    = GIMP_CHANNEL (drawable);
   GeglBuffer  *old_buffer = gimp_drawable_get_buffer (drawable);
@@ -1017,8 +1018,7 @@ gimp_channel_set_buffer (GimpDrawable *drawable,
 
   GIMP_DRAWABLE_CLASS (parent_class)->set_buffer (drawable,
                                                   push_undo, undo_desc,
-                                                  buffer,
-                                                  offset_x, offset_y);
+                                                  buffer, bounds);
 
   gegl_buffer_signal_connect (buffer, "changed",
                               G_CALLBACK (gimp_channel_buffer_changed),
diff --git a/app/core/gimpdrawable-transform.c b/app/core/gimpdrawable-transform.c
index cc1690559c..cdda65e367 100644
--- a/app/core/gimpdrawable-transform.c
+++ b/app/core/gimpdrawable-transform.c
@@ -1120,7 +1120,7 @@ gimp_drawable_transform_paste (GimpDrawable     *drawable,
     {
       gimp_drawable_set_buffer_full (drawable, TRUE, NULL,
                                      buffer,
-                                     offset_x, offset_y,
+                                     GEGL_RECTANGLE (offset_x, offset_y, 0, 0),
                                      TRUE);
     }
 
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index 3aea229b09..22b1cc2634 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -185,8 +185,7 @@ static void       gimp_drawable_real_set_buffer    (GimpDrawable      *drawable,
                                                     gboolean           push_undo,
                                                     const gchar       *undo_desc,
                                                     GeglBuffer        *buffer,
-                                                    gint               offset_x,
-                                                    gint               offset_y);
+                                                    const GeglRectangle *bounds);
 
 static void       gimp_drawable_real_push_undo     (GimpDrawable      *drawable,
                                                     const gchar       *undo_desc,
@@ -535,7 +534,8 @@ gimp_drawable_scale (GimpItem              *item,
 
   gimp_drawable_set_buffer_full (drawable, gimp_item_is_attached (item), NULL,
                                  new_buffer,
-                                 new_offset_x, new_offset_y,
+                                 GEGL_RECTANGLE (new_offset_x, new_offset_y,
+                                                 0,            0),
                                  TRUE);
   g_object_unref (new_buffer);
 }
@@ -614,7 +614,8 @@ gimp_drawable_resize (GimpItem     *item,
 
   gimp_drawable_set_buffer_full (drawable, gimp_item_is_attached (item), NULL,
                                  new_buffer,
-                                 new_offset_x, new_offset_y,
+                                 GEGL_RECTANGLE (new_offset_x, new_offset_y,
+                                                 0,            0),
                                  TRUE);
   g_object_unref (new_buffer);
 }
@@ -851,12 +852,11 @@ gimp_drawable_real_get_buffer (GimpDrawable *drawable)
 }
 
 static void
-gimp_drawable_real_set_buffer (GimpDrawable *drawable,
-                               gboolean      push_undo,
-                               const gchar  *undo_desc,
-                               GeglBuffer   *buffer,
-                               gint          offset_x,
-                               gint          offset_y)
+gimp_drawable_real_set_buffer (GimpDrawable        *drawable,
+                               gboolean             push_undo,
+                               const gchar         *undo_desc,
+                               GeglBuffer          *buffer,
+                               const GeglRectangle *bounds)
 {
   GimpItem   *item          = GIMP_ITEM (drawable);
   const Babl *old_format    = NULL;
@@ -883,10 +883,12 @@ gimp_drawable_real_set_buffer (GimpDrawable *drawable,
                    "buffer", gimp_drawable_get_buffer (drawable),
                    NULL);
 
-  gimp_item_set_offset (item, offset_x, offset_y);
+  gimp_item_set_offset (item, bounds->x, bounds->y);
   gimp_item_set_size (item,
-                      gegl_buffer_get_width  (buffer),
-                      gegl_buffer_get_height (buffer));
+                      bounds->width  ? bounds->width :
+                                       gegl_buffer_get_width (buffer),
+                      bounds->height ? bounds->height :
+                                       gegl_buffer_get_height (buffer));
 
   if (gimp_drawable_get_format (drawable) != old_format)
     gimp_drawable_format_changed (drawable);
@@ -1294,30 +1296,26 @@ gimp_drawable_set_buffer (GimpDrawable *drawable,
                           const gchar  *undo_desc,
                           GeglBuffer   *buffer)
 {
-  gint offset_x, offset_y;
-
   g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
   g_return_if_fail (GEGL_IS_BUFFER (buffer));
 
   if (! gimp_item_is_attached (GIMP_ITEM (drawable)))
     push_undo = FALSE;
 
-  gimp_item_get_offset (GIMP_ITEM (drawable), &offset_x, &offset_y);
-
-  gimp_drawable_set_buffer_full (drawable, push_undo, undo_desc, buffer,
-                                 offset_x, offset_y, TRUE);
+  gimp_drawable_set_buffer_full (drawable, push_undo, undo_desc, buffer, NULL,
+                                 TRUE);
 }
 
 void
-gimp_drawable_set_buffer_full (GimpDrawable *drawable,
-                               gboolean      push_undo,
-                               const gchar  *undo_desc,
-                               GeglBuffer   *buffer,
-                               gint          offset_x,
-                               gint          offset_y,
-                               gboolean      update)
+gimp_drawable_set_buffer_full (GimpDrawable        *drawable,
+                               gboolean             push_undo,
+                               const gchar         *undo_desc,
+                               GeglBuffer          *buffer,
+                               const GeglRectangle *bounds,
+                               gboolean             update)
 {
-  GimpItem *item;
+  GimpItem      *item;
+  GeglRectangle  curr_bounds;
 
   g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
   g_return_if_fail (GEGL_IS_BUFFER (buffer));
@@ -1327,21 +1325,40 @@ gimp_drawable_set_buffer_full (GimpDrawable *drawable,
   if (! gimp_item_is_attached (GIMP_ITEM (drawable)))
     push_undo = FALSE;
 
-  if (update                                                            &&
-      (gimp_item_get_width  (item)   != gegl_buffer_get_width (buffer)  ||
-       gimp_item_get_height (item)   != gegl_buffer_get_height (buffer) ||
-       gimp_item_get_offset_x (item) != offset_x                        ||
-       gimp_item_get_offset_y (item) != offset_y))
+  if (! bounds)
+    {
+      gimp_item_get_offset (GIMP_ITEM (drawable),
+                            &curr_bounds.x, &curr_bounds.y);
+
+      curr_bounds.width  = 0;
+      curr_bounds.height = 0;
+
+      bounds = &curr_bounds;
+    }
+
+  if (update && gimp_drawable_get_buffer (drawable))
     {
-      gimp_drawable_update (drawable, 0, 0, -1, -1);
+      GeglBuffer    *old_buffer = gimp_drawable_get_buffer (drawable);
+      GeglRectangle  old_extent;
+      GeglRectangle  new_extent;
+
+      old_extent = *gegl_buffer_get_extent (old_buffer);
+      old_extent.x += gimp_item_get_offset_x (item);
+      old_extent.y += gimp_item_get_offset_x (item);
+
+      new_extent = *gegl_buffer_get_extent (buffer);
+      new_extent.x += bounds->x;
+      new_extent.y += bounds->y;
+
+      if (! gegl_rectangle_equal (&old_extent, &new_extent))
+        gimp_drawable_update (drawable, 0, 0, -1, -1);
     }
 
   g_object_freeze_notify (G_OBJECT (drawable));
 
   GIMP_DRAWABLE_GET_CLASS (drawable)->set_buffer (drawable,
                                                   push_undo, undo_desc,
-                                                  buffer,
-                                                  offset_x, offset_y);
+                                                  buffer, bounds);
 
   g_object_thaw_notify (G_OBJECT (drawable));
 
diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h
index 4227df098d..e19b48fbe5 100644
--- a/app/core/gimpdrawable.h
+++ b/app/core/gimpdrawable.h
@@ -89,8 +89,7 @@ struct _GimpDrawableClass
                                            gboolean              push_undo,
                                            const gchar          *undo_desc,
                                            GeglBuffer           *buffer,
-                                           gint                  offset_x,
-                                           gint                  offset_y);
+                                           const GeglRectangle  *bounds);
   void          (* push_undo)             (GimpDrawable         *drawable,
                                            const gchar          *undo_desc,
                                            GeglBuffer           *buffer,
@@ -168,8 +167,7 @@ void            gimp_drawable_set_buffer_full    (GimpDrawable       *drawable,
                                                   gboolean            push_undo,
                                                   const gchar        *undo_desc,
                                                   GeglBuffer         *buffer,
-                                                  gint                offset_x,
-                                                  gint                offset_y,
+                                                  const GeglRectangle *bounds,
                                                   gboolean            update);
 
 void            gimp_drawable_steal_buffer       (GimpDrawable       *drawable,
diff --git a/app/core/gimpdrawablemodundo.c b/app/core/gimpdrawablemodundo.c
index db2c933058..5c3e897eb1 100644
--- a/app/core/gimpdrawablemodundo.c
+++ b/app/core/gimpdrawablemodundo.c
@@ -198,7 +198,9 @@ gimp_drawable_mod_undo_pop (GimpUndo            *undo,
                         &drawable_mod_undo->offset_y);
 
   gimp_drawable_set_buffer_full (drawable, FALSE, NULL,
-                                 buffer, offset_x, offset_y, TRUE);
+                                 buffer,
+                                 GEGL_RECTANGLE (offset_x, offset_y, 0, 0),
+                                 TRUE);
   g_object_unref (buffer);
 }
 
diff --git a/app/core/gimpgrouplayer.c b/app/core/gimpgrouplayer.c
index 75d316c204..c71ff9141f 100644
--- a/app/core/gimpgrouplayer.c
+++ b/app/core/gimpgrouplayer.c
@@ -1068,9 +1068,7 @@ gimp_group_layer_convert_type (GimpLayer        *layer,
 
   gimp_drawable_set_buffer_full (GIMP_DRAWABLE (group),
                                  FALSE, NULL,
-                                 buffer,
-                                 gimp_item_get_offset_x (GIMP_ITEM (group)),
-                                 gimp_item_get_offset_y (GIMP_ITEM (group)),
+                                 buffer, NULL,
                                  TRUE);
 
   /*  reset, the actual format is right now  */
@@ -1993,8 +1991,7 @@ gimp_group_layer_update_size (GimpGroupLayer *group)
 
       gimp_drawable_set_buffer_full (GIMP_DRAWABLE (group),
                                      FALSE, NULL,
-                                     buffer,
-                                     x, y,
+                                     buffer, NULL,
                                      FALSE /* don't update the drawable, the
                                             * flush() below will take care of
                                             * that.
@@ -2100,7 +2097,7 @@ gimp_group_layer_update_mask_size (GimpGroupLayer *group)
 
   gimp_drawable_set_buffer_full (GIMP_DRAWABLE (mask),
                                  FALSE, NULL,
-                                 buffer, bounds.x, bounds.y,
+                                 buffer, &bounds,
                                  TRUE);
 
   g_object_unref (buffer);
diff --git a/app/core/gimpgrouplayerundo.c b/app/core/gimpgrouplayerundo.c
index a1ac9e3f1e..7ea70f4abb 100644
--- a/app/core/gimpgrouplayerundo.c
+++ b/app/core/gimpgrouplayerundo.c
@@ -158,8 +158,7 @@ gimp_group_layer_undo_pop (GimpUndo            *undo,
               gimp_drawable_set_buffer_full (GIMP_DRAWABLE (mask),
                                              FALSE, NULL,
                                              group_layer_undo->mask_buffer,
-                                             group_layer_undo->mask_bounds.x,
-                                             group_layer_undo->mask_bounds.y,
+                                             &group_layer_undo->mask_bounds,
                                              TRUE);
             }
         }
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index af4abbf3d2..e966634a60 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -200,8 +200,7 @@ static void    gimp_layer_set_buffer            (GimpDrawable       *drawable,
                                                  gboolean            push_undo,
                                                  const gchar        *undo_desc,
                                                  GeglBuffer         *buffer,
-                                                 gint                offset_x,
-                                                 gint                offset_y);
+                                                 const GeglRectangle *bounds);
 
 static GimpColorProfile *
                gimp_layer_get_color_profile     (GimpColorManaged   *managed);
@@ -1477,12 +1476,11 @@ gimp_layer_get_active_mask (GimpDrawable *drawable)
 }
 
 static void
-gimp_layer_set_buffer (GimpDrawable *drawable,
-                       gboolean      push_undo,
-                       const gchar  *undo_desc,
-                       GeglBuffer   *buffer,
-                       gint          offset_x,
-                       gint          offset_y)
+gimp_layer_set_buffer (GimpDrawable        *drawable,
+                       gboolean             push_undo,
+                       const gchar         *undo_desc,
+                       GeglBuffer          *buffer,
+                       const GeglRectangle *bounds)
 {
   GeglBuffer *old_buffer = gimp_drawable_get_buffer (drawable);
   gint        old_linear = -1;
@@ -1492,8 +1490,7 @@ gimp_layer_set_buffer (GimpDrawable *drawable,
 
   GIMP_DRAWABLE_CLASS (parent_class)->set_buffer (drawable,
                                                   push_undo, undo_desc,
-                                                  buffer,
-                                                  offset_x, offset_y);
+                                                  buffer, bounds);
 
   if (gimp_filter_peek_node (GIMP_FILTER (drawable)))
     {
diff --git a/app/text/gimptextlayer.c b/app/text/gimptextlayer.c
index 41c7e12453..fb4146a74a 100644
--- a/app/text/gimptextlayer.c
+++ b/app/text/gimptextlayer.c
@@ -95,8 +95,7 @@ static void       gimp_text_layer_set_buffer     (GimpDrawable      *drawable,
                                                   gboolean           push_undo,
                                                   const gchar       *undo_desc,
                                                   GeglBuffer        *buffer,
-                                                  gint               offset_x,
-                                                  gint               offset_y);
+                                                  const GeglRectangle *bounds);
 static void       gimp_text_layer_push_undo      (GimpDrawable      *drawable,
                                                   const gchar       *undo_desc,
                                                   GeglBuffer        *buffer,
@@ -323,12 +322,11 @@ gimp_text_layer_rename (GimpItem     *item,
 }
 
 static void
-gimp_text_layer_set_buffer (GimpDrawable *drawable,
-                            gboolean      push_undo,
-                            const gchar  *undo_desc,
-                            GeglBuffer   *buffer,
-                            gint          offset_x,
-                            gint          offset_y)
+gimp_text_layer_set_buffer (GimpDrawable        *drawable,
+                            gboolean             push_undo,
+                            const gchar         *undo_desc,
+                            GeglBuffer          *buffer,
+                            const GeglRectangle *bounds)
 {
   GimpTextLayer *layer = GIMP_TEXT_LAYER (drawable);
   GimpImage     *image = gimp_item_get_image (GIMP_ITEM (layer));
@@ -339,8 +337,7 @@ gimp_text_layer_set_buffer (GimpDrawable *drawable,
 
   GIMP_DRAWABLE_CLASS (parent_class)->set_buffer (drawable,
                                                   push_undo, undo_desc,
-                                                  buffer,
-                                                  offset_x, offset_y);
+                                                  buffer, bounds);
 
   if (push_undo && ! layer->modified)
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]