This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Change to coalescePaintEvents method's heuristics


Here is a patch which changes the heuristics of coalescePaintEvents
method in java.awt.Component class.  The following is a rather
long-winded explanation for the patch:

The old heuristics dictated that two paint areas will be merged if the
union of the areas is less than twice that of the sum of the areas. 
This has the side-effect of repainting regions that were not originally
intended to be repainted, as illustrated below:

+----+                                +---------+
|    |                                |     ####|
|    +----+    will be merged into    |         |
+----|    |                           |         |
     |    |                           |####     |
     +----+                           +---------+

In the diagram above, # denotes areas not originally intended to be
repainted.  In the case that we are repainting a Container, if any
heavyweight components exist in the areas denoted by #, they would be
over-painted with the Container's background color and would not be
repainted again.

We could introduce a mechanism to explicitly and forcefully repaint the
erased heavyweight components, but that seems like a hack to me.  (I
could be wrong on this.  Comments are welcome.)

Instead, I propose that we change the heuristics so it only merges the
two areas if the union of the areas is less than or equal to the sum of
the areas.  This ensures that we only repaint areas that were originally
intended to be repainted.

This heuristic change should be a temporary solution.  In the future, we
should implement a complex and efficient repaint area object (like Sun's
RepaintArea) that will allow us to coalesce paint areas into
non-rectangular shapes.  For public references to Sun's RepaintArea
object, see:
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Component.html#coalesceEvents(java.awt.AWTEvent,%20java.awt.AWTEvent)
http://java.sun.com/j2se/1.3/docs/guide/awt/enhancements.html#coalescing

Please let me know if my ideas and approach are way off base.

-David Jee


2004-01-19  David Jee  <djee@redhat.com>

        * java/awt/Component.java
        (coalescePaintEvents): Change heuristics to merge if the union
        of the areas is less than or equal to the sum of the areas.

Index: java/awt/Component.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Component.java,v
retrieving revision 1.31
diff -u -r1.31 Component.java
--- java/awt/Component.java	12 Nov 2003 22:03:49 -0000	1.31
+++ java/awt/Component.java	16 Jan 2004 22:24:46 -0000
@@ -4172,27 +4172,29 @@
 
   /**
    * Coalesce paint events. Current heuristic is: Merge if the union of
-   * areas is less than twice that of the sum of the areas. The X server
+   * areas is less than or equal to the sum of the areas. The X server
    * tend to create a lot of paint events that are adjacent but not
    * overlapping.
    *
    * <pre>
+   * +------+-----+
+   * |      |     |  ...will be merged
+   * |      |     |
+   * |      |     |
+   * +------+-----+
+   *
    * +------+
-   * |      +-----+  ...will be merged
+   * |      +-----+  ...will not be merged
    * |      |     |
    * |      |     |
    * +------+     |
    *        +-----+
    *
-   * +---------------+--+
-   * |               |  |  ...will not be merged
-   * +---------------+  |
-   *                 |  |
-   *                 |  |
-   *                 |  |
-   *                 |  |
-   *                 |  |
-   *                 +--+
+   * +------+  +-----+
+   * |      |  |     |  ...will not be merged
+   * |      |  |     |
+   * |      |  |     |
+   * +------+  +-----+
    * </pre>
    *
    * @param queuedEvent the first paint event
@@ -4210,10 +4212,13 @@
     int r2a = r2.width * r2.height;
     int ua  = union.width * union.height;
 
-    if (ua > (r1a+r2a)*2)
+    // FIXME: As the javadocs comments illustrate, we only merge
+    // the two areas if the they are adjacent and if they form a
+    // rectangle when joined.
+    // In the future, we should implement non-rectangular repaint
+    // areas, which were added to Sun's Java 2 SDK v1.3.
+    if (ua > r1a+r2a)
       return null;
-    /* The 2 factor should maybe be reconsidered. Perhaps 3/2
-       would be better? */
 
     newEvent.setUpdateRect(union);
     return newEvent;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]