[gimp/wip/animation: 141/197] plug-ins: speed-up updating composition of many frames at once.



commit b941092e53d0f622a84138f42e096e2d6dfbdd3c
Author: Jehan <jehan girinstud io>
Date:   Mon May 22 17:06:21 2017 +0200

    plug-ins: speed-up updating composition of many frames at once.
    
    Even though actual rendering is now done in background, the GUI was
    still lagging out. This was because of the recursive renaming on cels
    which was still needed but we were recomputing cel names just too many
    times.

 plug-ins/animation-play/animation-utils.c          |   25 +++++++++++++++
 plug-ins/animation-play/animation-utils.h          |    4 ++
 plug-ins/animation-play/core/animation-renderer.c  |   33 ++------------------
 plug-ins/animation-play/widgets/animation-xsheet.c |   26 +++++++++------
 4 files changed, 48 insertions(+), 40 deletions(-)
---
diff --git a/plug-ins/animation-play/animation-utils.c b/plug-ins/animation-play/animation-utils.c
index 1f57729..76fe3fb 100755
--- a/plug-ins/animation-play/animation-utils.c
+++ b/plug-ins/animation-play/animation-utils.c
@@ -315,3 +315,28 @@ show_item (gint   item,
   if (parent > 0)
     show_item (parent, -1);
 }
+
+gint
+compare_int_from (gconstpointer f1,
+                  gconstpointer f2,
+                  gpointer      data)
+{
+  gint first_frame = GPOINTER_TO_INT (data);
+  gint frame1      = GPOINTER_TO_INT (f1);
+  gint frame2      = GPOINTER_TO_INT (f2);
+  gint invert;
+
+  if (frame1 == frame2)
+    {
+      return 0;
+    }
+  else
+    {
+      invert = ((frame1 >= first_frame && frame2 >= first_frame) ||
+                (frame1 < first_frame && frame2 < first_frame)) ? 1 : -1;
+      if (frame1 < frame2)
+        return invert * -1;
+      else
+        return invert;
+    }
+}
diff --git a/plug-ins/animation-play/animation-utils.h b/plug-ins/animation-play/animation-utils.h
index 590fbdf..79c598c 100755
--- a/plug-ins/animation-play/animation-utils.h
+++ b/plug-ins/animation-play/animation-utils.h
@@ -54,6 +54,10 @@ void         hide_item           (gint               item,
 void         show_item           (gint               item,
                                   gint32             color_tag);
 
+gint         compare_int_from    (gconstpointer      f1,
+                                  gconstpointer      f2,
+                                  gpointer           data);
+
 #endif  /*  __ANIMATION_UTILS_H__  */
 
 
diff --git a/plug-ins/animation-play/core/animation-renderer.c 
b/plug-ins/animation-play/core/animation-renderer.c
index 507ca81..042c6f6 100644
--- a/plug-ins/animation-play/core/animation-renderer.c
+++ b/plug-ins/animation-play/core/animation-renderer.c
@@ -23,6 +23,8 @@
 #include <libgimp/gimp.h>
 #include <libgimp/stdplugins-intl.h>
 
+#include "animation-utils.h"
+
 #include "animation.h"
 #include "animation-playback.h"
 #include "animation-renderer.h"
@@ -67,10 +69,6 @@ static void     animation_renderer_get_property  (GObject           *object,
                                                   GValue            *value,
                                                   GParamSpec        *pspec);
 
-static gint     animation_renderer_sort_frame    (gconstpointer      f1,
-                                                  gconstpointer      f2,
-                                                  gpointer           data);
-
 static gpointer animation_renderer_process_queue (AnimationRenderer *renderer);
 static gboolean animation_renderer_idle_update   (AnimationRenderer *renderer);
 
@@ -225,31 +223,6 @@ animation_renderer_get_property (GObject      *object,
     }
 }
 
