[gegl/threaded-base-classes] operation: refactor in_place handling to take place in base classes



commit 6f01798b4e69a50baafa818bd3d0d3cd0017cfed
Author: Øyvind Kolås <pippin gimp org>
Date:   Tue Jun 24 08:13:49 2014 +0200

    operation: refactor in_place handling to take place in base classes
    
    Adding a flag to operation, that is used by the implementation/further
    subclass to declare that in-place processing should be done if possible.  This
    also adds that capability to the base class of GIMPs layer modes.

 gegl/operation/gegl-operation-composer3.c       |   16 +++++++++++++++-
 gegl/operation/gegl-operation-point-composer.c  |    9 +++++++--
 gegl/operation/gegl-operation-point-composer3.c |    1 +
 gegl/operation/gegl-operation-point-filter.c    |    5 ++++-
 gegl/operation/gegl-operation.h                 |    6 +++++-
 5 files changed, 32 insertions(+), 5 deletions(-)
---
diff --git a/gegl/operation/gegl-operation-composer3.c b/gegl/operation/gegl-operation-composer3.c
index c79f803..b885661 100644
--- a/gegl/operation/gegl-operation-composer3.c
+++ b/gegl/operation/gegl-operation-composer3.c
@@ -165,12 +165,26 @@ gegl_operation_composer3_process (GeglOperation        *operation,
       g_warning ("requested processing of %s pad on a composer", output_prop);
       return FALSE;
     }
-  output = gegl_operation_context_get_target (context, "output");
 
   if (result->width == 0 || result->height == 0)
+  {
+    output = gegl_operation_context_get_target (context, "output");
     return TRUE;
+  }
 
   input = gegl_operation_context_get_source (context, "input");
+
+  if (op_class->want_in_place && 
+      gegl_can_do_inplace_processing (operation, input, result))
+    {
+      output = g_object_ref (input);
+      gegl_operation_context_take_object (context, "output", G_OBJECT (output));
+    }
+  else
+    {
+      output = gegl_operation_context_get_target (context, "output");
+    }
+
   aux   = gegl_operation_context_get_source (context, "aux");
   aux2  = gegl_operation_context_get_source (context, "aux2");
 
diff --git a/gegl/operation/gegl-operation-point-composer.c b/gegl/operation/gegl-operation-point-composer.c
index ec99365..8c52c08 100644
--- a/gegl/operation/gegl-operation-point-composer.c
+++ b/gegl/operation/gegl-operation-point-composer.c
@@ -66,6 +66,7 @@ gegl_operation_point_composer_class_init (GeglOperationPointComposerClass *klass
   operation_class->prepare = prepare;
   operation_class->no_cache = FALSE;
   operation_class->process = gegl_operation_composer_process2;
+  operation_class->want_in_place = TRUE;
 
   klass->process = NULL;
   klass->cl_process = NULL;
@@ -88,6 +89,7 @@ gegl_operation_composer_process2 (GeglOperation        *operation,
                                   gint                  level)
 {
   GeglOperationComposerClass *klass   = GEGL_OPERATION_COMPOSER_GET_CLASS (operation);
+  GeglOperationClass         *op_class = (void*)klass;
   GeglBuffer                 *input;
   GeglBuffer                 *aux;
   GeglBuffer                 *output;
@@ -102,13 +104,16 @@ gegl_operation_composer_process2 (GeglOperation        *operation,
   input = gegl_operation_context_get_source (context, "input");
   aux   = gegl_operation_context_get_source (context, "aux");
 
-  if (gegl_can_do_inplace_processing (operation, input, result))
+  if (op_class->want_in_place && 
+      gegl_can_do_inplace_processing (operation, input, result))
     {
       output = g_object_ref (input);
       gegl_operation_context_take_object (context, "output", G_OBJECT (output));
     }
   else
-    output = gegl_operation_context_get_target (context, "output");
+    {
+      output = gegl_operation_context_get_target (context, "output");
+    }
 
     {
       if (result->width == 0 || result->height == 0)
diff --git a/gegl/operation/gegl-operation-point-composer3.c b/gegl/operation/gegl-operation-point-composer3.c
index 92a6612..fd0faa1 100644
--- a/gegl/operation/gegl-operation-point-composer3.c
+++ b/gegl/operation/gegl-operation-point-composer3.c
@@ -56,6 +56,7 @@ gegl_operation_point_composer3_class_init (GeglOperationPointComposer3Class *kla
   composer_class->process = gegl_operation_point_composer3_process;
   operation_class->prepare = prepare;
   operation_class->no_cache =TRUE;
+  operation_class->want_in_place = TRUE;
 }
 
 static void
diff --git a/gegl/operation/gegl-operation-point-filter.c b/gegl/operation/gegl-operation-point-filter.c
index 886f8f9..a30abbb 100644
--- a/gegl/operation/gegl-operation-point-filter.c
+++ b/gegl/operation/gegl-operation-point-filter.c
@@ -60,6 +60,7 @@ gegl_operation_point_filter_class_init (GeglOperationPointFilterClass *klass)
   operation_class->process = gegl_operation_point_filter_op_process;
   operation_class->prepare = prepare;
   operation_class->no_cache = TRUE;
+  operation_class->want_in_place = TRUE;
 
   klass->process = NULL;
   klass->cl_process = NULL;
@@ -198,13 +199,15 @@ static gboolean gegl_operation_point_filter_op_process
                                const GeglRectangle  *roi,
                                gint                  level)
 {
+  GeglOperationClass       *klass = GEGL_OPERATION_GET_CLASS (operation);
   GeglBuffer               *input;
   GeglBuffer               *output;
   gboolean                  success = FALSE;
 
   input = gegl_operation_context_get_source (context, "input");
 
-  if (gegl_can_do_inplace_processing (operation, input, roi))
+  if (klass->want_in_place && 
+      gegl_can_do_inplace_processing (operation, input, roi))
     {
       output = g_object_ref (input);
       gegl_operation_context_take_object (context, "output", G_OBJECT (output));
diff --git a/gegl/operation/gegl-operation.h b/gegl/operation/gegl-operation.h
index fb3b739..02c6f72 100644
--- a/gegl/operation/gegl-operation.h
+++ b/gegl/operation/gegl-operation.h
@@ -79,7 +79,11 @@ struct _GeglOperationClass
   guint           no_cache      :1;  /* do not create a cache for this operation */
   guint           opencl_support:1;
   guint           parallelize:1;
-  guint64         bit_pad:61;
+  guint           want_in_place:1; /* if possible to use for in-place
+                                      processing, making output buffer =
+                                      input buffer.
+                                      */
+  guint64         bit_pad:60;
 
   /* attach this operation with a GeglNode, override this if you are creating a
    * GeglGraph, it is already defined for Filters/Sources/Composers.


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