This enables the use of VolatileImages as backbuffer for Swing. This
effectively solves the performance problems brought by the Java2D
rewrite.

2006-06-10  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/RepaintManager.java
        (getVolatileOffscreenBuffer): Store the created buffer.
        * javax/swing/JComponent.java
        (paintDoubleBuffered): Try to use a volatile offscreen buffer
        for better performance.


/Roman

-- 
“Improvement makes straight roads, but the crooked roads, without
Improvement, are roads of Genius.” - William Blake
Index: javax/swing/JComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JComponent.java,v
retrieving revision 1.124
diff -u -1 -0 -r1.124 JComponent.java
--- javax/swing/JComponent.java	9 Jun 2006 23:27:59 -0000	1.124
+++ javax/swing/JComponent.java	10 Jun 2006 08:00:46 -0000
@@ -2167,22 +2167,27 @@
   
   /**
    * Performs double buffered repainting.
    */
   private void paintDoubleBuffered(Rectangle r)
   {
     RepaintManager rm = RepaintManager.currentManager(this);
 
     // Paint on the offscreen buffer.
     Component root = getRoot(this);
-    Image buffer = rm.getOffscreenBuffer(this, root.getWidth(),
+    Image buffer = rm.getVolatileOffscreenBuffer(this, root.getWidth(),
                                                  root.getHeight());
+    // The volatile offscreen buffer may be null when that's not supported
+    // by the AWT backend. Fall back to normal backbuffer in this case.
+    if (buffer == null)
+      buffer = rm.getOffscreenBuffer(this, root.getWidth(), root.getHeight());
+
     //Rectangle targetClip = SwingUtilities.convertRectangle(this, r, root);
     Point translation = SwingUtilities.convertPoint(this, 0, 0, root);
     Graphics g2 = buffer.getGraphics();
     g2.translate(translation.x, translation.y);
     g2.setClip(r.x, r.y, r.width, r.height);
     g2 = getComponentGraphics(g2);
     isPaintingDoubleBuffered = true;
     try
       {
         paint(g2);
Index: javax/swing/RepaintManager.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/RepaintManager.java,v
retrieving revision 1.36
diff -u -1 -0 -r1.36 RepaintManager.java
--- javax/swing/RepaintManager.java	18 May 2006 14:17:52 -0000	1.36
+++ javax/swing/RepaintManager.java	10 Jun 2006 08:00:48 -0000
@@ -760,24 +760,36 @@
    * @param proposedWidth the proposed width of the buffer
    * @param proposedHeight the proposed height of the buffer
    *
    * @since 1.4
    *
    * @see VolatileImage
    */
   public Image getVolatileOffscreenBuffer(Component comp, int proposedWidth,
                                           int proposedHeight)
   {
-    int maxWidth = doubleBufferMaximumSize.width;
-    int maxHeight = doubleBufferMaximumSize.height;
-    return comp.createVolatileImage(Math.min(maxWidth, proposedWidth),
-                                    Math.min(maxHeight, proposedHeight));
+    Component root = getRoot(comp);
+    Image buffer = (Image) offscreenBuffers.get(root);
+    if (buffer == null 
+        || buffer.getWidth(null) < proposedWidth 
+        || buffer.getHeight(null) < proposedHeight
+        || !(buffer instanceof VolatileImage))
+      {
+        int width = Math.max(proposedWidth, root.getWidth());
+        width = Math.min(doubleBufferMaximumSize.width, width);
+        int height = Math.max(proposedHeight, root.getHeight());
+        height = Math.min(doubleBufferMaximumSize.height, height);
+        buffer = root.createVolatileImage(width, height);
+        if (buffer != null)
+          offscreenBuffers.put(root, buffer);
+      }
+    return buffer;
   }
   
 
   /**
    * Get the value of the [EMAIL PROTECTED] #doubleBufferMaximumSize} property.
    *
    * @return The current value of the property
    *
    * @see #setDoubleBufferMaximumSize
    */

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

Reply via email to