-static gint
-animation_renderer_sort_frame (gconstpointer f1,
-                               gconstpointer f2,
-                               gpointer      data)
-{
-  gint first_frame = GPOINTER_TO_INT (data);
-  gint frame1      = GPOINTER_TO_INT (f1);
-  gint frame2      = GPOINTER_TO_INT (f2);
-  gint invert;
-
-  if (frame1 == frame2)
-    {
-      return 0;
-    }
-  else
-    {
-      invert = ((frame1 >= first_frame && frame2 >= first_frame) ||
-                (frame1 < first_frame && frame2 < first_frame)) ? 1 : -1;
-      if (frame1 < frame2)
-        return invert * -1;
-      else
-        return invert;
-    }
-}
-
 static gpointer
 animation_renderer_process_queue (AnimationRenderer *renderer)
 {
@@ -381,7 +354,7 @@ on_frames_changed (Animation         *animation,
       g_async_queue_remove (renderer->priv->queue, GINT_TO_POINTER (i + 1));
       g_async_queue_push_sorted (renderer->priv->queue,
                                  GINT_TO_POINTER (i + 1),
-                                 (GCompareDataFunc) animation_renderer_sort_frame,
+                                 (GCompareDataFunc) compare_int_from,
                                  /* TODO: right now I am sorting the render
                                   * queue in common order. I will have to test
                                   * sorting it from the current position.
diff --git a/plug-ins/animation-play/widgets/animation-xsheet.c 
b/plug-ins/animation-play/widgets/animation-xsheet.c
index e1aae8a..9fc58bb 100755
--- a/plug-ins/animation-play/widgets/animation-xsheet.c
+++ b/plug-ins/animation-play/widgets/animation-xsheet.c
@@ -203,7 +203,8 @@ static void     on_track_right_clicked               (GtkToolButton   *toolbutto
 /* Utils */
 static void     animation_xsheet_rename_cel          (AnimationXSheet *xsheet,
                                                       GtkWidget       *cel,
-                                                      gboolean         recursively);
+                                                      gboolean         recursively,
+                                                      gint             stop_position);
 static void     animation_xsheet_jump                (AnimationXSheet *xsheet,
                                                       gint             position);
 static void     animation_xsheet_attach_cel          (AnimationXSheet *xsheet,
@@ -626,7 +627,7 @@ animation_xsheet_add_track (AnimationXSheet *xsheet,
       cel = gtk_toggle_button_new ();
       track->data = g_list_append (track->data, cel);
       animation_xsheet_attach_cel (xsheet, cel, level, i);
-      animation_xsheet_rename_cel (xsheet, cel, FALSE);
+      animation_xsheet_rename_cel (xsheet, cel, FALSE, -1);
 
       g_signal_connect (cel, "button-release-event",
                         G_CALLBACK (animation_xsheet_cel_clicked),
@@ -705,7 +706,7 @@ animation_xsheet_add_frames (AnimationXSheet *xsheet,
           cel = gtk_toggle_button_new ();
           iter->data = g_list_append (iter->data, cel);
           animation_xsheet_attach_cel (xsheet, cel, j, i);
-          animation_xsheet_rename_cel (xsheet, cel, FALSE);
+          animation_xsheet_rename_cel (xsheet, cel, FALSE, -1);
 
           g_signal_connect (cel, "button-release-event",
                             G_CALLBACK (animation_xsheet_cel_clicked),
@@ -1187,6 +1188,7 @@ on_layer_selection (AnimationLayerView *view,
     return;
 
   frames = g_queue_copy (xsheet->priv->selected_frames);
+  g_queue_sort (frames, compare_int_from, 0);
   while (! g_queue_is_empty (frames))
     {
       GList     *track_cels;
@@ -1204,7 +1206,8 @@ on_layer_selection (AnimationLayerView *view,
                                           GPOINTER_TO_INT (position),
                                           layers);
 
-      animation_xsheet_rename_cel (xsheet, button, TRUE);
+      animation_xsheet_rename_cel (xsheet, button, TRUE,
+                                   GPOINTER_TO_INT (g_queue_peek_head (frames)));
     }
   g_queue_free (frames);
 }
@@ -1461,7 +1464,7 @@ animation_xsheet_suite_do (GtkWidget       *button,
   cels = g_list_nth_data (xsheet->priv->cels, level);
   cel = g_list_nth_data (cels, position);
 
-  animation_xsheet_rename_cel (xsheet, cel, TRUE);
+  animation_xsheet_rename_cel (xsheet, cel, TRUE, -1);
 
   /* Delete the widget. */
   animation_xsheet_suite_cancelled (NULL, xsheet);
@@ -1802,7 +1805,7 @@ animation_xsheet_track_title_updated (GtkEntryBuffer  *buffer,
       GtkWidget *cel;
 
       cel = iter->data;
-      animation_xsheet_rename_cel (xsheet, cel, FALSE);
+      animation_xsheet_rename_cel (xsheet, cel, FALSE, -1);
     }
 }
 
@@ -1923,7 +1926,8 @@ on_track_right_clicked (GtkToolButton   *button,
 static void
 animation_xsheet_rename_cel (AnimationXSheet *xsheet,
                              GtkWidget       *cel,
-                             gboolean         recursively)
+                             gboolean         recursively,
+                             gint             stop_position)
 {
   const GList *layers;
   const GList *prev_layers = NULL;
@@ -1995,7 +1999,7 @@ animation_xsheet_rename_cel (AnimationXSheet *xsheet,
                                               GPOINTER_TO_INT (track_num),
                                               GPOINTER_TO_INT (position),
                                               NULL);
-          animation_xsheet_rename_cel (xsheet, cel, recursively);
+          animation_xsheet_rename_cel (xsheet, cel, recursively, stop_position);
           return;
         }
       else
@@ -2047,7 +2051,8 @@ animation_xsheet_rename_cel (AnimationXSheet *xsheet,
       g_free (markup);
     }
 
-  if (recursively)
+  if (recursively &&
+      GPOINTER_TO_INT (position) + 1 != stop_position)
     {
       GList     *track_cels;
       GtkWidget *next_cel;
@@ -2058,7 +2063,8 @@ animation_xsheet_rename_cel (AnimationXSheet *xsheet,
                                   GPOINTER_TO_INT (position) + 1);
       if (next_cel)
         {
-          animation_xsheet_rename_cel (xsheet, next_cel, TRUE);
+          animation_xsheet_rename_cel (xsheet, next_cel, TRUE,
+                                       stop_position);
         }
     }
 }


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