< 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,50 ****
--- 41,53 ----
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,399 ****
* @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;
}
/**
* Creates an image containing pixels read from the screen. This image does
* not include the mouse cursor.
--- 386,398 ----
* @param y Y position of pixel
* @return Color of the pixel
*/
public synchronized Color getPixelColor(int x, int y) {
checkScreenCaptureAllowed();
! 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,541 ****
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);
!
// HighResolutionImage
! pixels = temppixels;
buffer = new DataBufferInt(pixels, pixels.length);
raster = Raster.createPackedRaster(buffer, scaledRect.width,
scaledRect.height, scaledRect.width, bandmasks, null);
SunWritableRaster.makeTrackable(buffer);
--- 520,539 ----
false, null);
imageArray = new BufferedImage[1];
imageArray[0] = highResolutionImage;
} else {
! 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 = 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 >