< prev index next >
src/java.desktop/share/classes/java/awt/Robot.java
Print this page
rev 60071 : 8211999: Window positioning bugs due to overlapping GraphicsDevice bounds (Windows/HiDPI)
Reviewed-by: XXX
@@ -41,10 +41,13 @@
import sun.awt.ComponentFactory;
import sun.awt.SunToolkit;
import sun.awt.image.SunWritableRaster;
import sun.java2d.SunGraphicsEnvironment;
+import static sun.java2d.SunGraphicsEnvironment.toDeviceSpace;
+import static sun.java2d.SunGraphicsEnvironment.toDeviceSpaceAbs;
+
/**
* This class is used to generate native system input events
* for the purposes of test automation, self-running demos, and
* other applications where control of the mouse and keyboard
* is needed. The primary purpose of Robot is to facilitate
@@ -383,17 +386,13 @@
* @param y Y position of pixel
* @return Color of the pixel
*/
public synchronized Color getPixelColor(int x, int y) {
checkScreenCaptureAllowed();
- AffineTransform tx = GraphicsEnvironment.
- getLocalGraphicsEnvironment().getDefaultScreenDevice().
- getDefaultConfiguration().getDefaultTransform();
- x = (int) (x * tx.getScaleX());
- y = (int) (y * tx.getScaleY());
- Color color = new Color(peer.getRGBPixel(x, y));
- return color;
+ Point point = peer.useAbsoluteCoordinates() ? toDeviceSpaceAbs(x, y)
+ : toDeviceSpace(x, y);
+ return new Color(peer.getRGBPixel(point.x, point.y));
}
/**
* Creates an image containing pixels read from the screen. This image does
* not include the mouse cursor.
@@ -521,21 +520,20 @@
false, null);
imageArray = new BufferedImage[1];
imageArray[0] = highResolutionImage;
} else {
-
- int sX = (int) Math.floor(screenRect.x * uiScaleX);
- int sY = (int) Math.floor(screenRect.y * uiScaleY);
- int sWidth = (int) Math.ceil(screenRect.width * uiScaleX);
- int sHeight = (int) Math.ceil(screenRect.height * uiScaleY);
- int[] temppixels;
- Rectangle scaledRect = new Rectangle(sX, sY, sWidth, sHeight);
- temppixels = peer.getRGBPixels(scaledRect);
-
+ Rectangle scaledRect;
+ if (peer.useAbsoluteCoordinates()) {
+ scaledRect = toDeviceSpaceAbs(gc, screenRect.x,
+ screenRect.y, screenRect.width, screenRect.height);
+ } else {
+ scaledRect = toDeviceSpace(gc, screenRect.x,
+ screenRect.y, screenRect.width, screenRect.height);
+ }
// HighResolutionImage
- pixels = temppixels;
+ pixels = peer.getRGBPixels(scaledRect);
buffer = new DataBufferInt(pixels, pixels.length);
raster = Raster.createPackedRaster(buffer, scaledRect.width,
scaledRect.height, scaledRect.width, bandmasks, null);
SunWritableRaster.makeTrackable(buffer);
< prev index next >