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 volatileBufferType;
+    /**
      * 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()) {
+            volatileBufferType = Transparency.TRANSLUCENT;
+        } else {
+            volatileBufferType = 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,
+                                                         volatileBufferType);
             volatileMap.put(config, image);
         }
         return image;
     }
 

@@ -1481,13 +1494,30 @@
             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 (volatileBufferType != Transparency.OPAQUE
+                                && osg instanceof Graphics2D) {
+                            final Graphics2D g2d = (Graphics2D) osg;
+                            final Color oldBg = g2d.getBackground();
+                            g2d.setBackground(c.getBackground());
+                            g2d.clearRect(x, y, bw, bh);
+                            g2d.setBackground(oldBg);
+                        }
                         c.paintToOffscreen(osg, x, y, bw, bh, maxx, maxy);
                         g.setClip(x, y, bw, bh);
+                        if (volatileBufferType != Transparency.OPAQUE
+                                && g instanceof Graphics2D) {
+                            final Graphics2D g2d = (Graphics2D) g;
+                            final Composite oldComposite = g2d.getComposite();
+                            g2d.setComposite(AlphaComposite.Src);
+                            g2d.drawImage(image, x, y, c);
+                            g2d.setComposite(oldComposite);
+                        } else {
                         g.drawImage(image, x, y, c);
+                        }
                         osg.translate(x, y);
                     }
                 }
             } finally {
                 osg.dispose();