[gimp] Limit the draw tool's redraw framerate to about 29 FPS using a timeout



commit 08193e8b56ac85837200af5c3ff7a57f9eb5a209
Author: Michael Natterer <mitch gimp org>
Date:   Fri Mar 19 21:08:41 2010 +0100

    Limit the draw tool's redraw framerate to about 29 FPS using a timeout

 app/tools/gimpdrawtool.c |   41 +++++++++++++++++++++++++++++++++++++++--
 app/tools/gimpdrawtool.h |    5 +++--
 2 files changed, 42 insertions(+), 4 deletions(-)
---
diff --git a/app/tools/gimpdrawtool.c b/app/tools/gimpdrawtool.c
index e9ee01e..1075c8f 100644
--- a/app/tools/gimpdrawtool.c
+++ b/app/tools/gimpdrawtool.c
@@ -42,6 +42,10 @@
 #include "gimpdrawtool.h"
 
 
+#define DRAW_TIMEOUT 35 /* ~29 FPS */
+#define USE_TIMEOUT  1
+
+
 static gboolean      gimp_draw_tool_has_display  (GimpTool       *tool,
                                                   GimpDisplay    *display);
 static GimpDisplay * gimp_draw_tool_has_image    (GimpTool       *tool,
@@ -154,10 +158,22 @@ gimp_draw_tool_control (GimpTool       *tool,
   GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
 }
 
+static gboolean
+gimp_draw_tool_draw_timeout (GimpDrawTool *draw_tool)
+{
+  draw_tool->draw_timeout = 0;
+
+  gimp_draw_tool_draw (draw_tool);
+
+  return FALSE;
+}
+
 static void
 gimp_draw_tool_draw (GimpDrawTool *draw_tool)
 {
-  if (draw_tool->paused_count == 0 && draw_tool->display)
+  if (! draw_tool->draw_timeout    &&
+      draw_tool->paused_count == 0 &&
+      draw_tool->display)
     {
       GIMP_DRAW_TOOL_GET_CLASS (draw_tool)->draw (draw_tool);
 
@@ -192,6 +208,12 @@ gimp_draw_tool_stop (GimpDrawTool *draw_tool)
 
   gimp_draw_tool_draw (draw_tool);
 
+  if (draw_tool->draw_timeout)
+    {
+      g_source_remove (draw_tool->draw_timeout);
+      draw_tool->draw_timeout = 0;
+    }
+
   draw_tool->display = NULL;
 }
 
@@ -211,6 +233,12 @@ gimp_draw_tool_pause (GimpDrawTool *draw_tool)
   gimp_draw_tool_draw (draw_tool);
 
   draw_tool->paused_count++;
+
+  if (draw_tool->draw_timeout)
+    {
+      g_source_remove (draw_tool->draw_timeout);
+      draw_tool->draw_timeout = 0;
+    }
 }
 
 void
@@ -222,7 +250,16 @@ gimp_draw_tool_resume (GimpDrawTool *draw_tool)
     {
       draw_tool->paused_count--;
 
-      gimp_draw_tool_draw (draw_tool);
+#ifdef USE_TIMEOUT
+      if (! draw_tool->draw_timeout)
+        draw_tool->draw_timeout =
+          gdk_threads_add_timeout_full (G_PRIORITY_HIGH,
+                                        DRAW_TIMEOUT,
+                                        (GSourceFunc) gimp_draw_tool_draw_timeout,
+                                        draw_tool, NULL);
+#else
+  gimp_draw_tool_draw (draw_tool);
+#endif
     }
   else
     {
diff --git a/app/tools/gimpdrawtool.h b/app/tools/gimpdrawtool.h
index 738caf6..0b7894b 100644
--- a/app/tools/gimpdrawtool.h
+++ b/app/tools/gimpdrawtool.h
@@ -50,8 +50,9 @@ struct _GimpDrawTool
                                  *  a different one than tool->display)
                                  */
 
-  gint            paused_count; /*  count to keep track of multiple pauses */
-  gboolean        is_drawn;     /*  is the stuff we draw currently visible */
+  gint            paused_count; /*  count to keep track of multiple pauses  */
+  gboolean        is_drawn;     /*  is the stuff we draw currently visible  */
+  guint           draw_timeout; /*  draw delay timeout ID                   */
 };
 
 struct _GimpDrawToolClass



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