-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8349188: LineBorder does not scale correctly #26025
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
Conversation
|
👋 Welcome back rmahajan! A progress list of the required criteria for merging this PR into |
|
@rajamah 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 207 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 (@aivanov-jdk, @mrserb) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
|
/contributor add @aivanov-jdk |
|
@rajamah |
Webrevs
|
aivanov-jdk
left a comment
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.
Looks good except for a few nits.
src/java.desktop/share/classes/javax/swing/border/LineBorder.java
Outdated
Show resolved
Hide resolved
test/jdk/javax/swing/border/LineBorder/ScaledLineBorderTest.java
Outdated
Show resolved
Hide resolved
src/java.desktop/share/classes/javax/swing/border/LineBorder.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Alexey Ivanov <[email protected]>
Co-authored-by: Alexey Ivanov <[email protected]>
Co-authored-by: Alexey Ivanov <[email protected]>
| Shape inner; | ||
|
|
||
| int offs = this.thickness * (int) scaleFactor; | ||
| int offs = clipRound(this.thickness * scaleFactor); |
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.
Please double-check whether you need to use Region.clipScale() instead.
I actually do not remember when to use one over the other. Maybe if you find a review request for the patch where these methods were added, you can confirm which one should be used. I checked the current source, and it seems that we randomly use one or the other, which seems incorrect.
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.
it might be possible we should use one for the left/top part and another for the right/bottom so we will not create a gaps.
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.
Please double-check whether you need to use Region.clipScale() instead.
@mrserb We use Region.clipRound for converting coordinates in SwingUtilities3.paintBorder:
jdk/src/java.desktop/share/classes/com/sun/java/swing/SwingUtilities3.java
Lines 231 to 236 in a23de2e
| double xx = at.getScaleX() * x + at.getTranslateX(); | |
| double yy = at.getScaleY() * y + at.getTranslateY(); | |
| xtranslation = clipRound(xx); | |
| ytranslation = clipRound(yy); | |
| width = clipRound(at.getScaleX() * w + xx) - xtranslation; | |
| height = clipRound(at.getScaleY() * h + yy) - ytranslation; |
These formulas were introduced in #10681 (JDK-8282958); and after refactoring #11571 (JDK-8294680), the new formulas resolved JDK-8294921 after #7449 (JDK-8279614) where there was a gap between the component edge and its border. These formulas specifically addressed the situation with gaps and were developed while we worked on making LineBorder and EtchedBorder render better at fractional scales.
So, using clipRound seems good enough. Initially, I suggested using (int) (this.thickness * scaleFactor), but clipRound gives better results.
I actually do not remember when to use one over the other. Maybe if you find a review request for the patch where these methods were added, you can confirm which one should be used.
I couldn't find anything explaining where clipScale is better than clipRound. The discussion for JDK-8000629 started in March 2013 and continued in April 2013.
I checked the current source, and it seems that we randomly use one or the other, which seems incorrect.
The javadoc for neither clipScale nor clipRound provides an example where each method is best suitable. So, it's not that surprising either is used randomly…
It seems to me, that both clipScale and clipRound yield the same result. The former uses Math.round, whereas the latter uses Math.ceil after subtracting 0.5.
it might be possible we should use one for the left/top part and another for the right/bottom so we will not create a gaps.
Perhaps… However, I'm pretty sure gaps are still possible whatever method we choose because fractional pixels don't fit nicely into the pixel grid.
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 am pretty sure these methods produce different results for negative coordinates.
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.
probably these discussions may help
https://mail.openjdk.org/pipermail/2d-dev/2016-July/007152.html
https://mail.openjdk.org/pipermail/2d-dev/2016-October/007764.html
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.
@mrserb Putting the discussions aside, does the suggested fix look good to you?
As I said, border painting uses clipRound consistently: both in coordinate calculation and in thickness calculation. This approach resolves the problem reported.
Looking at descriptions of clipScale and clipRound, it seems the former suits better… Yet it makes the rendering less consistent with other borders: using clipScale switches to 2-pixel and 3-pixel border at 1.50 and 2.50 correspondingly (from 1 and 2 with clipRound). In other cases, the border thickness also increases, which may be undesirable.
Overall, there are 6 failures of the ScaledLineBorderTest.java test when the code in JDK uses clipScale instead of clipRound.
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 looked at another test case Rajat and I discussed, and using clipScale doesn't help there either. I prefer rendering with clipRound.
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.
My point is to investigate the difference between clipScale and clipRound to ensure the correct one is used. There was a complex discussion before about similar issue, which is why we currently have two separate versions of this rounding logic. Simply replacing one with the other might not work and some other tweaks should be done.
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.
My point is clipRound works good in this use case, it resolves the problem, I see no reason not to accept the fix.
I agree with your general concern that we should understand better the purpose of each method. Yet no one seems to remember the outcome of that complex discussion, therefore switching to clipScale could be postponed; if it's deemed necessary, we can easily change the method, both in the implementation and in the test.
I submitted JDK-8361095 to ensure this current discussion isn't forgotten and we figure out the purpose and guidelines for clipScale and clipRound.
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.
Ok sounds good.
|
/integrate |
|
Nudge the Skara bots with a comment… |
|
/sponsor |
|
Going to push as commit 24117c6.
Your commit was automatically rebased without conflicts. |
|
@aivanov-jdk @rajamah Pushed as commit 24117c6. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Modified the code to account for border thickness correctly and updated the related tests to make sure we are testing the new change.
Testing done.
Progress
Issue
Reviewers
Contributors
<[email protected]>Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26025/head:pull/26025$ git checkout pull/26025Update a local copy of the PR:
$ git checkout pull/26025$ git pull https://git.openjdk.org/jdk.git pull/26025/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 26025View PR using the GUI difftool:
$ git pr show -t 26025Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26025.diff
Using Webrev
Link to Webrev Comment