-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
8303904: [macos]Transparent Windows Paint Wrong (Opaque, Pixelated) w/o Volatile Buffering #23430
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back anass-baya! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
@anass-baya 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
|
test/jdk/javax/swing/JWindow/NonVolatileTransparentWindows/PixelatedImageTest.java
Outdated
Show resolved
Hide resolved
test/jdk/javax/swing/JWindow/NonVolatileTransparentWindows/TransparentWindowTest.java
Outdated
Show resolved
Hide resolved
float scaleFactor = getDevice().getScaleFactor(); | ||
int fullResWidth = Math.round( scaleFactor * width); | ||
int fullResHeight = Math.round( scaleFactor * height); | ||
WritableRaster wr = model.createCompatibleWritableRaster(fullResWidth, fullResHeight); |
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 working on this. :)
I have a couple of questions:
- This math looks great for the simple case of a 200% high-res monitor; is the rounding safe for non-integer resolutions?
For ex if width is 33 and scaleFactor is 1.25, then we'll call round(41.25)
, so fullResWidth = 41
.
Will the native windowing system allocate 41px for our Window? (Because if so: great. We have a perfect fit.) Or could it allocate 42px? (In which case we may have a thin border on the right/bottom that becomes unpaintable...)
- I'm assuming if
fullResWidth
/fullResHeight
is ever zero we'll get a RTE. I don't think it's stated, but the preexisting code suggestswidth
andheight
were never zero. Is it possiblescaleFactor
can ever be less than .5? (I've never observed that in my day-to-day life, but I'm just thinking about edge cases and RTE's...)
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.
Hello @mickleness ,
Thank you for your review.
It is well known that we can lose a fraction of a pixel. For example in #23183 we allowed a 1-pixel margin of error to compensate for that as the rounding error could accumulate
returnValue.scale(scaleFactor, scaleFactor); | ||
return returnValue; | ||
} | ||
}; | ||
} |
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.
This may be outside the scope of this ticket, but I'm seeing similar code in Win32GraphicsConfig#createAcceleratedImage(..), X11GraphicsConfig#createAcceleratedImage(..), and GLXGraphicsConfig#createAcceleratedImage(..) .
Should those be looked at, or is there another ticket to explore those? (That is: are they also going to be opaque and the wrong resolution?)
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.
Hello @mickleness,
The problem is not reproduced on windows !! I can see it only on mac
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.
tldr: Wow / huh. You're right. Thanks for checking.
That code looks so suspicious that I did some digging:
(A. On Windows the TransparentWindowTest says it fails because Image.getTransparency() is OPAQUE, but the test is wrong: the window looks fine.)
B. It works because on Windows we end up using the TranslucentWindowPainter. We never invoke Win32GraphicsConfig#createAcceleratedImage(..)
at all (unless the TransparentWindowTest invokes it directly).
I tested:
A. repainting on a timer (so we'd explicitly go through the RepaintManager), and
B. an ellipse fill instead of a rectangle fill (to double-check that transparent pixels really were transparent).
C. using Window.setShape(..) instead of changing the window's background color to transparent (to make sure it followed the same path)
(... and I don't have access to any other platforms to make sure Linux is doing the right thing.)
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.
Hello @mickleness,
Yes, on Windows we use TranslucentWindowPainter.
I moved the PR to draft since I'm trying to simplify the scaling handler logic. I'll come back to you once I'm done with that.
This test is only for macOS. On Windows, it will fail because we don’t explicitly set the Translucent flag.
returnValue.scale(scaleFactor, scaleFactor); | ||
return returnValue; | ||
} | ||
}; | ||
} |
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.
Should this new createAcceleratedImage(..)
logic be moved to CGraphicsConfig
?
This looks like copied and pasted code in two subclasses that could be abstracted into the parent class. (I could be wrong here; I just wanted to check opinions...?)
It looks like these two classes (MTLGraphicsConfig and CGLGraphicsConfig) are the only subclasses for CGraphicsConfig.
@anass-baya If your fix is based on @mickleness's previous PR, you should him as co-author using the |
@anass-baya Syntax:
User names can only be used for users in the census associated with this repository. For other contributors you need to supply the full name and email address. |
/contributor add Jeremy mickleness mickleness@gmail.com |
@anass-baya |
@mickleness I wonder what is your preferred email address and name. You were referenced by another email in your recent contribution. |
|
||
Image img = getLWGC().createAcceleratedImage(getTarget(), scaledWidth, scaledHeight); | ||
if(ScaleX == 1 || ScaleY == 1) | ||
return img; |
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.
Should this be &&
instead of ||
?
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 to me (note I'm not an official OpenJDK reviewer). I'm not a fan of the instanceof Graphics2D
check, but any alternative I propose would be more lines of code so I accept this is good enough.
import java.awt.Rectangle; | ||
import java.awt.Toolkit; | ||
import java.awt.Window; | ||
import java.awt.*; |
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 know in other PRs reviewers have asked to expand wildcard imports. (I haven't studied that topic closely enough to have an informed opinion.)
The PR includes two fix :
1 - The first fix targets proper rendering of the transparent image.
2 - The second fix ensures the image is painted at the correct resolution to avoid pixelation.
Progress
Issue
Reviewers without OpenJDK IDs
Contributors
<mickleness@gmail.com>
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/23430/head:pull/23430
$ git checkout pull/23430
Update a local copy of the PR:
$ git checkout pull/23430
$ git pull https://git.openjdk.org/jdk.git pull/23430/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 23430
View PR using the GUI difftool:
$ git pr show -t 23430
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/23430.diff
Using Webrev
Link to Webrev Comment