-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8280861: Robot color picker broken on Linux with scaling above 100% #7425
Conversation
👋 Welcome back mkartashev! A progress list of the required criteria for merging this PR into |
@mkartashev The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
inline static int scale_down_to_minus_inf(int what, int scale) { | ||
return (int)floorf(what / (float)scale); | ||
} | ||
|
||
static gboolean gtk3_get_drawable_data(JNIEnv *env, jintArray pixelArray, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need to do the same for the gtk2? I suggest to update one of the test below to cover gtk_robot on/off for both gtk2/gtk3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not as the previous fix was mode for gtk3 only, but I can double-check. Do you know if MATE desktop environment is a good candidate for finding gtk2 or are there easier options on Ubuntu?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea what MATE is but if you are saying you have a recent Ubuntu and you don't have GTK2, I am at least 95% sure GTK2 is still available from Ubuntu package manager for all current releases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MATE desktop continues the "traditional" Gnome2 desktop development, so I thought it would be a good test for Gtk2 interfaces. FWIW, I ran the tests on such a system with DPI set to 200 (there's no other way to scale the interface under MATE AFAIK) and they all pass. However, the test executes the same code path as before going by if (gtk3_version_3_10)
branch.
GTK2 is still available from Ubuntu package manager for all current releases.
Right, but as long as gtk3 is also available, that's what we are going to use as AWT backend, see the code in gtk_interface.c.
I hacked around to forbid gtk3 from loading and the tests still passed (this time, without executing my changes).
I think gtk2 has no real notion of scale so the coordinates and size are always in screen pixels. See, for example, the documentation for gdk_pixbuf_get_from_drawable().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You do not need to hack the code, just add a "jdk.gtk.version" option to enable specific gtk version, this is what I suggested above. to disable the gtk usage in the robot the "awt.robot.gtk" can be used. So you can add that to some test to check that code paths works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pointers, I'll set up a separate test for that.
inline static int scale_down_to_minus_inf(int what, int scale) { | ||
return (int)floorf(what / (float)scale); | ||
} | ||
|
||
static gboolean gtk3_get_drawable_data(JNIEnv *env, jintArray pixelArray, | ||
int x, jint y, jint width, jint height, jint jwidth, int dx, int dy, | ||
jint scale) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this scale parameter is simply ignored? If the passed parameters are always in the device space and the array is allocated properly then we should not care about this scale(especially in case of gtk2)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this scale parameter is simply ignored?
Looks like it. I can only find one call site of get_drawable_data()
(in Java_sun_awt_X11_XRobotPeer_getRGBPixelsImpl()) and the scale
parameter is always 1. I think I can drop it from the interface if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please, this "scale" just make the code complicated w/o reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's done; please, take a look at the updated code.
@@ -2861,35 +2863,48 @@ static void transform_detail_string (const gchar *detail, | |||
} | |||
} | |||
|
|||
inline static int scale_down_to_plus_inf(int what, int scale) { | |||
return (int)ceilf(what / (float)scale); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the name of this and the companion function confusing.
what is "inf" short for ? I see that and I think plus_infinity.
scaled_ceiling and scaled_floor might be better names based on what I see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, "inf" is for infinity; this is sort of how the rounding modes are described in the IEEE754 standard. But since full length words make the function name too long and short versions are confusing, I will rename as you suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@prrace The change has been made, please, take a look.
@mkartashev This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 96 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@mrserb) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
/integrate |
@mkartashev |
/sponsor |
Going to push as commit cc7cf81.
Your commit was automatically rebased without conflicts. |
@forantar @mkartashev Pushed as commit cc7cf81. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
The primary API for image capture on modern Linuxes is
gdk_pixbuf_get_from_window()
that expects both coordinates and the size unscaled (i.e. not multiplied by the current desktop scale). At the same time,gtk3_interface.c:gtk3_get_drawable_data()
gets the coordinates fromRobot
that pre-scales them (multiplying by the scale known to Java, however, not necessarily the current desktop scale). The problem with the size had been partly taken care of in JDK-8225118, but coordinates are still passed togdk_pixbuf_get_from_window()
pre-scaled.The idea of the fix is to capture a possibly larger area that is guaranteed to contain the one that is interesting to the caller and then only copy the interesting pixels to the output image. As a positive side effect, the size of the captured area cannot be less than 1x1 (provided the correct input, of course). This solves the problem of zero size passed to
(*fp_gdk_pixbuf_get_from_drawable)
when the desktop scale is 3 and we're asked to capture just one pixel. In that case, the previous formula (width / (float) win_scale + 0.5
) would have yielded0
.A related issue would be that tests written specifically for this general area (
java/awt/Robot
) didn't catch this problem and only somewhat unrelated tests (javax/swing/...
) were affected.This one is solved by adding pixel-sized areas to the test image in
HiDPIRobotScreenCaptureTest.java
, which precise colors are then verified to match the expected ones. In addition to that, instead of verifying just the color of the center of a large area, 4 more pixels close to the area's border are checked. This helps to make sure that captured area coordinates aren't way off.The tests under
javax/swing/...
that originally helped to identify this problem were modified to provide more screen space for painting their components as extreme desktop scaling (300%) on Ubuntu doesn't leave much room due to a humongous title bar.The fix was tested by running all the modified tests on Ubuntu with desktop scaling set to 100%, 200%, and 300%. The
Robot
tests were also executed on Windows (300% scaling) and MacOS.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/7425/head:pull/7425
$ git checkout pull/7425
Update a local copy of the PR:
$ git checkout pull/7425
$ git pull https://git.openjdk.java.net/jdk pull/7425/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 7425
View PR using the GUI difftool:
$ git pr show -t 7425
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/7425.diff