[gimp/wip/passthrough: 18/26] app: add GimpDrawable::get_source_node() vfunc



commit 9bdd9747517805607674b87b3ffb52ce0a6b2032
Author: Ell <ell_se yahoo com>
Date:   Fri Apr 21 15:21:10 2017 -0400

    app: add GimpDrawable::get_source_node() vfunc
    
    For pass-through groups, we want to use the group's layer-stack
    graph directly in its filter node, in place of the drawable's
    buffer-source node.  Add a get_source_node() vfunc to GimpDrawable,
    which defaults to returning the buffer-source node, and use it in
    gimp_drawable_get_source_node() instead of using the buffer-source
    node directly.  We'll later override this function for
    GimpGroupLayer.

 app/core/gimpdrawable.c |   38 +++++++++++++++++++++++++++++++-------
 app/core/gimpdrawable.h |    1 +
 2 files changed, 32 insertions(+), 7 deletions(-)
---
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index 131db44..8fe8d46 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -181,6 +181,7 @@ static void       gimp_drawable_real_swap_pixels   (GimpDrawable      *drawable,
                                                     GeglBuffer        *buffer,
                                                     gint               x,
                                                     gint               y);
+static GeglNode * gimp_drawable_real_get_source_node (GimpDrawable    *drawable);
 
 
 G_DEFINE_TYPE_WITH_CODE (GimpDrawable, gimp_drawable, GIMP_TYPE_ITEM,
@@ -260,6 +261,7 @@ gimp_drawable_class_init (GimpDrawableClass *klass)
   klass->set_buffer                  = gimp_drawable_real_set_buffer;
   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;
 
   g_object_class_override_property (object_class, PROP_BUFFER, "buffer");
 
@@ -326,6 +328,12 @@ gimp_drawable_finalize (GObject *object)
       drawable->private->source_node = NULL;
     }
 
+  if (drawable->private->buffer_source_node)
+    {
+      g_object_unref (drawable->private->buffer_source_node);
+      drawable->private->buffer_source_node = NULL;
+    }
+
   if (drawable->private->filter_stack)
     {
       g_object_unref (drawable->private->filter_stack);
@@ -919,6 +927,21 @@ gimp_drawable_real_swap_pixels (GimpDrawable *drawable,
   gimp_drawable_update (drawable, x, y, width, height);
 }
 
+static GeglNode *
+gimp_drawable_real_get_source_node (GimpDrawable *drawable)
+{
+  g_warn_if_fail (drawable->private->buffer_source_node == NULL);
+
+  drawable->private->buffer_source_node = gegl_node_new ();
+
+  gegl_node_set (drawable->private->buffer_source_node,
+                 "operation", "gegl:buffer-source",
+                 "buffer",    gimp_drawable_get_buffer (drawable),
+                 NULL);
+
+  return g_object_ref (drawable->private->buffer_source_node);
+}
+
 
 /*  public functions  */
 
@@ -1222,6 +1245,7 @@ gimp_drawable_set_buffer_full (GimpDrawable *drawable,
 GeglNode *
 gimp_drawable_get_source_node (GimpDrawable *drawable)
 {
+  GeglNode *source;
   GeglNode *filter;
   GeglNode *output;
 
@@ -1232,18 +1256,18 @@ gimp_drawable_get_source_node (GimpDrawable *drawable)
 
   drawable->private->source_node = gegl_node_new ();
 
-  drawable->private->buffer_source_node =
-    gegl_node_new_child (drawable->private->source_node,
-                         "operation", "gegl:buffer-source",
-                         "buffer",    gimp_drawable_get_buffer (drawable),
-                         NULL);
+  source = GIMP_DRAWABLE_GET_CLASS (drawable)->get_source_node (drawable);
+
+  gegl_node_add_child (drawable->private->source_node, source);
+
+  g_object_unref (source);
 
   filter = gimp_filter_stack_get_graph (GIMP_FILTER_STACK (drawable->private->filter_stack));
 
   gegl_node_add_child (drawable->private->source_node, filter);
 
-  gegl_node_connect_to (drawable->private->buffer_source_node, "output",
-                        filter,                                "input");
+  gegl_node_connect_to (source, "output",
+                        filter, "input");
 
   output = gegl_node_get_output_proxy (drawable->private->source_node, "output");
 
diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h
index 1be7af7..c80c7d9 100644
--- a/app/core/gimpdrawable.h
+++ b/app/core/gimpdrawable.h
@@ -110,6 +110,7 @@ struct _GimpDrawableClass
                                            GeglBuffer           *buffer,
                                            gint                  x,
                                            gint                  y);
+  GeglNode    * (* get_source_node)       (GimpDrawable         *drawable);
 };
 
 


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