On Fri, 8 Oct 2021 10:23:13 GMT, Sergey Bylokhov <[email protected]> wrote:
> In JDK 9 the native code for the robot class was reworked to get an access to
> the HiDPI quality screenshots. So we allocate the data storage for the HiDPI
> quality and then request the best quality from the macOS.
>
> It works fine if the user request the screenshot of some area, since we
> properly scale this area. Unfortunately it does not work well if the user
> request only one pixel, in this case we allocate the array of one element and
> does not multiply the size by the scale, so if the system scale is 2 then the
> macOS returns the 2x2 pixels, which does not fit properly to the array of one
> element. This can be checked by the Xcheck:jni option which produce fatal
> error in this case.
>
> Solution is to allocate the storage of the proper size 1 * scale * 1 * scale
I get that getPixelColor() / getRGBPixel() takes only a coordinate but when
looking at CRobotPeer it is far from obvious why there is this inconsistency.
If we can't make the shared code consistent - maybe add a scale parameter ?
Then at least we should have some comments.
But why are X11 and Windows fine with no scale ?
X11:
@Override
public int getRGBPixel(int x, int y) {
int[] pixelArray = new int[1];
getRGBPixelsImpl(xgc, x, y, 1, 1, pixelArray, useGtk);
return pixelArray[0];
}
Windows :
@Override
public int getRGBPixel(int x, int y) {
// See 7002846: that's ineffective, but works correctly with
non-opaque windows
return getRGBPixels(new Rectangle(x, y, 1, 1))[0];
}
And in native what I was suggesting was a safeguard that would have detected
this problem - which I still think would be a good idea.
BTW "usually this is 1x1 pixel on lowdpi and 4x4 on hidpi screen, actually
macOS may return any size"
When might it return "any size" ?
My experiments show scale==2 no matter what scale I use in the macos Display
settings for the built-in retina
-------------
PR: https://git.openjdk.java.net/jdk/pull/5864