summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-11-29 12:56:39 +0000
committerRoman Kennke <roman@kennke.org>2006-11-29 12:56:39 +0000
commit2f73ddf076a53a46a68920d1654cf8ec04c57798 (patch)
treee8334d005b733f07b0fe2ea0e25773fc0b85126d
parent6ca41bd8e0b635c95a9f5c2b5041cc84063e9978 (diff)
downloadclasspath-2f73ddf076a53a46a68920d1654cf8ec04c57798.tar.gz
2006-11-29 Roman Kennke <kennke@aicas.com>
* java/awt/Component.java (isShowing): Simplified condition code and avoid unnecessary if-codepaths. (coalesceEvents): Always coalesce paint events and let the peer figure out the expanding of the repaint area. * gnu/java/awt/peer/swing/SwingComponentPeer.java (currentPaintEvents): Removed. Replaced by paintArea. (paintArea): New field. Tracks the dirty area. (SwingComponentPeer): Removed init of currentPaintEvents. (coalescePaintEvent): Simplified to only union the dirty regions. (handleEvent): Paint dirty region that was tracked in paintArea. * gnu/java/awt/peer/gtk/GtkComponentPeer.java (paintArea): New field. Tracks the dirty region. (coalescePaintEvent): Implemented to track the dirty region. (paintComponent): Use the dirty region in paintArea. Protect state by putting the paint and dispose code in a try-finally. (updateComponent): Use the dirty region in paintArea. Protect state by putting the paint and dispose code in a try-finally.
-rw-r--r--ChangeLog21
-rw-r--r--gnu/java/awt/peer/gtk/GtkComponentPeer.java56
-rw-r--r--gnu/java/awt/peer/swing/SwingComponentPeer.java82
-rw-r--r--java/awt/Component.java11
4 files changed, 93 insertions, 77 deletions
diff --git a/ChangeLog b/ChangeLog
index ab7fcbc3e..7f00ee349 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,26 @@
2006-11-29 Roman Kennke <kennke@aicas.com>
+ * java/awt/Component.java
+ (isShowing): Simplified condition code and avoid unnecessary
+ if-codepaths.
+ (coalesceEvents): Always coalesce paint events and let the peer
+ figure out the expanding of the repaint area.
+ * gnu/java/awt/peer/swing/SwingComponentPeer.java
+ (currentPaintEvents): Removed. Replaced by paintArea.
+ (paintArea): New field. Tracks the dirty area.
+ (SwingComponentPeer): Removed init of currentPaintEvents.
+ (coalescePaintEvent): Simplified to only union the dirty regions.
+ (handleEvent): Paint dirty region that was tracked in paintArea.
+ * gnu/java/awt/peer/gtk/GtkComponentPeer.java
+ (paintArea): New field. Tracks the dirty region.
+ (coalescePaintEvent): Implemented to track the dirty region.
+ (paintComponent): Use the dirty region in paintArea. Protect
+ state by putting the paint and dispose code in a try-finally.
+ (updateComponent): Use the dirty region in paintArea. Protect
+ state by putting the paint and dispose code in a try-finally.
+
+2006-11-29 Roman Kennke <kennke@aicas.com>
+
* java/awt/font/TextLayout.java
(getVisualHighlightShape): Removed debug output.
diff --git a/gnu/java/awt/peer/gtk/GtkComponentPeer.java b/gnu/java/awt/peer/gtk/GtkComponentPeer.java
index f96033e56..f6bf588e9 100644
--- a/gnu/java/awt/peer/gtk/GtkComponentPeer.java
+++ b/gnu/java/awt/peer/gtk/GtkComponentPeer.java
@@ -90,6 +90,11 @@ public class GtkComponentPeer extends GtkGenericPeer
Insets insets;
+ /**
+ * The current repaint area.
+ */
+ protected Rectangle paintArea;
+
/* 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 */
@@ -308,13 +313,20 @@ public class GtkComponentPeer extends GtkGenericPeer
// seems expensive. However, the graphics state does not carry
// over between calls to paint, and resetting the graphics object
// may even be more costly than simply creating a new one.
- Graphics g = getGraphics();
-
- g.setClip(event.getUpdateRect());
-
- awtComponent.paint(g);
-
- g.dispose();
+ synchronized (paintArea)
+ {
+ Graphics g = getGraphics();
+ try
+ {
+ g.setClip(paintArea);
+ awtComponent.paint(g);
+ }
+ finally
+ {
+ g.dispose();
+ paintArea = null;
+ }
+ }
}
// This method and its overrides are the only methods in the peers
@@ -327,13 +339,20 @@ public class GtkComponentPeer extends GtkGenericPeer
|| (awtComponent.getWidth() < 1 || awtComponent.getHeight() < 1))
return;
- Graphics g = getGraphics();
-
- g.setClip(event.getUpdateRect());
-
- awtComponent.update(g);
-
- g.dispose();
+ synchronized (paintArea)
+ {
+ Graphics g = getGraphics();
+ try
+ {
+ g.setClip(paintArea);
+ awtComponent.update(g);
+ }
+ finally
+ {
+ g.dispose();
+ paintArea = null;
+ }
+ }
}
public boolean isFocusTraversable ()
@@ -754,7 +773,14 @@ public class GtkComponentPeer extends GtkGenericPeer
public void coalescePaintEvent (PaintEvent e)
{
-
+ synchronized (this)
+ {
+ Rectangle newRect = e.getUpdateRect();
+ if (paintArea == null)
+ paintArea = newRect;
+ else
+ Rectangle.union(paintArea, newRect, paintArea);
+ }
}
public void updateCursorImmediately ()
diff --git a/gnu/java/awt/peer/swing/SwingComponentPeer.java b/gnu/java/awt/peer/swing/SwingComponentPeer.java
index 7e1ad86a0..bfa14ddde 100644
--- a/gnu/java/awt/peer/swing/SwingComponentPeer.java
+++ b/gnu/java/awt/peer/swing/SwingComponentPeer.java
@@ -64,9 +64,6 @@ import java.awt.image.VolatileImage;
import java.awt.peer.ComponentPeer;
import java.awt.peer.ContainerPeer;
import java.awt.peer.LightweightPeer;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
import javax.swing.JComponent;
import javax.swing.RepaintManager;
@@ -83,7 +80,7 @@ import javax.swing.RepaintManager;
* This class also provides the necesary hooks into the Swing painting and
* event handling system. In order to achieve this, it traps paint, mouse and
* key events in {@link #handleEvent(AWTEvent)} and calls some special methods
- * ({@link #peerPaint(Graphics,boolean)}, {@link #handleKeyEvent(KeyEvent)},
+ * ({@link #peerPaint(Graphics)}, {@link #handleKeyEvent(KeyEvent)},
* {@link #handleMouseEvent(MouseEvent)} and
* {@link #handleMouseMotionEvent(MouseEvent)}) that call the corresponding
* Swing methods.
@@ -110,25 +107,18 @@ public class SwingComponentPeer
protected Font peerFont;
/**
- * The repaint requests that will be handled next. The events queued
- * up here are in the exact same order as they appear in
- * {@link #coalescePaintEvent(PaintEvent)}, that is in event queue order.
- * This is used for coalescing paint events.
- *
- * @see #coalescePaintEvent(PaintEvent)
+ * The current repaint area.
*/
- protected List currentPaintEvents;
+ protected Rectangle paintArea;
/**
* Creates a SwingComponentPeer instance. Subclasses are expected to call
- * this constructor and thereafter call {@link #init(Component,
- * SwingComponent)}in order to setup the AWT and Swing components properly.
+ * this constructor and thereafter call {@link #init(Component, JComponent)}
+ * in order to setup the AWT and Swing components properly.
*/
protected SwingComponentPeer()
{
- // Initialize paint event queue.
- currentPaintEvents = new LinkedList();
-
+ // Nothing to do here.
}
/**
@@ -412,24 +402,22 @@ public class SwingComponentPeer
// paint event list.
// We must synchronize on the tree lock first to avoid deadlock,
// because Container.paint() will grab it anyway.
- synchronized (awtComponent.getTreeLock())
+ synchronized (this)
{
- synchronized (currentPaintEvents)
+ assert paintArea != null;
+ if (awtComponent.isShowing())
{
- if (currentPaintEvents.contains(e))
+ Graphics g = awtComponent.getGraphics();
+ try
{
- Graphics g = awtComponent.getGraphics();
- try
- {
- Rectangle clip = ((PaintEvent) e).getUpdateRect();
- g.clipRect(clip.x, clip.y, clip.width, clip.height);
- peerPaint(g, e.getID() == PaintEvent.UPDATE);
- }
- finally
- {
- g.dispose();
- }
- currentPaintEvents.remove(e);
+ Rectangle clip = paintArea;
+ g.clipRect(clip.x, clip.y, clip.width, clip.height);
+ peerPaint(g, e.getID() == PaintEvent.UPDATE);
+ }
+ finally
+ {
+ g.dispose();
+ paintArea = null;
}
}
}
@@ -832,35 +820,13 @@ public class SwingComponentPeer
*/
public void coalescePaintEvent(PaintEvent e)
{
- synchronized (currentPaintEvents)
+ synchronized (this)
{
Rectangle newRect = e.getUpdateRect();
- boolean coalesced = false;
- for (Iterator i = currentPaintEvents.iterator(); i.hasNext() && ! coalesced;)
- {
- PaintEvent e2 = (PaintEvent) i.next();
- if (e.getID() == e2.getID())
- {
- Rectangle oldRect = e2.getUpdateRect();
- if (oldRect.contains(newRect))
- {
- // Merge newRect into oldRect. We have to discard the old request
- // so that the events are still in the correct order.
- i.remove();
- newRect.setBounds(oldRect);
- coalesced = true;
- }
- else if (newRect.contains(oldRect))
- {
- // Merge oldRect into newRect. We have to discard the old request
- // so that the events are still in the correct order.
- i.remove();
- coalesced = true;
- }
- }
- // TODO: Maybe do something more clever here.
- }
- currentPaintEvents.add(e);
+ if (paintArea == null)
+ paintArea = newRect;
+ else
+ Rectangle.union(paintArea, newRect, paintArea);
}
}
diff --git a/java/awt/Component.java b/java/awt/Component.java
index 992ac5fd0..380faf824 100644
--- a/java/awt/Component.java
+++ b/java/awt/Component.java
@@ -823,10 +823,7 @@ public abstract class Component
*/
public boolean isShowing()
{
- if (! visible || peer == null)
- return false;
-
- return parent == null ? false : parent.isShowing();
+ return visible && peer != null && (parent == null || parent.isShowing());
}
/**
@@ -3627,6 +3624,12 @@ public abstract class Component
else if (r2.contains(r1))
coalesced = newEvent;
}
+ else
+ {
+ // Replace the event and let the heavyweight figure out the expanding
+ // of the repaint area.
+ coalesced = newEvent;
+ }
break;
default:
coalesced = null;