changeset 47731:187b92b2e32d

8145795: [PIT] java/awt/Window/ScreenLocation/ScreenLocationTest.java fails (can assign Integer.MAX_VALUE to Window dimensions) Reviewed-by: serb, pkbalakr Contributed-by: pankaj.b.bansal@oracle.com
author aghaisas
date Mon, 23 Oct 2017 16:55:52 +0530
parents 9b702b6608f9
children d64ae7c1d70f
files src/java.desktop/unix/classes/sun/awt/X11/XDragSourceContextPeer.java src/java.desktop/unix/classes/sun/awt/X11/XlibUtil.java src/java.desktop/unix/classes/sun/awt/X11GraphicsConfig.java src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsDevice.cpp src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsDevice.h test/jdk/java/awt/Window/ScreenLocation/ScreenLocationTest.java
diffstat 6 files changed, 31 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/unix/classes/sun/awt/X11/XDragSourceContextPeer.java	Fri Oct 20 20:08:09 2017 -0700
+++ b/src/java.desktop/unix/classes/sun/awt/X11/XDragSourceContextPeer.java	Mon Oct 23 16:55:52 2017 +0530
@@ -38,6 +38,7 @@
 
 import java.util.*;
 
+import sun.java2d.pipe.Region;
 import sun.util.logging.PlatformLogger;
 
 import sun.awt.dnd.SunDragSourceContextPeer;
@@ -811,10 +812,10 @@
     }
 
     public int scaleUp(int x) {
-        return x * windowScale;
+        return Region.clipRound(x * (double)windowScale);
     }
 
     public int scaleDown(int x) {
-        return x / windowScale;
+        return Region.clipRound(x / (double)windowScale);
     }
 }
--- a/src/java.desktop/unix/classes/sun/awt/X11/XlibUtil.java	Fri Oct 20 20:08:09 2017 -0700
+++ b/src/java.desktop/unix/classes/sun/awt/X11/XlibUtil.java	Mon Oct 23 16:55:52 2017 +0530
@@ -38,6 +38,8 @@
 import sun.awt.X11GraphicsDevice;
 import sun.awt.X11GraphicsEnvironment;
 
+import sun.java2d.pipe.Region;
+
 /*
  * This class is a collection of utility methods that operate
  * with native windows.
@@ -414,6 +416,6 @@
     }
 
     static int scaleDown(int x, int scale) {
-        return x / scale;
+        return Region.clipRound(x / (double)scale);
     }
 }
--- a/src/java.desktop/unix/classes/sun/awt/X11GraphicsConfig.java	Fri Oct 20 20:08:09 2017 -0700
+++ b/src/java.desktop/unix/classes/sun/awt/X11GraphicsConfig.java	Mon Oct 23 16:55:52 2017 +0530
@@ -49,6 +49,7 @@
 import sun.java2d.loops.RenderLoops;
 import sun.java2d.loops.SurfaceType;
 import sun.java2d.loops.CompositeType;
+import sun.java2d.pipe.Region;
 import sun.java2d.x11.X11SurfaceData;
 import sun.awt.image.OffScreenImage;
 import sun.awt.image.SunVolatileImage;
@@ -265,11 +266,11 @@
     }
 
     public int scaleUp(int x) {
-        return x * getScale();
+        return Region.clipRound(x * (double)getScale());
     }
 
     public int scaleDown(int x) {
-        return x / getScale();
+        return Region.clipRound(x / (double)getScale());
     }
 
     /**
--- a/src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsDevice.cpp	Fri Oct 20 20:08:09 2017 -0700
+++ b/src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsDevice.cpp	Mon Oct 23 16:55:52 2017 +0530
@@ -632,22 +632,37 @@
 
 int AwtWin32GraphicsDevice::ScaleUpX(int x)
 {
-    return (int)ceil(x * scaleX);
+    return CheckIntLimits(x * scaleX);
 }
 
 int AwtWin32GraphicsDevice::ScaleUpY(int y)
 {
-    return (int)ceil(y * scaleY);
+    return CheckIntLimits(y * scaleY);
 }
 
 int AwtWin32GraphicsDevice::ScaleDownX(int x)
 {
-    return (int)ceil(x / scaleX);
+    return CheckIntLimits(x / scaleX);
 }
 
 int AwtWin32GraphicsDevice::ScaleDownY(int y)
 {
-    return (int)ceil(y / scaleY);
+    return CheckIntLimits(y / scaleY);
+}
+
+int AwtWin32GraphicsDevice::CheckIntLimits(double value)
+{
+    if (value < INT_MIN)
+    {
+        return INT_MIN;
+    }
+
+    if (value > INT_MAX)
+    {
+        return INT_MAX;
+    }
+
+    return (int)ceil(value);
 }
 
 void AwtWin32GraphicsDevice::InitDesktopScales()
--- a/src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsDevice.h	Fri Oct 20 20:08:09 2017 -0700
+++ b/src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsDevice.h	Mon Oct 23 16:55:52 2017 +0530
@@ -119,6 +119,7 @@
     float                   scaleY;
 
     static HDC              MakeDCFromMonitor(HMONITOR);
+    static int              CheckIntLimits(double value);
 };
 
 #endif AWT_WIN32GRAPHICSDEVICE_H
--- a/test/jdk/java/awt/Window/ScreenLocation/ScreenLocationTest.java	Fri Oct 20 20:08:09 2017 -0700
+++ b/test/jdk/java/awt/Window/ScreenLocation/ScreenLocationTest.java	Mon Oct 23 16:55:52 2017 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -24,7 +24,7 @@
 /*
  * @test
  * @key headful
- * @bug 8011616
+ * @bug 8011616 8145795
  * @summary JWindow.getLocation and JWindow.getLocationOnScreen return different
  *          values on Unity
  * @author Semyon Sadetsky