Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8349701

TrueType fonts are rendered incorrectly in VolatileImage with Metal

XMLWordPrintable

    • 2d
    • x86_64
    • os_x

      ADDITIONAL SYSTEM INFORMATION :
      Not reproducible on MS Windows. Reproduced on:
      - zulu17.48.15-ca-jdk17.0.0-macosx_aarch64 with `-Dsun.java2d.metal=true`
      - temurin17.0.13+11 aarch64 (aka OpenJDK17U-jdk_aarch64_mac_hotspot_17.0.13_11) `with -Dsun.java2d.metal=true`
      - zulu19.0.45-ea-jdk19.0.0-ea.18-macosx_aarch64 and zulu21.38.21-ca-jdk21.0.5-macosx_aarch64 without additional system properties

      A DESCRIPTION OF THE PROBLEM :
      Some TrueType fonts are rendered by method `java.awt.Graphics2D#drawString` incorrectly in VolatileImage in the Metal rendering pipeline on macOS. The resulting image has diagonal artifacts.

      The root cause was found to be JDK-8284378 by bisecting on JDK versions, which landed me on zulu19.0.43-ea-jdk19.0.0-ea.17-macosx_aarch64 as the last good version and zulu19.0.45-ea-jdk19.0.0-ea.18-macosx_aarch64 as the first bad version. Then I looked at this range of versions in the JDK 19 updates repository:

        $ git log jdk-19+17..jdk-19+18 --oneline -- '*macosx*'
        f4edb59a6e4 8284567: Collapse identical catch branches in java.base
        3a0ddeba52b 8284378: Make Metal the default Java 2D rendering pipeline for macOS
        192886546bf 8284166: [macos] Replace deprecated alternateSelectedControlColor with selectedContentBackgroundColor

      Workaround
      Disable the Metal rendering pipeline by passing a system property -Dsun.java2d.metal=false or -Dsun.java2d.opengl=true to the JVM.

      REGRESSION : Last worked in version 18

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Prerequisites
      Requirements for the bug reproduction:
      1) macOS aarch64
      2) Metal rendering pipeline is used. See JDK-8284378 "Make Metal the default Java 2D rendering pipeline for macOS" for details.
      3) VolatileImage is used
      4) Default desktop rendering hints (from "awt.font.desktophints") are added
      5) A TrueType font is used. In this reproducer, the file OpenSans-Regular.ttf downloaded from Google Fonts is used.
      6) Font size is less than 51.

      Steps to reproduce
      1) Launch class swing.MetalFontRenderingBug (attached), with swing/OpenSans-Regular.ttf in resources
      2) Observe the text in the demo's window

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The text in the window ("Font: Open Sans Regular, size: 50") is readable.
      ACTUAL -
      The text in the window is unreadable with some kind of diagonal artifacts.

            jdv Jayathirth D V
            adev Anupam Dev
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: