8145795: [PIT] java/awt/Window/ScreenLocation/ScreenLocationTest.java fails (can assign Integer.MAX_VALUE to Window dimensions)

Reviewed-by: serb, pkbalakr
This commit is contained in:
Pankaj Bansal 2017-10-23 16:55:52 +05:30 committed by Ajit Ghaisas
parent c852879b03
commit 6e6996cd6c
6 changed files with 31 additions and 11 deletions
src/java.desktop
test/jdk/java/awt/Window/ScreenLocation

@ -38,6 +38,7 @@ import java.awt.dnd.InvalidDnDOperationException;
import java.util.*;
import sun.java2d.pipe.Region;
import sun.util.logging.PlatformLogger;
import sun.awt.dnd.SunDragSourceContextPeer;
@ -811,10 +812,10 @@ public final class XDragSourceContextPeer
}
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);
}
}

@ -38,6 +38,8 @@ import sun.awt.X11GraphicsConfig;
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 @@ public class XlibUtil
}
static int scaleDown(int x, int scale) {
return x / scale;
return Region.clipRound(x / (double)scale);
}
}

@ -49,6 +49,7 @@ import sun.java2d.SurfaceData;
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 class X11GraphicsConfig extends GraphicsConfiguration
}
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());
}
/**

@ -632,22 +632,37 @@ void AwtWin32GraphicsDevice::SetScale(float sx, float sy)
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()

@ -119,6 +119,7 @@ private:
float scaleY;
static HDC MakeDCFromMonitor(HMONITOR);
static int CheckIntLimits(double value);
};
#endif AWT_WIN32GRAPHICSDEVICE_H

@ -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