Open Bug 1424983 Opened 4 years ago Updated 4 years ago

[Moz2D] SVG Filter have no effect on the image if HWA is enabled


(Core :: Graphics, defect, P3)

28 Branch



Tracking Status
firefox-esr52 --- wontfix
firefox57 --- wontfix
firefox58 --- wontfix
firefox59 --- fix-optional
firefox60 --- fix-optional


(Reporter: r2drozdz, Unassigned)



(Keywords: regression, Whiteboard: [gfx-noted])


(1 file)

Attached image different_browsers.png
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36

Steps to reproduce:

Basically, open this codepen:

It contains a SVG with an image and simple filter applied.

Actual results:

In Firefox the filters have no effect on the image. In other browsers the image looks dramatically different. The cause of this is an optimisation that Firefox makes to its feColorMatrix filters. If they appear consecutively then it concatenates the matrices. But this is incorrect with some matrices that transform the colours outside of the 0 to 1 range which requires clamping of the colours. So in this example the first filter adds half to the red channel of the image (transforming to the range 0.5 to 1.5) and the second channel subtracts half. Clamping means this has the effect of setting R to min(R,0.5). The first filter subtracts half from the green channel (transforming to the range -0.5 to +0.5) and the second filter adds half. Clamping has the effect of setting G to max(G,0.5). The blue channel is slightly more complex. The first filter multiplies the blue channel by 2 and subtracts half (transforming to the range -0.5 to +1.5) and second filter divides by 2 and adds a quarter. Clamping has the effect of setting B to max(0.25,min(B,0.75)).

So when Firefox concatenates these two color matrices, they cancel out leaving no overall effect. Usually this concatenation of matrices is a good optimisation, but not when colours are transformed outside of the 0 to 1 range. I would suggest that Firefox should only concatenate matrices only if the first does not transform the primary colours outside of the 0 to 1 range.

Note that the clamping is very useful. I use feColorMatrix with clamping to determine the minimum and maximum of the R, G and B channels. But unfortunately because of this bug this fails in Firefox and I have no alternative way of achieving the same result using SVG filters.

Does Firefox optimise other SVG filters in the same way?

Expected results:

Filter should be applied on the image like in other browser (see image attached).
I can reproduce the problem on Nightly59.0a1 Windows10.

Regression window:

Suspect:Bug 924103, Bug 924102

And Disabling HWA fixes the problem.
Blocks: 924103, 924102
Ever confirmed: true
Keywords: regression
Version: 57 Branch → 28 Branch
Component: SVG → Graphics
Summary: SVG Filter have no effect on the image → [Moz2D] SVG Filter have no effect on the image if HWA is enabled
Your bunch of patch seems to cause the regression. Can you look into this?
Flags: needinfo?(mstange)
samw underlying cause as bug 1421537 perhaps?
It might be! It must be Direct2D that's doing the optimization internally, because on the Gecko / Moz2D side we intentionally don't collapse subsequent color matrix filters for exactly this reason.
Priority: -- → P3
Whiteboard: [gfx-noted]
Flags: needinfo?(mstange)
You need to log in before you can comment on or make changes to this bug.