You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ap...@apache.org on 2006/11/21 17:46:06 UTC

svn commit: r477740 - /harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JComponent.java

Author: apetrenko
Date: Tue Nov 21 08:46:05 2006
New Revision: 477740

URL: http://svn.apache.org/viewvc?view=rev&rev=477740
Log:
Patch for HARMONY-2106 "[classlib][swing] Performance improvement for paintChildren method of JComponent"

Modified:
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JComponent.java

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JComponent.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JComponent.java?view=diff&rev=477740&r1=477739&r2=477740
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JComponent.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JComponent.java Tue Nov 21 08:46:05 2006
@@ -36,6 +36,7 @@
 import java.awt.LayoutManager2;
 import java.awt.Point;
 import java.awt.Rectangle;
+import java.awt.Shape;
 import java.awt.Window;
 import java.awt.dnd.DropTarget;
 import java.awt.event.ActionListener;
@@ -85,6 +86,7 @@
 import javax.swing.plaf.ComponentUI;
 
 import org.apache.harmony.awt.ClipRegion;
+import org.apache.harmony.awt.gl.MultiRectArea;
 import org.apache.harmony.x.swing.StringConstants;
 import org.apache.harmony.x.swing.Utilities;
 
@@ -873,21 +875,84 @@
     }
 
     protected void paintChildren(final Graphics graphics) {
-        for (int i = getComponentCount() - 1; i >= 0; i--) {
-            Component comp = getComponent(i);
-            if (comp.isVisible()) {
-                if (!comp.isLightweight()) {
-                    continue;
+        Rectangle clipBounds = graphics.getClipBounds();
+        if (clipBounds != null && clipBounds.isEmpty()) {
+            return;
+        }
+
+        int cc = getComponentCount();
+        if (!isOptimizedDrawingEnabled()) {
+            MultiRectArea childrenCoverage = null;
+            Component compList[] = new Component[cc];
+            Shape clipList[] = new Shape[cc];
+            int rc = -1;
+
+            for (int i = 0; i < cc; i++) {
+                Component comp = getComponent(i);
+                if (comp.isVisible()) {
+                    if (!comp.isLightweight()) {
+                        continue;
+                    }
+                    MultiRectArea clip;
+                    Rectangle bounds = comp.getBounds();
+                    if (childrenCoverage == null && comp.isOpaque()) {
+                        childrenCoverage = new MultiRectArea(bounds);
+                        clip = new MultiRectArea(bounds);
+                    } else {
+                        clip = new MultiRectArea(bounds);
+                        clip.substract(childrenCoverage);
+                        if (clip.isEmpty()) {
+                            continue;
+                        }
+                        if (comp.isOpaque()) {
+                            childrenCoverage = MultiRectArea.union(
+                                    childrenCoverage, clip);
+                        }
+                    }
+                    rc++;
+                    if (clipBounds != null) {
+                        clip.intersect(clipBounds);
+                    }
+                    clip.translate(-bounds.x, -bounds.y);
+                    compList[rc] = comp;
+                    clipList[rc] = clip;
                 }
+            }
+
+            while (rc >= 0) {
+                Component comp = compList[rc];
                 Graphics gComp = getChildJComponentGraphics(graphics, comp);
                 if (gComp != null) {
-                    Rectangle componentBounds = getComponentVisibleRect(comp, SwingUtilities.getLocalBounds(comp));
-                    gComp.clipRect(componentBounds.x, componentBounds.y, componentBounds.width, componentBounds.height);
-                    Rectangle clipBounds = gComp.getClipBounds();
-                    if (!clipBounds.isEmpty()) {
+                    ((Graphics2D) gComp).clip(clipList[rc]);
+                    if (!gComp.getClipBounds().isEmpty()) {
                         comp.paint(gComp);
                     }
                     gComp.dispose();
+                }
+                rc--;
+            }
+        } else {
+            for (int i = cc - 1; i >= 0; i--) {
+                Component comp = getComponent(i);
+                if (comp.isVisible()) {
+                    if (!comp.isLightweight()) {
+                        continue;
+                    }
+                    Graphics gComp = getChildJComponentGraphics(graphics, comp);
+                    if (gComp != null) {
+                        Rectangle bounds = comp.getBounds();
+                        int x = bounds.x;
+                        int y = bounds.y;
+                        if(clipBounds != null){
+                            bounds = bounds.intersection(clipBounds);
+                        }
+                        bounds.translate(-x, -y);
+                        gComp.clipRect(bounds.x, bounds.y, bounds.width, bounds.height);
+                        if (!gComp.getClipBounds().isEmpty()) {
+                            comp.paint(gComp);
+                        }
+                        gComp.dispose();
+                    }
                 }
             }
         }