src/share/classes/javax/swing/RepaintManager.java

Print this page

        

@@ -117,10 +117,15 @@
     private static final Object repaintManagerKey = RepaintManager.class;
 
     // Whether or not a VolatileImage should be used for double-buffered painting
     static boolean volatileImageBufferEnabled = true;
     /**
+     * Type of VolatileImage which should be used for double-buffered
+     * painting.
+     */
+    private static final int doubleBufferType;
+    /**
      * Value of the system property awt.nativeDoubleBuffering.
      */
     private static boolean nativeDoubleBuffering;
 
     // The maximum number of times Swing will attempt to use the VolatileImage

@@ -202,10 +207,17 @@
                 getLocalGraphicsEnvironment();
         if (ge instanceof SunGraphicsEnvironment) {
             ((SunGraphicsEnvironment)ge).addDisplayChangedListener(
                     new DisplayChangedHandler());
         }
+        Toolkit tk = Toolkit.getDefaultToolkit();
+        if ((tk instanceof SunToolkit)
+                && ((SunToolkit) tk).isSwingBackbufferTranslucencySupported()) {
+            doubleBufferType = Transparency.TRANSLUCENT;
+        } else {
+            doubleBufferType = Transparency.OPAQUE;
+        }
     }
 
     /**
      * Return the RepaintManager for the calling thread given a Component.
      *

@@ -987,11 +999,12 @@
         if (image == null || image.getWidth() < width ||
                              image.getHeight() < height) {
             if (image != null) {
                 image.flush();
             }
-            image = config.createCompatibleVolatileImage(width, height);
+            image = config.createCompatibleVolatileImage(width, height,
+                                                         doubleBufferType);
             volatileMap.put(config, image);
         }
         return image;
     }
 

@@ -1481,13 +1494,28 @@
             try {
                 for(x = clipX, maxx = clipX+clipW; x < maxx ;  x += bw ) {
                     for(y=clipY, maxy = clipY + clipH; y < maxy ; y += bh) {
                         osg.translate(-x, -y);
                         osg.setClip(x,y,bw,bh);
+                        if (doubleBufferType != Transparency.OPAQUE
+                                && osg instanceof Graphics2D) {
+                            Graphics2D g2d = (Graphics2D) osg.create();
+                            g2d.setBackground(c.getBackground());
+                            g2d.clearRect(x, y, bw, bh);
+                            g2d.dispose();
+                        }
                         c.paintToOffscreen(osg, x, y, bw, bh, maxx, maxy);
                         g.setClip(x, y, bw, bh);
+                        if (doubleBufferType != Transparency.OPAQUE
+                                && osg instanceof Graphics2D) {
+                            Graphics2D g2d = (Graphics2D) g.create();
+                            g2d.setComposite(AlphaComposite.Src);
+                            g2d.drawImage(image, x, y, c);
+                            g2d.dispose();
+                        } else {
                         g.drawImage(image, x, y, c);
+                        }
                         osg.translate(x, y);
                     }
                 }
             } finally {
                 osg.dispose();