On Sun, 6 Sep 2026 01:42:08 GMT, John Hendrikx <[email protected]> wrote:

>> This PR adds a `getDrawingContext` method to `WritableImage`, which works 
>> similar to `Canvas::getGraphicsContext` and shares the same signatures. Key 
>> features include:
>> 
>> - **Shape rendering**: `strokeRect`, `fillRect`, `strokeOval`, `fillOval`, 
>> `strokeArc`, `fillArc`, `strokePolyline`, `fillPolygon`, etc.
>> - **Stroke and fill attributes**: `lineWidth`, `lineCap`, `lineJoin`, 
>> `miterLimit`, `fillRule`, `stroke` and `fill` paints.
>> - **Global graphics settings**: `globalAlpha` and `globalBlendMode`.
>> - **Image drawing**: draw other `Image` instances with scaling and 
>> source/destination rectangles.
>> - **Text rendering**: render text
>> - **Save/Restore**: store current stroke, font, dashes, etc and restore them 
>> later
>> - **Paths**: begin a path, with lines, curves, etc, then stroke or fill it
>> - **Clips**: support rectangular clips in the SW renderer
>> 
>> This feature enables direct software rendering to `WritableImage` without 
>> requiring a `Canvas` + snapshot.
>> 
>> **Additional notes**:
>> 
>> - The implementation leverages the software stack consisting of the Marlin 
>> rasterizer and Pisces compositor/painter.
>> 
>> **Example usage**:
>> 
>> 
>> WritableImage img = new WritableImage(400, 400);
>> DrawingContext ctx = img.getDrawingContext();
>> ctx.setFill(Color.RED);
>> ctx.fillRect(50, 50, 100, 100);
>> 
>> 
>> See the sample program `RandomShapesDemo` to see a `WritableImage` and 
>> `Canvas` side by side performing the same operations:
>> 
>> <img width="1249" height="741" alt="image" 
>> src="https://github.com/user-attachments/assets/4a0b9dcc-8f96-4faa-99cf-83c66d2c851e";
>>  />
>> 
>> Newer version:
>> 
>> <img width="1249" height="741" alt="image" 
>> src="https://github.com/user-attachments/assets/c0502620-3d02-4fbd-8c33-43bd5138b42c";
>>  />
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> John Hendrikx has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Use actual painted pixels to compute dirty rects

modules/javafx.graphics/src/main/java/com/sun/prism/sw/SWDrawingContext.java 
line 90:

> 88:  * Features include:
> 89:  * <ul>
> 90:  *   <li>Stroke and fill management (line width, line caps, joins, miter 
> limits, dashes).</li>

I'd strongly prefer if you used 4 spaces of indentation like everywhere else in 
the codebase, and that you didn't include the closing `</li>`. I think we 
should consider adding the 4-spaces rule to our very limited style guide, as I 
don't think that repeated discussions or a free-for-all "everyone invents their 
own style" is useful.

modules/javafx.graphics/src/main/java/com/sun/prism/sw/SWDrawingContext.java 
line 592:

> 590:     private Rectangle transformRect(double x1, double y1, double x2, 
> double y2) {
> 591:         double[] src = {x1, y1, x2, y1, x1, y2, x2, y2};
> 592:         double[] dst = new double[8];

You could use scratch arrays stored in the class to prevent unnecessary 
allocations here (maybe reuse `coords`).

modules/javafx.graphics/src/main/java/com/sun/prism/sw/SWDrawingContext.java 
line 1029:

> 1027:     @Override
> 1028:     public boolean isPointInPath(double x, double y) {
> 1029:         // TODO: HTML5 considers points on the path to be inside, but we

What is left to do here?

modules/javafx.graphics/src/main/java/javafx/scene/image/DrawingContext.java 
line 55:

> 53:  * The {@code DrawingContext} maintains the following rendering attributes
> 54:  * which affect various subsets of the rendering methods:
> 55:  * <table class="overviewSummary" style="width:80%; margin-left:auto; 
> margin-right:auto">

Please indent the HTML elements of this table, it is unreadable in source code.

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

PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r3944446161
PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r3944455105
PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r3944461923
PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r3944471133

Reply via email to