On Thu, 8 Oct 2026 07:26:40 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: > > Fix review comments modules/javafx.graphics/src/main/java/com/sun/prism/sw/SWDrawingContext.java line 602: > 600: transform.transform(src, 0, dst, 0, 4); > 601: > 602: double minX = Math.max(0, Math.floor(Math.min(Math.min(dst[0], > dst[2]), Math.min(dst[4], dst[6])))); what happens when the input is fractional? should this case be detected and handled similarly to what `Canvas` is doing (NGCanvas:716) modules/javafx.graphics/src/main/java/com/sun/prism/sw/SWDrawingContext.java line 1265: > 1263: > 1264: graphics.resetPaintBounds(); > 1265: graphics.drawTexture(tex, (float)dx, (float)dy, (float)(dx > + dw), (float)(dy + dh), (float)sx, (float)sy, (float)(sx + sw), (float)(sy + > sh)); should these coordinates account for `prismImage.getPixelScale()` ? modules/javafx.graphics/src/main/java/javafx/scene/canvas/GraphicsContext.java line 889: > 887: } > 888: > 889: @Override the superclass javadoc does not list the effect, which seems to be saved/restored in this class. modules/javafx.graphics/src/main/java/javafx/scene/canvas/GraphicsContext.java line 1544: > 1542: } > 1543: > 1544: @Override this method inherits javadoc that contradicts implementation (as Effect is also applied) modules/javafx.graphics/src/main/java/javafx/scene/image/DrawingContext.java line 1017: > 1015: * Clears a portion of the drawing surface with a transparent color > value. > 1016: * <p> > 1017: * This method is not affected by any of the rendering attributes. is this true? implementation seems to apply transform and clip. modules/javafx.graphics/src/test/java/test/com/sun/javafx/pgstub/StubToolkit.java line 672: > 670: } > 671: } > 672: else { this formatting really bothers me... https://www.oracle.com/java/technologies/javase/codeconventions-contents.html ------------- PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r4234648313 PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r4234651885 PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r4234701998 PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r4234689103 PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r4234670242 PR Review Comment: https://git.openjdk.org/jfx/pull/1969#discussion_r4234718082
