[gimp] app: add gimp_drawable_steal_buffer()



commit b50be495cbc279af17a72f093bf813ccd90e1580
Author: Ell <ell_se yahoo com>
Date:   Tue Feb 13 13:09:07 2018 -0500

    app: add gimp_drawable_steal_buffer()
    
    ... which transfers a buffer from one drawable to another in a safe
    manner, leaving the source drawable empty.
    
    There are already two ad-hoc instances where we steal a drawable's
    buffer through simple pointer assignment, however, this avoids
    performing potentially necessary cleanup and setup.  In particular,
    since commit d0ae244fe85a502446fe9c7b82afdf1b89498966 this causes
    actual errors.  The next two commits replace those instances with
    calls to gimp_drawable_steal_buffer().

 app/core/gimpdrawable.c |   21 +++++++++++++++++++++
 app/core/gimpdrawable.h |    3 +++
 2 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index ce1d829..d259944 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -1214,6 +1214,27 @@ gimp_drawable_set_buffer_full (GimpDrawable *drawable,
     gimp_drawable_update (drawable, 0, 0, -1, -1);
 }
 
+void
+gimp_drawable_steal_buffer (GimpDrawable *drawable,
+                            GimpDrawable *src_drawable)
+{
+  GeglBuffer *buffer;
+
+  g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
+  g_return_if_fail (GIMP_IS_DRAWABLE (src_drawable));
+
+  buffer = gimp_drawable_get_buffer (src_drawable);
+
+  if (buffer)
+    g_object_ref (buffer);
+
+  gimp_drawable_set_buffer (src_drawable, FALSE, NULL, NULL);
+  gimp_drawable_set_buffer (drawable,     FALSE, NULL, buffer);
+
+  if (buffer)
+    g_object_unref (buffer);
+}
+
 GeglNode *
 gimp_drawable_get_source_node (GimpDrawable *drawable)
 {
diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h
index c80c7d9..abd1e45 100644
--- a/app/core/gimpdrawable.h
+++ b/app/core/gimpdrawable.h
@@ -189,6 +189,9 @@ void            gimp_drawable_set_buffer_full    (GimpDrawable       *drawable,
                                                   gint                offset_x,
                                                   gint                offset_y);
 
+void            gimp_drawable_steal_buffer       (GimpDrawable       *drawable,
+                                                  GimpDrawable       *src_drawable);
+
 GeglNode      * gimp_drawable_get_source_node    (GimpDrawable       *drawable);
 GeglNode      * gimp_drawable_get_mode_node      (GimpDrawable       *drawable);
 


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