RFR: 8218973: SVG with masking is not rendering image with mask effect [v12]

Kevin Rushforth kcr at openjdk.java.net
Fri Sep 11 00:29:52 UTC 2020

On Tue, 8 Sep 2020 09:56:06 GMT, Bhawesh Choudhary <bchoudhary at openjdk.org> wrote:

>> Root cause of issue is Specifying a image mask from GraphicsContextJava.cpp in WebKit was not implemented, so masking
>> doesn't take place at all while rendering SVGRect. to fix this issue add implementation of function clipToImageBuffer()
>> in GraphicsContextJava.cpp and send clip image to WCGraphicsPrismContext.java  While rendering in
>> WCGraphicsPrismContext.java if image clip mask is available, use it for rendering using MaskTextureGraphics interface
>> otherwise use usual way of rendering.
> Bhawesh Choudhary has updated the pull request incrementally with one additional commit since the last revision:
>   Added unit test for strokes

modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCGraphicsPrismContext.java line 447:

> 445:     public void setClip(int cx, int cy, int cw, int ch, WCImage maskImage) {
> 446:         setClip(new Rectangle(cx, cy, cw, ch));
> 447:         state.setClipMaskImage(maskImage);

Should all of the other variants of setClip (the ones that don't take a maskImage) set the clipMaskImage to null?
Otherwise it seems that it might not be reset to null in all cases.

modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCGraphicsPrismContext.java line 520:

> 518:         state.apply(g1);
> 519:         g1.setPaint(paint);
> 520:         if(stroke != null) {

Minor: there should be a space after the `if`.

modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCGraphicsPrismContext.java line 524:

> 522:         }
> 523:         if (isFill) {
> 524:             g1.fill(shape);

This will call the slower `fill(Shape)` method in all cases rather than the specialized `fillRect` or `fillRoundRect`
method. Given all the other things that are done to draw a shape with a clip mask, I suspect that this is fine. One
thing to consider is to pass in an enum instead of a boolean. The enum could say whether to use the specialized calls
or the generic `fill` call. It's probably not worth the effort to make this change.

modules/javafx.web/src/test/java/test/javafx/scene/web/SVGTest.java line 164:

> 162:             final WebPage webPage = WebEngineShim.getPage(getEngine());
> 163:             assertNotNull(webPage);
> 164:             final BufferedImage img = WebPageShim.paint(webPage, 0, 0, 200, 200);

This is added to the (preexisting) problem of calling `paint` on the wrong thread. In this case, it doesn't seem to
cause any additional problems, and other tests in this same class do it, so we can fix this in the follow-on issue that
is already filed, [JDK-8252596](https://bugs.openjdk.java.net/browse/JDK-8252596).


PR: https://git.openjdk.java.net/jfx/pull/213

More information about the openjfx-dev mailing list