RFR: 8377426: Adjust scene background to color scheme [v2]
Michael Strauß
mstrauss at openjdk.org
Thu Feb 12 11:54:21 UTC 2026
On Thu, 12 Feb 2026 11:39:33 GMT, Michael Strauß <mstrauss at openjdk.org> wrote:
>> When a non-opaque scene fill color is used with a stage style other than `StageStyle.TRANSPARENT`, the actual fill color is always white. This doesn't work well when the scene uses a dark color scheme. A practical solution is to allow non-opaque scene fill colors, and blend them on top of a white or black background (depending on color scheme) to derive an opaque color that adapts intuitively to the color scheme.
>>
>> To test this, simply create a scene that uses a non-opaque fill color and observe the scene background when the color scheme is changed.
>>
>> This PR includes a system test, run it with:
>>
>> ./gradlew -PFULL_TEST=true -PUSE_ROBOT=true :systemTests:test --tests test.robot.javafx.scene.SceneFillTest.testSceneFill
>
> Michael Strauß has updated the pull request incrementally with one additional commit since the last revision:
>
> Clear background to dominant fill color
I've changed the implementation to get rid of the "white flash" that can sometimes be observed. For that purpose, I'm trying to find a solid color that best matches the actual paint that JavaFX will later render. This solid color is then passed to the OS to be the window's background color. After the first frame is rendered, this background color is no longer visible because JavaFX draws the entire background.
Finding a color that is representative of the actual JavaFX paint is done as follows:
1. `Color`: Blend the color on top of a white or black background, depending on the scene's color scheme.
2. `LinearGradient`, `RadialGradient`: Blend the gradient on top of a white or black background, and sample it at various locations to compute the average color.
3. `ImagePattern`: Compute the dominant color of the image by approximating its color palette with a clustering algorithm, and then select the color cluster with the most pixels in it. For large images, the runtime cost of this algorithm can be quite high, so its fidelity is throttled depending on the input image to not exceed 32000 samples.
Blending is done in sRGB space, as that's what the JavaFX rendering pipeline will do.
With this change, you shouldn't observe a wrong background before the first frame is rendered in most cases.
-------------
PR Comment: https://git.openjdk.org/jfx/pull/2068#issuecomment-3890471064
More information about the openjfx-dev
mailing list