< prev index next >

src/java.desktop/windows/classes/sun/awt/windows/TranslucentWindowPainter.java

Print this page

        

@@ -24,22 +24,25 @@
  */
 package sun.awt.windows;
 
 import java.awt.AlphaComposite;
 import java.awt.Color;
+import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.GraphicsConfiguration;
 import java.awt.Image;
 import java.awt.Window;
+import java.awt.geom.AffineTransform;
 import java.awt.image.BufferedImage;
 import java.awt.image.DataBufferInt;
 import java.awt.image.VolatileImage;
 import java.security.AccessController;
 import sun.awt.image.BufImgSurfaceData;
 import sun.java2d.DestSurfaceProvider;
 import sun.java2d.InvalidPipeException;
 import sun.java2d.Surface;
+import sun.java2d.pipe.Region;
 import sun.java2d.pipe.RenderQueue;
 import sun.java2d.pipe.BufferedContext;
 import sun.java2d.pipe.hw.AccelGraphicsConfig;
 import sun.java2d.pipe.hw.AccelSurface;
 import sun.security.action.GetPropertyAction;

@@ -115,10 +118,16 @@
      * The image can not be null, and NPE will be thrown if it is.
      */
     protected abstract boolean update(Image bb);
 
     /**
+     * Create (if needed), clears back buffer (if requested) and return
+     * graphics for this class depending upon the buffer type
+     */
+    protected abstract Graphics getGraphics(boolean clear);
+
+    /**
      * Flushes the resources associated with the painter. They will be
      * recreated as needed.
      */
     public abstract void flush();
 

@@ -128,25 +137,23 @@
      * @param repaint indicates if the window should be completely repainted
      * to the back buffer using {@link java.awt.Window#paintAll} before update.
      */
     public void updateWindow(boolean repaint) {
         boolean done = false;
-        Image bb = getBackBuffer(repaint);
         while (!done) {
             if (repaint) {
-                Graphics2D g = (Graphics2D)bb.getGraphics();
+                Graphics2D g = (Graphics2D) getGraphics(repaint);
                 try {
                     window.paintAll(g);
                 } finally {
                     g.dispose();
                 }
             }
 
-            done = update(bb);
+            done = update(getBackBuffer(false));
             if (!done) {
                 repaint = true;
-                bb = getBackBuffer(true);
             }
         }
     }
 
     private static final Image clearImage(Image bb) {

@@ -176,12 +183,16 @@
             super(peer);
         }
 
         @Override
         protected Image getBackBuffer(boolean clear) {
-            int w = window.getWidth();
-            int h = window.getHeight();
+            GraphicsConfiguration gc = peer.getGraphicsConfiguration();
+            AffineTransform transform = gc.getDefaultTransform();
+            int w = Region.clipRound(
+                    window.getWidth() * transform.getScaleX());
+            int h = Region.clipRound(
+                    window.getHeight() * transform.getScaleY());
             if (backBuffer == null ||
                 backBuffer.getWidth() != w ||
                 backBuffer.getHeight() != h)
             {
                 flush();

@@ -234,10 +245,23 @@
             if (backBuffer != null) {
                 backBuffer.flush();
                 backBuffer = null;
             }
         }
+
+        @Override
+        protected Graphics getGraphics(boolean clear) {
+            Graphics g = getBackBuffer(clear).getGraphics();
+            /*
+            This graphics object returned by BuffereImage is not scaled to
+            graphics configuration, but this graphics object can be used by
+            components inside this TranslucentWindow. So need to scale this
+            before returning.
+             */
+            ((Graphics2D)g).transform(peer.getGraphicsConfiguration().getDefaultTransform());
+            return g;
+        }
     }
 
     /**
      * A version of the painter which uses VolatileImage as the internal buffer.
      * The window is painted into this VI and then copied into the parent's

@@ -281,10 +305,15 @@
             if (viBB != null) {
                 viBB.flush();
                 viBB = null;
             }
         }
+
+        @Override
+        protected Graphics getGraphics(boolean clear) {
+            return getBackBuffer(clear).getGraphics();
+        }
     }
 
     /**
      * Optimized version of hw painter. Uses VolatileImages for the
      * buffer, and uses an optimized path to pull the data from those into
< prev index next >