Hi,

While debugging some awt gtk+ peer issues I noticed that we always route
repaint events through 2 queues. First we create a Timer and put it in
there. Second we put it in the actual system event queue. If the repaint
is requested immediately that is overkill. And looking at a couple of
sample programs it looks like delayed repaints are not that often
requested at all. So this patch defers the creation of the Timer till
the first time a delayed repaint request is actually made. And it
immediately posts the repaint event to the system event queue if no
delay is asked for.

2006-02-09  Mark Wielaard  <[EMAIL PROTECTED]>

    * gnu/java/awt/peer/gtk/GtkComponentPeer.java (repaintTimer):
    Removed field.
    (repaint): Immediately post to queue when tm <= 0, otherwise call
    RepaintTimerTask.schedule().
    (RepaintTimerTask): Make static.
    (RepaintTimerTask.repaintTimer): New static final field.
    (RepaintTimerTask.awtComponent): New field.
    (schedule): New static method.

OK to commit?

Cheers,

Mark
Index: gnu/java/awt/peer/gtk/GtkComponentPeer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java,v
retrieving revision 1.101
diff -u -r1.101 GtkComponentPeer.java
--- gnu/java/awt/peer/gtk/GtkComponentPeer.java	9 Feb 2006 17:44:30 -0000	1.101
+++ gnu/java/awt/peer/gtk/GtkComponentPeer.java	9 Feb 2006 23:29:38 -0000
@@ -1,5 +1,6 @@
 /* GtkComponentPeer.java -- Implements ComponentPeer with GTK
-   Copyright (C) 1998, 1999, 2002, 2004, 2005  Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2002, 2004, 2005, 2006
+   Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -87,8 +88,6 @@
 
   boolean isInRepaint;
 
-  static final Timer repaintTimer = new Timer (true);
-
   /* this isEnabled differs from Component.isEnabled, in that it
      knows if a parent is disabled.  In that case Component.isEnabled 
      may return true, but our isEnabled will always return false */
@@ -383,19 +389,32 @@
     if (x == 0 && y == 0 && width == 0 && height == 0)
       return;
 
-    repaintTimer.schedule(new RepaintTimerTask(x, y, width, height), tm);
+    System.err.println("UPDATE: " + awtComponent);
+    Thread.dumpStack();
+    if (tm <= 0)
+      q().postEvent(new PaintEvent(awtComponent, PaintEvent.UPDATE,
+				   new Rectangle(x, y, width, height)));
+    else
+      RepaintTimerTask.schedule(tm, x, y, width, height, awtComponent);
   }
 
-  private class RepaintTimerTask extends TimerTask
+  /**
+   * Used for scheduling delayed paint updates on the event queue.
+   */
+  private static class RepaintTimerTask extends TimerTask
   {
+    private static final Timer repaintTimer = new Timer(true);
+
     private int x, y, width, height;
+    private Component awtComponent;
 
-    RepaintTimerTask(int x, int y, int width, int height)
+    RepaintTimerTask(Component c, int x, int y, int width, int height)
     {
       this.x = x;
       this.y = y;
       this.width = width;
       this.height = height;
+      this.awtComponent = c;
     }
 
     public void run()
@@ -403,6 +422,12 @@
       q().postEvent (new PaintEvent (awtComponent, PaintEvent.UPDATE,
                                      new Rectangle (x, y, width, height)));
     }
+
+    static void schedule(long tm, int x, int y, int width, int height,
+			 Component c)
+    {
+      repaintTimer.schedule(new RepaintTimerTask(c, x, y, width, height), tm);
+    }
   }
 
   public void requestFocus ()

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to