diff options
author | Anton Tarasov <anton.tarasov@jetbrains.com> | 2017-04-06 13:34:50 +0300 |
---|---|---|
committer | Anton Tarasov <anton.tarasov@jetbrains.com> | 2017-04-06 13:36:03 +0300 |
commit | 7aa0858e44eac3bcf26581e6d55f5445cff14aee (patch) | |
tree | 7327f1d3472ba5384c6f9503fe5857b9f8b8f5f3 | |
parent | 6ec43ecd3d4be64fe5a4aa5a8cb953bfc6e6acc7 (diff) | |
download | jdk8u_jdk-7aa0858e44eac3bcf26581e6d55f5445cff14aee.tar.gz |
JRE-299 [windows] ColorPicker crashesjb8u152-b817
-rw-r--r-- | src/share/classes/java/awt/Robot.java | 43 | ||||
-rw-r--r-- | src/windows/classes/sun/awt/windows/WRobotPeer.java | 6 | ||||
-rw-r--r-- | src/windows/native/sun/windows/awt_Robot.cpp | 16 | ||||
-rw-r--r-- | src/windows/native/sun/windows/awt_Robot.h | 2 |
4 files changed, 20 insertions, 47 deletions
diff --git a/src/share/classes/java/awt/Robot.java b/src/share/classes/java/awt/Robot.java index 8fd3c37c23..d689760cc8 100644 --- a/src/share/classes/java/awt/Robot.java +++ b/src/share/classes/java/awt/Robot.java @@ -27,7 +27,6 @@ package java.awt; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; -import java.awt.geom.Point2D; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import java.awt.image.DirectColorModel; @@ -38,7 +37,6 @@ import java.lang.reflect.InvocationTargetException; import sun.awt.ComponentFactory; import sun.awt.SunToolkit; import sun.awt.image.SunWritableRaster; -import sun.font.FontUtilities; import sun.security.util.SecurityConstants; /** @@ -433,17 +431,6 @@ public class Robot { // cases rendering to the screen may be delayed Toolkit.getDefaultToolkit().sync(); - if (!GraphicsEnvironment.isHeadless()) { - Point2D center = new Point2D.Float(screenRect.x + screenRect.width / 2, screenRect.y + screenRect.height / 2); - for (GraphicsDevice device : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) { - Rectangle bounds = device.getDefaultConfiguration().getBounds(); - if (bounds.contains(center)) { - scaleUp(screenRect, device); - break; - } - } - } - int pixels[]; int[] bandmasks = new int[3]; @@ -454,7 +441,13 @@ public class Robot { bandmasks[1] = screenCapCM.getGreenMask(); bandmasks[2] = screenCapCM.getBlueMask(); - raster = Raster.createPackedRaster(buffer, screenRect.width, screenRect.height, screenRect.width, bandmasks, null); + assert pixels != null; + int arraySize = screenRect.width * screenRect.height; + double devScale = arraySize != 0 ? Math.sqrt(pixels.length / arraySize) : 1; + int devScreenWidth = (int)Math.ceil(screenRect.width * devScale); + int devScreenHeight = (int)Math.ceil(screenRect.height * devScale); + + raster = Raster.createPackedRaster(buffer, devScreenWidth, devScreenHeight, devScreenWidth, bandmasks, null); SunWritableRaster.makeTrackable(buffer); image = new BufferedImage(screenCapCM, raster, false, null); @@ -462,28 +455,6 @@ public class Robot { return image; } - private static void scaleUp(Rectangle bounds, GraphicsDevice device) { - double scaleX = device.getDefaultConfiguration().getDefaultTransform().getScaleX(); - double scaleY = device.getDefaultConfiguration().getDefaultTransform().getScaleY(); - int x; - int y; - if (FontUtilities.isWindows) { - // On Windows JDK transforms the screen bounds to the user space as follows: - // [x, y, width, height] -> [x, y, width / scale, height / scale] - // xy are not transformed in order to avoid overlapping of the screen bounds in multi-dpi env. - Rectangle deviceBounds = device.getDefaultConfiguration().getBounds(); - - // scale the delta b/w xy and deviceBounds.xy - x = (int) Math.floor(deviceBounds.x + (bounds.x - deviceBounds.x) * scaleX); - y = (int) Math.floor(deviceBounds.y + (bounds.y - deviceBounds.y) * scaleY); - } else { - x = (int) Math.floor(bounds.x * scaleX); - y = (int) Math.floor(bounds.y * scaleY); - } - - bounds.setBounds(x, y, (int)Math.ceil(bounds.width * scaleX), (int)Math.ceil(bounds.height * scaleY)); - } - private static void checkValidRect(Rectangle rect) { if (rect.width <= 0 || rect.height <= 0) { throw new IllegalArgumentException("Rectangle width and height must be > 0"); diff --git a/src/windows/classes/sun/awt/windows/WRobotPeer.java b/src/windows/classes/sun/awt/windows/WRobotPeer.java index 8521ec73c0..5e5ae8b16a 100644 --- a/src/windows/classes/sun/awt/windows/WRobotPeer.java +++ b/src/windows/classes/sun/awt/windows/WRobotPeer.java @@ -70,10 +70,8 @@ final class WRobotPeer extends WObjectPeer implements RobotPeer @Override public int [] getRGBPixels(Rectangle bounds) { - int pixelArray[] = new int[bounds.width*bounds.height]; - getRGBPixels(bounds.x, bounds.y, bounds.width, bounds.height, pixelArray); - return pixelArray; + return getRGBPixels(bounds.x, bounds.y, bounds.width, bounds.height); } - private native void getRGBPixels(int x, int y, int width, int height, int pixelArray[]); + private native int[] getRGBPixels(int x, int y, int width, int height); } diff --git a/src/windows/native/sun/windows/awt_Robot.cpp b/src/windows/native/sun/windows/awt_Robot.cpp index 8fe72e29a2..bf981898a5 100644 --- a/src/windows/native/sun/windows/awt_Robot.cpp +++ b/src/windows/native/sun/windows/awt_Robot.cpp @@ -197,7 +197,7 @@ inline jint AwtRobot::WinToJavaPixel(USHORT r, USHORT g, USHORT b) return value; } -void AwtRobot::GetRGBPixels(jint x, jint y, jint width, jint height, jintArray pixelArray) +jintArray AwtRobot::GetRGBPixels(jint x, jint y, jint width, jint height) { DASSERT(width > 0 && height > 0); @@ -285,7 +285,9 @@ void AwtRobot::GetRGBPixels(jint x, jint y, jint width, jint height, jintArray p *prgbq = *( (RGBQUAD *)(&jpixel) ); } - // copy pixels into Java array + jintArray pixelArray = env->NewIntArray(numPixels); + +// copy pixels into Java array env->SetIntArrayRegion(pixelArray, 0, numPixels, (jint *)pixelData); delete pinfo; @@ -297,6 +299,8 @@ void AwtRobot::GetRGBPixels(jint x, jint y, jint width, jint height, jintArray p ::DeleteObject(hbitmap); ::DeleteDC(hdcMem); ::DeleteDC(hdcScreen); + + return pixelArray; } void AwtRobot::KeyPress( jint jkey ) @@ -404,14 +408,14 @@ JNIEXPORT void JNICALL Java_sun_awt_windows_WRobotPeer_mouseWheel( CATCH_BAD_ALLOC; } -JNIEXPORT void JNICALL Java_sun_awt_windows_WRobotPeer_getRGBPixels( - JNIEnv *env, jobject self, jint x, jint y, jint width, jint height, jintArray pixelArray) +JNIEXPORT jintArray JNICALL Java_sun_awt_windows_WRobotPeer_getRGBPixels( + JNIEnv *env, jobject self, jint x, jint y, jint width, jint height) { TRY; - AwtRobot::GetRobot(self)->GetRGBPixels(x, y, width, height, pixelArray); + return AwtRobot::GetRobot(self)->GetRGBPixels(x, y, width, height); - CATCH_BAD_ALLOC; + CATCH_BAD_ALLOC_RET(NULL); } JNIEXPORT void JNICALL Java_sun_awt_windows_WRobotPeer_keyPress( diff --git a/src/windows/native/sun/windows/awt_Robot.h b/src/windows/native/sun/windows/awt_Robot.h index 2b1def7cdf..8438bfe4fe 100644 --- a/src/windows/native/sun/windows/awt_Robot.h +++ b/src/windows/native/sun/windows/awt_Robot.h @@ -44,7 +44,7 @@ class AwtRobot : public AwtObject void MouseWheel(jint wheelAmt); jint getNumberOfButtons(); - void GetRGBPixels(jint x, jint y, jint width, jint height, jintArray pixelArray); + jintArray GetRGBPixels(jint x, jint y, jint width, jint height); void KeyPress( jint key ); void KeyRelease( jint key ); |