[gegl] add gegl_operation_progress



commit 4f2e557a0bb4b685870c12e9f16bcbdb3b371414
Author: Øyvind Kolås <pippin gimp org>
Date:   Thu Apr 21 16:24:45 2016 +0100

    add gegl_operation_progress

 gegl/graph/gegl-node.c          |   48 +++++++++++++++++++++++++++++++++++++-
 gegl/graph/gegl-node.h          |    2 +
 gegl/operation/gegl-operation.c |    8 ++++++
 gegl/operation/gegl-operation.h |    4 +-
 4 files changed, 58 insertions(+), 4 deletions(-)
---
diff --git a/gegl/graph/gegl-node.c b/gegl/graph/gegl-node.c
index ecd3e2c..0adf869 100644
--- a/gegl/graph/gegl-node.c
+++ b/gegl/graph/gegl-node.c
@@ -58,6 +58,7 @@ enum
 {
   INVALIDATED,
   COMPUTED,
+  PROGRESS,
   LAST_SIGNAL
 };
 
@@ -200,6 +201,15 @@ gegl_node_class_init (GeglNodeClass *klass)
                   g_cclosure_marshal_VOID__BOXED,
                   G_TYPE_NONE, 1,
                   GEGL_TYPE_RECTANGLE);
+
+  gegl_node_signals[PROGRESS] =
+    g_signal_new ("progress",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
+                  0,
+                  NULL, NULL,
+                  g_cclosure_marshal_VOID__DOUBLE,
+                  G_TYPE_NONE, 1, G_TYPE_DOUBLE);
 }
 
 static void
@@ -1677,7 +1687,7 @@ gegl_node_get_bounding_box (GeglNode *self)
 }
 
 void
-gegl_node_process (GeglNode *self)
+gegl_node_process (GeglNode *self) /* XXX: add level argument?  */
 {
   GeglProcessor *processor;
 
@@ -1728,7 +1738,7 @@ gegl_node_insert_before (GeglNode *self,
   g_return_if_fail (GEGL_IS_NODE (self));
   g_return_if_fail (GEGL_IS_NODE (to_be_inserted));
 
-  other     = gegl_node_get_producer (self, "input", NULL);/*XXX: handle pad name */
+  other     = gegl_node_get_producer (self, "input", NULL); /*XXX: handle pad name */
   rectangle = gegl_node_get_bounding_box (to_be_inserted);
 
   g_signal_handlers_block_matched (other, G_SIGNAL_MATCH_FUNC, 0, 0, 0, gegl_node_source_invalidated, NULL);
@@ -2170,3 +2180,37 @@ gegl_node_set_passthrough (GeglNode *node,
   gegl_node_invalidated (node, NULL, TRUE);
   node->passthrough = passthrough;
 }
+
+typedef struct Closure {
+  GeglNode  *node;
+  gdouble    progress;
+} Closure;
+
+static gboolean delayed_emission (void *data)
+{
+  Closure *closure = data;
+  g_signal_emit (closure->node,
+                 gegl_node_signals[PROGRESS], 0,
+                 closure->progress, NULL, NULL);
+  g_free (closure);
+  return FALSE;
+}
+
+/* this causes dispatch of the signal on the main thread - if we
+ * are in the main thread the callback will be directly executed now
+ * instead of queued
+ */
+void gegl_node_progress (GeglNode *node,
+                         gdouble   progress,
+                         gchar    *message)
+{
+  if (gegl_is_main_thread ())
+    g_signal_emit (node, gegl_node_signals[PROGRESS], 0, progress, message, NULL);
+  else
+  {
+    Closure *closure = g_new0 (Closure, 1);
+    closure->node = node;
+    closure->progress = progress;
+    g_idle_add (delayed_emission, closure);
+  }
+}
diff --git a/gegl/graph/gegl-node.h b/gegl/graph/gegl-node.h
index c98dba7..767745e 100644
--- a/gegl/graph/gegl-node.h
+++ b/gegl/graph/gegl-node.h
@@ -692,6 +692,8 @@ void           gegl_node_set_passthrough (GeglNode      *node,
                                           gboolean       passthrough);
 
 
+void       gegl_node_progress (GeglNode *node, gdouble progress, gchar *message);
+
 G_END_DECLS
 
 #endif /* __GEGL_NODE_H__ */
diff --git a/gegl/operation/gegl-operation.c b/gegl/operation/gegl-operation.c
index b90ef76..a2d9cd5 100644
--- a/gegl/operation/gegl-operation.c
+++ b/gegl/operation/gegl-operation.c
@@ -834,3 +834,11 @@ void gegl_temp_buffer_free (void)
       gegl_temp_size[no] = 0;
     }
 }
+
+void gegl_operation_progress (GeglOperation *operation,
+                              gdouble        progress,
+                              gchar         *message)
+{
+  if (operation->node)
+    gegl_node_progress (operation->node, progress, message);
+}
diff --git a/gegl/operation/gegl-operation.h b/gegl/operation/gegl-operation.h
index 62d2f24..e8bf96a 100644
--- a/gegl/operation/gegl-operation.h
+++ b/gegl/operation/gegl-operation.h
@@ -154,8 +154,6 @@ struct _GeglOperationClass
   gpointer      pad[9];
 };
 
-
-
 GeglRectangle   gegl_operation_get_invalidated_by_change
                                              (GeglOperation *operation,
                                               const gchar   *input_pad,
@@ -298,6 +296,8 @@ gboolean  gegl_object_get_has_forked      (GObject *object);
  */
 guchar    *gegl_temp_buffer (int no, int min_size);
 
+void       gegl_operation_progress (GeglOperation *operation, gdouble progress, gchar *message);
+
 G_END_DECLS
 
 /***


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