8164811: [hidpi]Tests fail with OpenGL and GDI Rendering 8189257: Enabling Translucent Frame with setBackground disables HiDPI
authorpbansal
Fri, 10 Nov 2017 12:37:02 +0530
changeset 47831 26ff2d9a753b
parent 47830 fd3c961a89ec
child 47832 4182b3b158e0
8164811: [hidpi]Tests fail with OpenGL and GDI Rendering 8189257: Enabling Translucent Frame with setBackground disables HiDPI Reviewed-by: serb, prr, pnarayanan Contributed-by: pankaj.b.bansal@oracle.com
src/java.desktop/windows/classes/sun/awt/windows/TranslucentWindowPainter.java
src/java.desktop/windows/classes/sun/awt/windows/WWindowPeer.java
test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/PerPixelTranslucent.java
test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/PerPixelTranslucentGradient.java
test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/PerPixelTranslucentSwing.java
test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/ShapedPerPixelTranslucentGradient.java
test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/ShapedTranslucentPerPixelTranslucentGradient.java
test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/TranslucentPerPixelTranslucentGradient.java
--- a/src/java.desktop/windows/classes/sun/awt/windows/TranslucentWindowPainter.java	Thu Nov 09 14:19:31 2017 -0800
+++ b/src/java.desktop/windows/classes/sun/awt/windows/TranslucentWindowPainter.java	Fri Nov 10 12:37:02 2017 +0530
@@ -26,10 +26,12 @@
 
 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;
@@ -38,6 +40,7 @@
 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;
@@ -117,6 +120,12 @@
     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.
      */
@@ -130,10 +139,9 @@
      */
     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 {
@@ -141,10 +149,9 @@
                 }
             }
 
-            done = update(bb);
+            done = update(getBackBuffer(false));
             if (!done) {
                 repaint = true;
-                bb = getBackBuffer(true);
             }
         }
     }
@@ -178,8 +185,12 @@
 
         @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)
@@ -236,6 +247,19 @@
                 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;
