[gimp/wip/animation: 342/373] plug-ins: prevent too much computation on constant camera update.



commit 4fb5d6966717f1ff4ea81ce0aca4a3794330e3a7
Author: Jehan <jehan girinstud io>
Date:   Mon Jun 26 01:46:29 2017 +0200

    plug-ins: prevent too much computation on constant camera update.
    
    If we are updating the camera in the GUI with spin buttons or mouse
    scroll, it will likely create a lot of events, hence useless
    re-computations. Add a timeout constantly postponed when updating in
    order to prevent this.

 .../widgets/animation-keyframe-view.c              |   55 ++++++++++++++++----
 1 files changed, 45 insertions(+), 10 deletions(-)
---
diff --git a/plug-ins/animation-play/widgets/animation-keyframe-view.c 
b/plug-ins/animation-play/widgets/animation-keyframe-view.c
index 4424678..6ff661a 100644
--- a/plug-ins/animation-play/widgets/animation-keyframe-view.c
+++ b/plug-ins/animation-play/widgets/animation-keyframe-view.c
@@ -37,17 +37,23 @@ struct _AnimationKeyFrameViewPrivate
   gint             position;
 
   GtkWidget       *offset_entry;
+
+  guint            update_source;
+  gint             update_x_offset;
+  gint             update_y_offset;
+  gint             update_position;
 };
 
 /* GObject handlers */
-static void animation_keyframe_view_constructed  (GObject               *object);
+static void     animation_keyframe_view_constructed  (GObject               *object);
 
-static void on_offset_entry_changed              (GimpSizeEntry         *entry,
-                                                  AnimationKeyFrameView *view);
-static void on_offsets_changed                   (AnimationCamera       *camera,
-                                                  gint                   position,
-                                                  gint                   duration,
-                                                  AnimationKeyFrameView *view);
+static gboolean animation_keyframe_update_source     (gpointer               user_data);
+static void     on_offset_entry_changed              (GimpSizeEntry         *entry,
+                                                      AnimationKeyFrameView *view);
+static void     on_offsets_changed                   (AnimationCamera       *camera,
+                                                      gint                   position,
+                                                      gint                   duration,
+                                                      AnimationKeyFrameView *view);
 
 G_DEFINE_TYPE (AnimationKeyFrameView, animation_keyframe_view, GTK_TYPE_NOTEBOOK)
 
@@ -198,6 +204,19 @@ animation_keyframe_view_constructed (GObject *object)
   gtk_widget_show (page);
 }
 
+static gboolean
+animation_keyframe_update_source (gpointer user_data)
+{
+  AnimationKeyFrameView *view = user_data;
+
+  view->priv->update_source = 0;
+  animation_camera_set_keyframe (view->priv->camera,
+                                 view->priv->update_position,
+                                 view->priv->update_x_offset,
+                                 view->priv->update_y_offset);
+  return G_SOURCE_REMOVE;
+}
+
 static void
 on_offset_entry_changed (GimpSizeEntry         *entry,
                          AnimationKeyFrameView *view)
@@ -205,11 +224,27 @@ on_offset_entry_changed (GimpSizeEntry         *entry,
   gdouble x_offset;
   gdouble y_offset;
 
+  /* If a timeout is pending, remove then recreate it in order to
+   * postpone the camera update. */
+  if (view->priv->update_source)
+    {
+      g_source_remove (view->priv->update_source);
+      if (view->priv->position != view->priv->update_position)
+        {
+          /* Do not postpone the update for another position. */
+          animation_camera_set_keyframe (view->priv->camera,
+                                         view->priv->update_position,
+                                         view->priv->update_x_offset,
+                                         view->priv->update_y_offset);
+        }
+    }
+
   x_offset = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (view->priv->offset_entry), 0);
   y_offset = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (view->priv->offset_entry), 1);
-  animation_camera_set_keyframe (view->priv->camera,
-                                 view->priv->position,
-                                 (gint) x_offset, (gint) y_offset);
+  view->priv->update_x_offset = x_offset;
+  view->priv->update_y_offset = y_offset;
+  view->priv->update_position = view->priv->position;
+  view->priv->update_source = g_timeout_add (100, animation_keyframe_update_source, view);
 }
 
 static void


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