On Wed, 2 Sep 2026 13:14:58 GMT, Jayathirth D V <[email protected]> wrote:

> Issue: When we render text using a TrueTypeFont and LCD mode, the rendered 
> text is corrupted with Metal pipeline on macOS.
> 
> Root cause: When FreeType rasterizes the LCD glyphs for TrueTypeFont it adds 
> padding bytes 
> https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/native/libfontmanager/freetypeScaler.c#L1033.
>  So glyph width and rowBytes are not same, and when we convert this LCD Glyph 
> into BGRA data in MTLTextRenderer.m we are not considering this padding and 
> it corrupts the text.
> 
> Fix: Use rowBytes information instead of width for LCD glyph and fill BGRA 
> data with proper offsets. I have also removed initialization of BGRA array to 
> 0, because we fill these arrays completely without any conditions.
> 
> Initially i was thinking of manual test but using already present 'A.ttf' 
> test font file in JDK, i am able to capture this LCD text corruption and 
> create an automated test. I have kept this test generic and to run on default 
> pipeline on all platforms, if not needed i can make the test macOS and Metal 
> specific. The generic test runs fine in CI pipeline.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

Overall, this looks good.
I have a minor comment regarding the for loop.

src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLTextRenderer.m line 
187:

> 185: 
> 186:         for (int col = 0; col < ginfo->width; col++) {
> 187:             dst[col * 4] = src[col * 3];

`col * 4` and `col * 3` can be stored in a variable and reused instead of 
repeating the same multiplications.

-------------

PR Review: https://git.openjdk.org/jdk/pull/32651#pullrequestreview-5100533531
PR Review Comment: https://git.openjdk.org/jdk/pull/32651#discussion_r3923376552

Reply via email to