On Mon, 10 Nov 2025 13:59:30 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. > > This feature enables direct software rendering to `WritableImage` without > requiring a `Canvas` + snapshot. > > **Additional notes**: > > - The implementation leverages the software `Pisces` renderer. > - This lays the groundwork for future support of text rendering and path > operations. > > **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). - The implementation leverages the software Pisces renderer. - This lays the groundwork for future support of text rendering and path operations. aren't these already implemented in this version? or something is still missing? modules/javafx.graphics/src/main/java/javafx/scene/canvas/GraphicsContext.java line 1415: > 1413: path.arcTo(curState.transform, (float) x1, (float) y1, > (float) x2, (float) y2, (float) radius); > 1414: } > 1415: catch (IllegalPathStateException | > NoninvertibleTransformException e) { aren't these braces incompatible with the coding style? modules/javafx.graphics/src/main/java/javafx/scene/canvas/GraphicsContext.java line 1501: > 1499: } > 1500: > 1501: @Override is this a new method in the `GraphicsContext`? if so, it needs `@since`. modules/javafx.graphics/src/main/java/javafx/scene/image/WritableImage.java line 170: > 168: * @return the {@link DrawingContext} associated with this image, > never {@code null} > 169: */ > 170: public DrawingContext getDrawingContext() { should this method be `final`? modules/javafx.graphics/src/main/java/javafx/scene/image/WritableImage.java line 175: > 173: if (context == null) { > 174: if (!(getWritablePlatformImage() instanceof > com.sun.prism.Image img)) { > 175: throw new IllegalStateException("platformImage must be a > prism image"); 1. this exception must be documented 2. what is a "prism image" from the user perspective? could the message be rephrased to give the user a better understanding? modules/javafx.graphics/src/test/java/test/com/sun/javafx/geom/Path2DTest.java line 209: > 207: } > 208: } > 209: RectBounds rectBounds = new RectBounds(10, 20, 20, 30); seems unrelated, but I would rather clean up this unused code. modules/javafx.graphics/src/test/java/test/com/sun/prism/sw/SWDrawingContextTest.java line 89: > 87: } > 88: catch (Exception e) { > 89: throw new IllegalStateException(e); illegal state? is this the right exception for the occasion? ------------- PR Review: https://git.openjdk.org/jfx/pull/1969#pullrequestreview-5071567871 PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r3898647857 PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r3898676684 PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r3898742884 PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r3898778737 PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r3898801577 PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r3898829408
