--- old/src/java.desktop/windows/classes/sun/java2d/d3d/D3DGraphicsConfig.java 2017-03-09 13:37:27.712734700 +0400 +++ new/src/java.desktop/windows/classes/sun/java2d/d3d/D3DGraphicsConfig.java 2017-03-09 13:37:26.492664900 +0400 @@ -186,7 +186,17 @@ SurfaceData sd = d3dvsm.getPrimarySurfaceData(); if (sd instanceof D3DSurfaceData) { D3DSurfaceData d3dsd = (D3DSurfaceData)sd; - D3DSurfaceData.swapBuffers(d3dsd, x1, y1, x2, y2); + double scaleX = sd.getDefaultScaleX(); + double scaleY = sd.getDefaultScaleY(); + if (scaleX > 1 || scaleY > 1) { + int sx1 = (int) Math.floor(x1 * scaleX); + int sy1 = (int) Math.floor(y1 * scaleY); + int sx2 = (int) Math.ceil(x2 * scaleX); + int sy2 = (int) Math.ceil(y2 * scaleY); + D3DSurfaceData.swapBuffers(d3dsd, sx1, sy1, sx2, sy2); + } else { + D3DSurfaceData.swapBuffers(d3dsd, x1, y1, x2, y2); + } } else { // the surface was likely lost could not have been restored Graphics g = peer.getGraphics(); @@ -212,7 +222,7 @@ } } } - + private static class D3DBufferCaps extends BufferCapabilities { public D3DBufferCaps() { // REMIND: should we indicate that the front-buffer --- old/src/java.desktop/windows/classes/sun/java2d/d3d/D3DSurfaceData.java 2017-03-09 13:37:34.387116500 +0400 +++ new/src/java.desktop/windows/classes/sun/java2d/d3d/D3DSurfaceData.java 2017-03-09 13:37:33.310054900 +0400 @@ -765,8 +765,18 @@ // that was supposed to be swapped, and no-op this swap final Component target = (Component)sd.getPeer().getTarget(); SunToolkit.executeOnEventHandlerThread(target, new Runnable() { - public void run() { - target.repaint(x1, y1, x2, y2); + public void run() { + double scaleX = sd.getDefaultScaleX(); + double scaleY = sd.getDefaultScaleY(); + if (scaleX > 1 || scaleY > 1) { + int sx1 = (int) Math.floor(x1 / scaleX); + int sy1 = (int) Math.floor(y1 / scaleY); + int sx2 = (int) Math.ceil(x2 / scaleX); + int sy2 = (int) Math.ceil(y2 / scaleY); + target.repaint(sx1, sy1, sx2 - sx1, sy2 - sy1); + } else { + target.repaint(x1, y1, x2 - x1, y2 - y1); + } } }); return; @@ -788,7 +798,7 @@ rq.unlock(); } } - + /** * Returns destination Image associated with this SurfaceData. */ --- /dev/null 2017-03-09 13:37:41.000000000 +0400 +++ new/test/javax/swing/JFrame/8175301/ScaledFrameBackgroundTest.java 2017-03-09 13:37:39.269395700 +0400 @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Color; +import java.awt.Rectangle; +import java.awt.Robot; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +/** + * @test + * @bug 8175301 + * @summary Java GUI hangs on Windows when Display set to 125% + * @run main/othervm -Dsun.java2d.uiScale=2 ScaledFrameBackgroundTest + * @run main/othervm -Dsun.java2d.uiScale=2 -Dsun.java2d.d3d=true ScaledFrameBackgroundTest + * @run main/othervm -Dsun.java2d.uiScale=2 -Dsun.java2d.opengl=true ScaledFrameBackgroundTest + */ +public class ScaledFrameBackgroundTest { + + private static final Color BACKGROUND = Color.RED; + private static JFrame frame; + + public static void main(String[] args) throws Exception { + + Robot robot = new Robot(); + robot.setAutoDelay(50); + + SwingUtilities.invokeAndWait(() -> { + frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(400, 300); + JPanel panel = new JPanel(); + panel.setBackground(BACKGROUND); + frame.getContentPane().add(panel); + frame.setVisible(true); + }); + + robot.waitForIdle(); + + Rectangle[] rects = new Rectangle[1]; + SwingUtilities.invokeAndWait(() -> { + rects[0] = frame.getBounds(); + }); + + Rectangle bounds = rects[0]; + + int x = bounds.x + bounds.width / 4; + int y = bounds.y + bounds.height / 4; + + Color color = robot.getPixelColor(x, y); + System.out.println("background: " + BACKGROUND); + System.out.println("color : " + color); + + if (!BACKGROUND.equals(color)) { + throw new RuntimeException("Wrong backgound color!"); + } + + x = bounds.x + 3 * bounds.width / 4; + y = bounds.y + 3 * bounds.height / 4; + + color = robot.getPixelColor(x, y); + System.out.println("background: " + BACKGROUND); + System.out.println("color : " + color); + + if (!BACKGROUND.equals(color)) { + throw new RuntimeException("Wrong backgound color!"); + } + } +}