JDK-8271052 : PoC - Implement Alpha Blending
  • Type: Enhancement
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: internal
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: generic
  • Submitted: 2021-07-21
  • Updated: 2022-12-13
  • Resolved: 2022-12-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
internalFixed
Related Reports
Blocks :  
Comments
Here is the commit in the sandbox - https://github.com/openjdk/jfx-sandbox/commit/205cf7e4f252470d21e557502d5f0680e7d95cf3
13-12-2022

I have implemented the metal equivalent of com.sun.prism.CompositeMode - CLEAR, SRC, SRC_OVER, DST_OUT, ADD. There are no tests to test these as CompositeMode is not a public API. The default SRC_OVER mode is tested with basic blending of shapes with different alpha. Here is the sample program which results in the same output with Metal pipeline and OpenGL pipeline. import javafx.application.Application; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.*; import javafx.scene.paint.*; import javafx.scene.shape.*; public class AlphaBlendingPoC extends Application { @Override public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("AlphaBlend Test Program"); Rectangle r = new Rectangle(); r.setX(50); r.setY(50); r.setWidth(50); r.setHeight(50); r.setFill(Color.rgb(0, 0, 255, 1.0)); Circle c = new Circle(); c.setFill(Color.rgb(255, 0, 0, 0.4)); c.setCenterX(50); c.setCenterY(50); c.setRadius(25); Group g = new Group(); g.getChildren().add(r); g.getChildren().add(c); Scene scene = new Scene(g); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { Application.launch(args); } }
13-12-2022

Decora shaders are used to implement (2) as well. There is an internal enum - com.sun.prism.CompositeMode - CLEAR, SRC, SRC_OVER, DST_OUT, ADD These are simple composite modes which are implemented in OpenGL using glBlend() function. These modes can be implemented using metal pipeline states. I am able to implement default SRC_OVER composite mode. Work is in progress to implement other modes.
07-12-2022

There are 2 ways BlendMode can be used- 1) As a Blend effect - (class Blend extends class Effect) See sample in - https://openjfx.io/javadoc/19/javafx.graphics/javafx/scene/effect/Blend.html 2) As a blend mode of a Node- See sample in - https://openjfx.io/javadoc/19/javafx.graphics/javafx/scene/effect/BlendMode.html There is another "Global Blend Mode" in rendering attributes table- See - https://openjfx.io/javadoc/19/javafx.graphics/javafx/scene/canvas/GraphicsContext.html#attr-ops-table To implement (1) above, decora shaders are used. As part of this PoC, I am trying to understand how (2) and "Global Blend Mode" are implemented in ES2 and D3D pipeline. The final goal of this PoC is to implement one or more BlendModes using metal pipeline states.
30-11-2022