JEP 382: New macOS Rendering Pipeline

OwnerPhilip Race
StatusClosed / Delivered
Componentclient-libs / 2d
Discussionlanai dash dev at openjdk dot java dot net
Reviewed byAjit Ghaisas, Alexey Ushakov, Iris Clark, Jayathirth D V, Kevin Rushforth, Sergey Bylokhov
Endorsed byKevin Rushforth
Created2020/01/31 21:40
Updated2022/04/05 17:26


Implement a Java 2D internal rendering pipeline for macOS using the Apple Metal API as alternative to the existing pipeline, which uses the deprecated Apple OpenGL API.




Two major factors motivate the introduction of a new Metal-based rendering pipeline on macOS:


Most graphical Java applications are written using the Swing UI toolkit, which renders via the Java 2D API. Internally, Java 2D can use software rendering plus a blit to the screen or it can use a platform-specific API, such as X11/Xrender on Linux, Direct3D on Windows, or OpenGL on macOS. These platform-specific APIs typically offer much better performance than software rendering, and generally off-load the CPU. Metal is the new macOS platform API for such rendering, replacing the deprecated OpenGL API. (The name has nothing to do with the Swing “Metal” Look and Feel; that is just a coincidence.)

We created a substantial amount of new internal implementation code to use the Metal framework, just as we already had for the other platform-specific APIs. Whilst easily fitting into the existing framework the new code is much more modern in its use of graphics hardware, making use of shaders rather than a fixed function pipeline. The changes are confined to macOS-specific code and even there only a minimal amount of code shared between Metal and OpenGL is updated. We did not introduce any new Java APIs, nor did we change any existing API.

The Metal pipeline can co-exist with the OpenGL pipeline. When a graphical application starts up, one or the other is chosen. For now, OpenGL remains the default. Metal is used only if it is specified on startup or if the initialization of OpenGL fails, as would happen in a future version of macOS with no OpenGL support.

At the time of integration of this JEP, Apple have yet to remove OpenGL. Until that happens an application can opt-in to Metal by specifying -Dsun.java2d.metal=true on the java command line. We will make the Metal rendering pipeline the default in a future release.

Prior to integration in the JDK, we conducted work on this JEP in Project Lanai.


Testing the functionality of the new pipeline did not require new functional test development, since no Java 2D APIs were changed. Existing tests and real-world applications sufficed. These included:

To test performance, we used:

Performance results for the final planned early-access release are here.

To further verify the new pipeline, we used macOS Xcode instrumentation tools to check for leaks and for correct Metal API usage.

Risks and Assumptions