On Tue, 20 Oct 2026 05:50:01 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. >> >> **New API for `GraphicsContext`** >> >> Because `GraphicsContext` was never designed to support a more generic API >> when it was conceived, it has gained a few new methods that were a better >> fit for the reusable `DrawingContext` interface: >> >> - `clipRect(x, y, w, h)` -- convenience equivalent to `rect(...)` + `clip()` >> - `getEffect()` -- no arg getter for the `Effect` >> - `getTextDirection()` and `setTextDirection(NodeOrientation)` -- takes >> precedence over `Canvas.getNodeOrientation()` when not set to `INHERIT` (the >> default) >> >> **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 four additional > commits since the last revision: > > - Fix proportional gradients for text > - Drop unnecessary applyStrokeParameters > - Document that self drawing is unspecified behavior. > - Fix code example More findings, but we are getting close. Question: why is rendering using the `DrawingContext` seems always blurry? <img width="877" height="574" alt="Image" src="https://github.com/user-attachments/assets/6e831a87-6ab0-4b33-88dc-140e29d74d72" /> https://github.com/andy-goryachev-oracle/Test/blob/ag.1969.drawing.context/src/goryachev/bugs/DrawingContext_8390915.java modules/javafx.graphics/src/main/java/com/sun/prism/sw/SWDrawingContext.java line 739: > 737: @Override > 738: public void strokeRoundRect(double x, double y, double w, double h, > double arcWidth, double arcHeight) { > 739: if (w != 0 || h != 0) { inconsistent check: see GraphicsContext:1646 modules/javafx.graphics/src/main/java/com/sun/prism/sw/SWDrawingContext.java line 829: > 827: > 828: private void strokePolyline(double[] xPoints, double[] yPoints, int > nPoints, boolean close) { > 829: if (xPoints != null && yPoints != null && nPoints >= 2 && > xPoints.length >= nPoints && yPoints.length >= nPoints) { difference in handling malformed arrays: GraphicsContext:738 throws AIOOBE, a no-op here. should it be addressed / documented? modules/javafx.graphics/src/main/java/javafx/scene/canvas/GraphicsContext.java line 1298: > 1296: */ > 1297: @Override > 1298: public void setTextDirection(NodeOrientation direction) { text direction attribute is missing from the table on L205 modules/javafx.graphics/src/main/native-prism-sw/JJavaSurface.c line 152: > 150: > 151: jint dataOffset = (*env)->GetIntField(env, surfaceHandle, > fieldIds[SURFACE_DATA_OFFSET]); > 152: jint* arrayData = (jint*)(*env)->GetPrimitiveArrayCritical(env, > surface->dataHandle, NULL); should you set super.data = NULL before `GetPrimitiveArrayCritical` ? modules/javafx.graphics/src/main/native-prism-sw/JJavaSurface.c line 171: > 169: (*env)->ReleasePrimitiveArrayCritical(env, surface->dataHandle, > surface->arrayData, 0); > 170: surface->arrayData = NULL; > 171: surface->dataHandle = NULL; should you set `super.data = NULL` here as well? modules/javafx.graphics/src/test/java/test/com/sun/javafx/geom/Path2DTest.java line 2: > 1: /* > 2: * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights > reserved. 2026 ------------- PR Review: https://git.openjdk.org/jfx/pull/1969#pullrequestreview-5591064719 PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r4330122759 PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r4330489396 PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r4330512776 PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r4329995934 PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r4330000200 PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r4329766174
