8159142: [hidpi] Visible artifacts in sun/java2d/SunGraphics2D/DrawImageBilinear.java
authorpbansal
Wed, 22 Nov 2017 11:52:59 +0530
changeset 47967 b69b22b7a9f9
parent 47966 a5fe5534b8a2
child 47968 a42e805414e4
8159142: [hidpi] Visible artifacts in sun/java2d/SunGraphics2D/DrawImageBilinear.java Reviewed-by: serb, prr, pnarayanan Contributed-by: pankaj.b.bansal@oracle.com
src/java.desktop/share/classes/sun/awt/image/SunVolatileImage.java
src/java.desktop/windows/classes/sun/java2d/d3d/D3DSurfaceData.java
src/java.desktop/windows/classes/sun/java2d/opengl/WGLSurfaceData.java
src/java.desktop/windows/classes/sun/java2d/windows/GDIWindowSurfaceData.java
test/jdk/sun/java2d/SunGraphics2D/DrawImageBilinear.java
--- a/src/java.desktop/share/classes/sun/awt/image/SunVolatileImage.java	Tue Nov 21 13:39:25 2017 -0800
+++ b/src/java.desktop/share/classes/sun/awt/image/SunVolatileImage.java	Wed Nov 22 11:52:59 2017 +0530
@@ -40,6 +40,7 @@
 import sun.java2d.SurfaceManagerFactory;
 import sun.java2d.DestSurfaceProvider;
 import sun.java2d.Surface;
+import sun.java2d.pipe.Region;
 import static sun.java2d.pipe.hw.AccelSurface.*;
 
 /**
@@ -245,8 +246,8 @@
      * or a backup surface with the given horizontal and vertical scale factors.
      */
     public BufferedImage getBackupImage(double scaleX, double scaleY) {
-        int w = (int) Math.ceil(getWidth() * scaleX);
-        int h = (int) Math.ceil(getHeight() * scaleY);
+        int w = Region.clipRound(getWidth() * scaleX);
+        int h = Region.clipRound(getHeight() * scaleY);
         return graphicsConfig.createCompatibleImage(w, h, getTransparency());
     }
 
--- a/src/java.desktop/windows/classes/sun/java2d/d3d/D3DSurfaceData.java	Tue Nov 21 13:39:25 2017 -0800
+++ b/src/java.desktop/windows/classes/sun/java2d/d3d/D3DSurfaceData.java	Wed Nov 22 11:52:59 2017 +0530
@@ -58,6 +58,7 @@
 import sun.java2d.pipe.PixelToParallelogramConverter;
 import sun.java2d.pipe.RenderBuffer;
 import sun.java2d.pipe.TextPipe;
+import sun.java2d.pipe.Region;
 import static sun.java2d.pipe.BufferedOpCodes.*;
 import static sun.java2d.d3d.D3DContext.D3DContextCaps.*;
 import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
@@ -236,8 +237,8 @@
             this.width = scaledSize.width;
             this.height = scaledSize.height;
         } else {
-            this.width = (int) Math.ceil(width * scaleX);
-            this.height = (int) Math.ceil(height * scaleY);
+            this.width = Region.clipRound(width * scaleX);
+            this.height = Region.clipRound(height * scaleY);
         }
 
         this.offscreenImage = image;
@@ -812,8 +813,8 @@
             double scaleY = getDefaultScaleY();
             Rectangle r = peer.getBounds();
             r.x = r.y = 0;
-            r.width = (int) Math.ceil(r.width * scaleX);
-            r.height = (int) Math.ceil(r.height * scaleY);
+            r.width = Region.clipRound(r.width * scaleX);
+            r.height = Region.clipRound(r.height * scaleY);
             return r;
         } else {
             return new Rectangle(width, height);
--- a/src/java.desktop/windows/classes/sun/java2d/opengl/WGLSurfaceData.java	Tue Nov 21 13:39:25 2017 -0800
+++ b/src/java.desktop/windows/classes/sun/java2d/opengl/WGLSurfaceData.java	Wed Nov 22 11:52:59 2017 +0530
@@ -37,6 +37,7 @@
 import sun.awt.Win32GraphicsDevice;
 import sun.awt.windows.WComponentPeer;
 import sun.java2d.SurfaceData;
+import sun.java2d.pipe.Region;
 
 public abstract class WGLSurfaceData extends OGLSurfaceData {
 
@@ -165,8 +166,8 @@
         public Rectangle getBounds() {
             Rectangle r = peer.getBounds();
             r.x = r.y = 0;
-            r.width = (int) Math.ceil(r.width * scaleX);
-            r.height = (int) Math.ceil(r.height * scaleY);
+            r.width = Region.clipRound(r.width * scaleX);
+            r.height = Region.clipRound(r.height * scaleY);
             return r;
         }
 
@@ -227,8 +228,8 @@
         {
             super(peer, gc, cm, type);
 
-            this.width = (int) Math.ceil(width * scaleX);
-            this.height = (int) Math.ceil(height * scaleY);
+            this.width = Region.clipRound(width * scaleX);
+            this.height = Region.clipRound(height * scaleY);
             offscreenImage = image;
 
             initSurface(this.width, this.height);
@@ -241,8 +242,8 @@
         public Rectangle getBounds() {
             if (type == FLIP_BACKBUFFER) {
                 Rectangle r = peer.getBounds();
-                r.width = (int) Math.ceil(r.width * scaleX);
-                r.height = (int) Math.ceil(r.height * scaleY);
+                r.width = Region.clipRound(r.width * scaleX);
+                r.height = Region.clipRound(r.height * scaleY);
                 r.x = r.y = 0;
                 return r;
             } else {
--- a/src/java.desktop/windows/classes/sun/java2d/windows/GDIWindowSurfaceData.java	Tue Nov 21 13:39:25 2017 -0800
+++ b/src/java.desktop/windows/classes/sun/java2d/windows/GDIWindowSurfaceData.java	Wed Nov 22 11:52:59 2017 +0530
@@ -302,8 +302,8 @@
     public Rectangle getBounds() {
         Rectangle r = peer.getBounds();
         r.x = r.y = 0;
-        r.width = (int) Math.ceil(r.width * scaleX);
-        r.height = (int) Math.ceil(r.height * scaleY);
+        r.width = Region.clipRound(r.width * scaleX);
+        r.height = Region.clipRound(r.height * scaleY);
         return r;
     }
 
--- a/test/jdk/sun/java2d/SunGraphics2D/DrawImageBilinear.java	Tue Nov 21 13:39:25 2017 -0800
+++ b/test/jdk/sun/java2d/SunGraphics2D/DrawImageBilinear.java	Wed Nov 22 11:52:59 2017 +0530
@@ -23,11 +23,12 @@
 /*
  * @test
  * @key headful
- * @bug 5009033 6603000 6666362
+ * @bug 5009033 6603000 6666362 8159142
  * @summary Verifies that images transformed with bilinear filtering do not
  * leave artifacts at the edges.
- * @run main/othervm DrawImageBilinear
- * @run main/othervm -Dsun.java2d.opengl=True DrawImageBilinear
+ * @run main/othervm -Dsun.java2d.uiScale=2.5 DrawImageBilinear
+ * @run main/othervm -Dsun.java2d.uiScale=2.5 -Dsun.java2d.opengl=True DrawImageBilinear
+ * @run main/othervm -Dsun.java2d.uiScale=2.5 -Dsun.java2d.d3d=false DrawImageBilinear
  * @author campbelc
  */