+        }
     }
 
     /**
@@ -283,6 +307,11 @@
                 viBB = null;
             }
         }
+
+        @Override
+        protected Graphics getGraphics(boolean clear) {
+            return getBackBuffer(clear).getGraphics();
+        }
     }
 
     /**
--- a/src/java.desktop/windows/classes/sun/awt/windows/WWindowPeer.java	Thu Nov 09 14:19:31 2017 -0800
+++ b/src/java.desktop/windows/classes/sun/awt/windows/WWindowPeer.java	Fri Nov 10 12:37:02 2017 +0530
@@ -717,7 +717,7 @@
 
     public final Graphics getTranslucentGraphics() {
         synchronized (getStateLock()) {
-            return isOpaque ? null : painter.getBackBuffer(false).getGraphics();
+            return isOpaque ? null : painter.getGraphics(false);
         }
     }
 
--- a/test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/PerPixelTranslucent.java	Thu Nov 09 14:19:31 2017 -0800
+++ b/test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/PerPixelTranslucent.java	Fri Nov 10 12:37:02 2017 +0530
@@ -25,6 +25,7 @@
 
 /*
  * @test
+ * @bug 8164811
  * @key headful
  * @summary Check if a per-pixel translucent window is dragged and resized
  *          by mouse correctly.
@@ -42,6 +43,7 @@
  * @library ../../../../lib/testlibrary
  * @build Common ExtendedRobot
  * @run main PerPixelTranslucent
+ * @run main/othervm -Dsun.java2d.uiScale=1.5 PerPixelTranslucent
  */
 
 public class PerPixelTranslucent extends Common {
--- a/test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/PerPixelTranslucentGradient.java	Thu Nov 09 14:19:31 2017 -0800
+++ b/test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/PerPixelTranslucentGradient.java	Fri Nov 10 12:37:02 2017 +0530
@@ -26,7 +26,7 @@
 /*
  * @test
  * @key headful
- * @bug 8032644
+ * @bug 8032644 8164811
  * @summary Check if a per-pixel translucent window is dragged and resized by
  *          mouse correctly
  * Test Description: Check if PERPIXEL_TRANSLUCENT translucency type is supported
@@ -44,6 +44,7 @@
  * @library ../../../../lib/testlibrary
  * @build Common ExtendedRobot
  * @run main PerPixelTranslucentGradient
+ * @run main/othervm -Dsun.java2d.uiScale=1.5 PerPixelTranslucentGradient
  */
 
 public class PerPixelTranslucentGradient extends Common {
--- a/test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/PerPixelTranslucentSwing.java	Thu Nov 09 14:19:31 2017 -0800
+++ b/test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/PerPixelTranslucentSwing.java	Fri Nov 10 12:37:02 2017 +0530
@@ -26,6 +26,7 @@
 
 /*
  * @test
+ * @bug 8164811
  * @key headful
  * @summary Check if a per-pixel translucent window shows only the area having
  *          opaque pixels
@@ -40,6 +41,7 @@
  * @library ../../../../lib/testlibrary
  * @build Common ExtendedRobot
  * @run main PerPixelTranslucentSwing
+ * @run main/othervm -Dsun.java2d.uiScale=1.5 PerPixelTranslucentSwing
  */
 
 public class PerPixelTranslucentSwing extends Common {
--- a/test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/ShapedPerPixelTranslucentGradient.java	Thu Nov 09 14:19:31 2017 -0800
+++ b/test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/ShapedPerPixelTranslucentGradient.java	Fri Nov 10 12:37:02 2017 +0530
@@ -26,7 +26,7 @@
 /*
  * @test
  * @key headful
- * @bug 7043845
+ * @bug 7043845 8164811
  * @summary Check if shaped and per-pixel translucent window is dragged and
  *          resized by mouse correctly.
  * Test Description: Check if PERPIXEL_TRANSLUCENT and PERPIXEL_TRANSPARENT
@@ -48,6 +48,7 @@
  * @library ../../../../lib/testlibrary
  * @build Common ExtendedRobot
  * @run main ShapedPerPixelTranslucentGradient
+ * @run main/othervm -Dsun.java2d.uiScale=1.5 ShapedPerPixelTranslucentGradient
  */
 
 public class ShapedPerPixelTranslucentGradient extends Common {
--- a/test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/ShapedTranslucentPerPixelTranslucentGradient.java	Thu Nov 09 14:19:31 2017 -0800
+++ b/test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/ShapedTranslucentPerPixelTranslucentGradient.java	Fri Nov 10 12:37:02 2017 +0530
@@ -25,6 +25,7 @@
 
 /*
  * @test
+ * @bug 8164811
  * @key headful
  * @summary Check if shaped, translucent and per-pixel translucent window is
  *          dragged and resized by mouse correctly.
@@ -48,6 +49,7 @@
  * @library ../../../../lib/testlibrary
  * @build Common ExtendedRobot
  * @run main ShapedTranslucentPerPixelTranslucentGradient
+ * @run main/othervm -Dsun.java2d.uiScale=1.5 ShapedTranslucentPerPixelTranslucentGradient
  */
 
 public class ShapedTranslucentPerPixelTranslucentGradient extends Common {
--- a/test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/TranslucentPerPixelTranslucentGradient.java	Thu Nov 09 14:19:31 2017 -0800
+++ b/test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/TranslucentPerPixelTranslucentGradient.java	Fri Nov 10 12:37:02 2017 +0530
@@ -25,7 +25,7 @@
 
 /*
  * @test
- * @bug 8144735
+ * @bug 8144735 8164811
  * @key headful
  * @summary Check if a per-pixel translucent and translucent window is dragged
  *          and resized by mouse correctly
@@ -46,6 +46,7 @@
  * @library ../../../../lib/testlibrary
  * @build Common ExtendedRobot
  * @run main TranslucentPerPixelTranslucentGradient
+ * @run main/othervm -Dsun.java2d.uiScale=1.5 TranslucentPerPixelTranslucentGradient
  */
 
 public class TranslucentPerPixelTranslucentGradient extends Common {