From cc0cb9660da5b9107065c86caa9fd9f057ef52ef Mon Sep 17 00:00:00 2001 From: Pankaj Bansal Date: Wed, 22 Nov 2017 11:52:59 +0530 Subject: [PATCH] 8159142: [hidpi] Visible artifacts in sun/java2d/SunGraphics2D/DrawImageBilinear.java Reviewed-by: serb, prr, pnarayanan --- .../classes/sun/awt/image/SunVolatileImage.java | 5 +++-- .../classes/sun/java2d/d3d/D3DSurfaceData.java | 9 +++++---- .../classes/sun/java2d/opengl/WGLSurfaceData.java | 13 +++++++------ .../sun/java2d/windows/GDIWindowSurfaceData.java | 4 ++-- .../sun/java2d/SunGraphics2D/DrawImageBilinear.java | 7 ++++--- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/java.desktop/share/classes/sun/awt/image/SunVolatileImage.java b/src/java.desktop/share/classes/sun/awt/image/SunVolatileImage.java index 1ee5c4019f1..55dfc8db766 100644 --- a/src/java.desktop/share/classes/sun/awt/image/SunVolatileImage.java +++ b/src/java.desktop/share/classes/sun/awt/image/SunVolatileImage.java @@ -40,6 +40,7 @@ import sun.java2d.SunGraphics2D; 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 @@ public class SunVolatileImage extends VolatileImage * 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()); } diff --git a/src/java.desktop/windows/classes/sun/java2d/d3d/D3DSurfaceData.java b/src/java.desktop/windows/classes/sun/java2d/d3d/D3DSurfaceData.java index 986f293d703..425209dcae3 100644 --- a/src/java.desktop/windows/classes/sun/java2d/d3d/D3DSurfaceData.java +++ b/src/java.desktop/windows/classes/sun/java2d/d3d/D3DSurfaceData.java @@ -58,6 +58,7 @@ import sun.java2d.pipe.ParallelogramPipe; 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 @@ public class D3DSurfaceData extends SurfaceData implements AccelSurface { 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 @@ public class D3DSurfaceData extends SurfaceData implements AccelSurface { 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); diff --git a/src/java.desktop/windows/classes/sun/java2d/opengl/WGLSurfaceData.java b/src/java.desktop/windows/classes/sun/java2d/opengl/WGLSurfaceData.java index d27b7d1cc6b..79eff60b2f8 100644 --- a/src/java.desktop/windows/classes/sun/java2d/opengl/WGLSurfaceData.java +++ b/src/java.desktop/windows/classes/sun/java2d/opengl/WGLSurfaceData.java @@ -37,6 +37,7 @@ import sun.awt.SunToolkit; 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 abstract class WGLSurfaceData extends OGLSurfaceData { 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 @@ public abstract class WGLSurfaceData extends OGLSurfaceData { { 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 abstract class WGLSurfaceData extends OGLSurfaceData { 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 { diff --git a/src/java.desktop/windows/classes/sun/java2d/windows/GDIWindowSurfaceData.java b/src/java.desktop/windows/classes/sun/java2d/windows/GDIWindowSurfaceData.java index ad211ab473c..629690fe136 100644 --- a/src/java.desktop/windows/classes/sun/java2d/windows/GDIWindowSurfaceData.java +++ b/src/java.desktop/windows/classes/sun/java2d/windows/GDIWindowSurfaceData.java @@ -302,8 +302,8 @@ public class GDIWindowSurfaceData extends SurfaceData { 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; } diff --git a/test/jdk/sun/java2d/SunGraphics2D/DrawImageBilinear.java b/test/jdk/sun/java2d/SunGraphics2D/DrawImageBilinear.java index cd1518e5b96..4330435aee9 100644 --- a/test/jdk/sun/java2d/SunGraphics2D/DrawImageBilinear.java +++ b/test/jdk/sun/java2d/SunGraphics2D/DrawImageBilinear.java @@ -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 */