Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8274939: Incorrect size of the pixel storage is used by the robot on …
…macOS

Reviewed-by: aivanov, prr
  • Loading branch information
mrserb committed Feb 12, 2022
1 parent 8acfbc2 commit eff5daf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/java.desktop/macosx/classes/sun/lwawt/macosx/CRobot.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2022, 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
Expand Down Expand Up @@ -168,9 +168,9 @@ public void keyRelease(final int keycode) {
*/
@Override
public int getRGBPixel(int x, int y) {
int[] c = new int[1];
double scale = fDevice.getScaleFactor();
getScreenPixels(new Rectangle(x, y, (int) scale, (int) scale), c);
int scale = fDevice.getScaleFactor();
int[] c = new int[scale * scale];
getScreenPixels(new Rectangle(x, y, scale, scale), c);
return c[0];
}

Expand Down
7 changes: 6 additions & 1 deletion src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2022, 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
Expand Down Expand Up @@ -321,6 +321,11 @@ static inline void autoDelay(BOOL isMove) {
jint picY = y;
jint picWidth = width;
jint picHeight = height;
jsize size = (*env)->GetArrayLength(env, pixels);
if (size < (long) picWidth * picHeight || picWidth < 0 || picHeight < 0) {
JNU_ThrowInternalError(env, "Invalid arguments to get screen pixels");
return;
}

CGRect screenRect = CGRectMake(picX / scale, picY / scale,
picWidth / scale, picHeight / scale);
Expand Down
Expand Up @@ -42,6 +42,8 @@
* @key headful
* @bug 8215105 8211999
* @summary tests that Robot can capture the common colors without artifacts
* @run main/othervm CheckCommonColors
* @run main/othervm -Xcheck:jni CheckCommonColors
*/
public final class CheckCommonColors {

Expand Down

5 comments on commit eff5daf

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrserb
Copy link
Member Author

@mrserb mrserb commented on eff5daf Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on eff5daf Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrserb the backport was successfully created on the branch mrserb-backport-eff5dafb in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit eff5dafb from the openjdk/jdk repository.

The commit being backported was authored by Sergey Bylokhov on 12 Feb 2022 and was reviewed by Alexey Ivanov and Phil Race.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev mrserb-backport-eff5dafb:mrserb-backport-eff5dafb
$ git checkout mrserb-backport-eff5dafb
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev mrserb-backport-eff5dafb

@mrserb
Copy link
Member Author

@mrserb mrserb commented on eff5daf Dec 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on eff5daf Dec 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrserb Could not automatically backport eff5dafb to openjdk/jdk11u-dev due to conflicts in the following files:

  • src/java.desktop/macosx/classes/sun/lwawt/macosx/CRobot.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk11u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk11u-dev master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b mrserb-backport-eff5dafb

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk eff5dafba9f72bd0612357712ffa472ce1c9166a

# Backport the commit
$ git cherry-pick --no-commit eff5dafba9f72bd0612357712ffa472ce1c9166a
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport eff5dafba9f72bd0612357712ffa472ce1c9166a'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk11u-dev with the title Backport eff5dafba9f72bd0612357712ffa472ce1c9166a.

Please sign in to comment.