[gimp] app: avoid useless line art closure recomputation.



commit c0996241f684e5ea51464e459353db94f366032b
Author: Jehan <jehan girinstud io>
Date:   Mon Mar 4 16:43:19 2019 +0100

    app: avoid useless line art closure recomputation.
    
    On various property changes, only recompute the line art when the
    property actually changed. Also add a gimp_line_art_bind_gap_length() to
    avoid computing twice the line art when changing both type of closure
    (splines and segments) together, as is currently the case.

 app/core/gimplineart.c         | 40 ++++++++++++++++++++++++++++++++--------
 app/core/gimplineart.h         |  3 +++
 app/tools/gimpbucketfilltool.c | 23 +++++++++++------------
 3 files changed, 46 insertions(+), 20 deletions(-)
---
diff --git a/app/core/gimplineart.c b/app/core/gimplineart.c
index a79c9b6831..528ec9a6c9 100644
--- a/app/core/gimplineart.c
+++ b/app/core/gimplineart.c
@@ -80,6 +80,7 @@ struct _GimpLineArtPrivate
   gdouble       threshold;
   gint          spline_max_len;
   gint          segment_max_len;
+  gboolean      max_len_bound;
 
   /* Used in the grow step. */
   gint          max_grow;
@@ -381,23 +382,39 @@ gimp_line_art_set_property (GObject      *object,
   switch (property_id)
     {
     case PROP_SELECT_TRANSPARENT:
-      line_art->priv->select_transparent = g_value_get_boolean (value);
-      gimp_line_art_compute (line_art);
+      if (line_art->priv->select_transparent != g_value_get_boolean (value))
+        {
+          line_art->priv->select_transparent = g_value_get_boolean (value);
+          gimp_line_art_compute (line_art);
+        }
       break;
     case PROP_MAX_GROW:
       line_art->priv->max_grow = g_value_get_int (value);
       break;
     case PROP_THRESHOLD:
-      line_art->priv->threshold = g_value_get_double (value);
-      gimp_line_art_compute (line_art);
+      if (line_art->priv->threshold != g_value_get_double (value))
+        {
+          line_art->priv->threshold = g_value_get_double (value);
+          gimp_line_art_compute (line_art);
+        }
       break;
     case PROP_SPLINE_MAX_LEN:
-      line_art->priv->spline_max_len = g_value_get_int (value);
-      gimp_line_art_compute (line_art);
+      if (line_art->priv->spline_max_len != g_value_get_int (value))
+        {
+          line_art->priv->spline_max_len = g_value_get_int (value);
+          if (line_art->priv->max_len_bound)
+            line_art->priv->segment_max_len = line_art->priv->spline_max_len;
+          gimp_line_art_compute (line_art);
+        }
       break;
     case PROP_SEGMENT_MAX_LEN:
-      line_art->priv->segment_max_len = g_value_get_int (value);
-      gimp_line_art_compute (line_art);
+      if (line_art->priv->segment_max_len != g_value_get_int (value))
+        {
+          line_art->priv->segment_max_len = g_value_get_int (value);
+          if (line_art->priv->max_len_bound)
+            line_art->priv->spline_max_len = line_art->priv->segment_max_len;
+          gimp_line_art_compute (line_art);
+        }
       break;
 
     default:
@@ -447,6 +464,13 @@ gimp_line_art_new (void)
                        NULL);
 }
 
+void
+gimp_line_art_bind_gap_length (GimpLineArt *line_art,
+                               gboolean     bound)
+{
+  line_art->priv->max_len_bound = bound;
+}
+
 void
 gimp_line_art_set_input (GimpLineArt  *line_art,
                          GimpPickable *pickable)
diff --git a/app/core/gimplineart.h b/app/core/gimplineart.h
index 184307d2d7..67376734f6 100644
--- a/app/core/gimplineart.h
+++ b/app/core/gimplineart.h
@@ -57,6 +57,9 @@ GType                gimp_line_art_get_type         (void) G_GNUC_CONST;
 
 GimpLineArt        * gimp_line_art_new              (void);
 
+void                 gimp_line_art_bind_gap_length  (GimpLineArt  *line_art,
+                                                     gboolean      bound);
+
 void                 gimp_line_art_set_input        (GimpLineArt  *line_art,
                                                      GimpPickable *pickable);
 GimpPickable       * gimp_line_art_get_input        (GimpLineArt  *line_art);
diff --git a/app/tools/gimpbucketfilltool.c b/app/tools/gimpbucketfilltool.c
index 8ee72e7607..547c7dacc4 100644
--- a/app/tools/gimpbucketfilltool.c
+++ b/app/tools/gimpbucketfilltool.c
@@ -235,6 +235,7 @@ gimp_bucket_fill_tool_constructed (GObject *object)
   g_signal_connect_swapped (line_art, "computing-end",
                             G_CALLBACK (gimp_bucket_fill_tool_line_art_computing_end),
                             tool);
+  gimp_line_art_bind_gap_length (line_art, TRUE);
   bucket_tool->priv->line_art = line_art;
 
   gimp_bucket_fill_tool_reset_line_art (bucket_tool);
@@ -800,19 +801,17 @@ gimp_bucket_fill_tool_options_notify (GimpTool         *tool,
   GIMP_TOOL_CLASS (parent_class)->options_notify (tool, options, pspec);
 
   if (! strcmp (pspec->name, "fill-area"))
-    /* We want more motion events when the tool is used in a paint tool
-     * fashion. Unfortunately we only set exact mode in line art fill,
-     * because we can't as easily remove events from the similar color
-     * mode just because a point has already been selected  (unless
-     * threshold were 0, but that's an edge case).
-     */
-    gimp_tool_control_set_motion_mode (tool->control,
-                                       bucket_options->fill_area == GIMP_BUCKET_FILL_LINE_ART ?
-                                       GIMP_MOTION_MODE_EXACT : GIMP_MOTION_MODE_COMPRESS);
-
-  if (! strcmp (pspec->name, "fill-area") ||
-      ! strcmp (pspec->name, "sample-merged"))
     {
+      /* We want more motion events when the tool is used in a paint tool
+       * fashion. Unfortunately we only set exact mode in line art fill,
+       * because we can't as easily remove events from the similar color
+       * mode just because a point has already been selected  (unless
+       * threshold were 0, but that's an edge case).
+       */
+      gimp_tool_control_set_motion_mode (tool->control,
+                                         bucket_options->fill_area == GIMP_BUCKET_FILL_LINE_ART ?
+                                         GIMP_MOTION_MODE_EXACT : GIMP_MOTION_MODE_COMPRESS);
+
       gimp_bucket_fill_tool_reset_line_art (bucket_tool);
     }
   else if (! strcmp (pspec->name, "fill-mode"))


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