RFR: 8311492: FontSmoothingType LCD produces wrong color when transparency is used
Kevin Rushforth
kcr at openjdk.org
Fri Feb 9 13:03:13 UTC 2024
JavaFX LCD text rendering (aka sub-pixel antialiasing) uses a pixel shader and alpha blending. The alpha channel is used is ways that interfere with its use for transparency. The existing logic checks that the current blend equation is SRC_OVER and that the surface is opaque, and that we are rendering using a Paint of type Color. It fails to check that the text color is opaque. When it isn't, the resulting alpha value is not preserved, even in the middle of the filled portion of the text, resulting in a visually noticeable difference in color.

The solution is to add the missing check for alpha == 1 to the test that checks whether we can use LCD text rendering. I note that Java2D falls back to gray scale when the text color is transparent for a similar reason.
I added a robot test that checks the color in the middle of the filled portion of a rendered text character and also checks that we use LCD for opaque colors and GRAY scale for transparent colors.
-------------
Commit messages:
- Test cleanup
- Make test more robust
- 8311492: FontSmoothingType LCD produces wrong color when transparency is used
Changes: https://git.openjdk.org/jfx/pull/1361/files
Webrev: https://webrevs.openjdk.org/?repo=jfx&pr=1361&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8311492
Stats: 285 lines in 3 files changed: 284 ins; 0 del; 1 mod
Patch: https://git.openjdk.org/jfx/pull/1361.diff
Fetch: git fetch https://git.openjdk.org/jfx.git pull/1361/head:pull/1361
PR: https://git.openjdk.org/jfx/pull/1361
More information about the openjfx-dev
mailing list