Closed Bug 1874314 Opened 2 years ago Closed 2 years ago

Accelerated Canvas 2D - Large Anti-Aliasing Error

Categories

(Core :: Graphics: Canvas2D, defect)

Firefox 121
defect

Tracking

()

VERIFIED FIXED
129 Branch
Tracking Status
firefox-esr115 --- wontfix
firefox-esr128 --- verified
firefox127 --- wontfix
firefox128 --- wontfix
firefox129 --- verified
firefox130 --- verified

People

(Reporter: tomxor, Assigned: lsalzman)

References

(Regression)

Details

(Keywords: regression)

Attachments

(2 files)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0

Steps to reproduce:

Set up a canvas and 2d context. Draw a rectangle with the parameters (0.5, 0.5, 1e-5, 64)

Actual results:

A highly visible line is drawn.

Expected results:

The command should barely affect the pixels if at all.

This is dependent on layers.acceleration.disabled=false (the default), and the position starting on a non-integer value, the effect being most prominent at +-0.5, +-0.5. The canvas must also be at least 2^14 pixels (64KB).

This affects more than fillRect. I've also found it to affect at least fillPath and strokePath with exactly the same behaviour in terms of sensitivity to the position of the upper left extents of the rendered shape.

The attached test case is a series of such thin fillRect commands between 0 and 1 width, starting at the centre of each pixel on the first row. This should render a linear gradient to demonstrate anti-aliasing behaviour. The pixels on the left half are the result of a single fillRect command between 0 and 0.5 width, but they all behave the same as 0.5 width, as if they are being ceiled.

Similarly you can replace the width X/W in the test case with 1e-5 and it will render a dark grey block.

In both cases if the 0.5 offset is removed from X and Y, or layers.acceleration.disabled is set to true, the error disappears.

The Bugbug bot thinks this bug should belong to the 'Core::Graphics: Canvas2D' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Graphics: Canvas2D
Product: Firefox → Core

:lsalzman, since you are the author of the regressor, bug 1773712, could you take a look? Also, could you set the severity field?

For more information, please visit BugBot documentation.

Flags: needinfo?(lsalzman)

Hi Timothy

Note that I discovered this on Linux. On the other hand, I noticed this regress quite a while ago when some new acceleration configs were flipped on by default which sounds very much the same as that MacOS issue... At the time I just flipped it back off because I didn't have the time to dig into it.

Good point. There would be a similar preference flip for the same thing but on Linux at a different time in a different bug. You could find that if you like but I think knowing what caused this to regress is enough.

We hit this issue in production, causing our rectangles to be blurred. It seems related to the new GPU canvas implementation. The workaround is to turn off GPU accel in FF settings, which isn't something we can recommend to our users. In the meantime we turned off GPU accel on canvas context with:

canvas.getContext("2d", { willReadFrequently: true })
Blocks: gfx-triage
Severity: -- → S2
Flags: needinfo?(lsalzman)

The existing distance-to-edge AA scheme breaks down somewhat when rectangles
have subpixel areas. We need to bias the AA to account for this situation when
the scales get to these subpixel sizes.

Assignee: nobody → lsalzman
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
No longer blocks: gfx-triage
Pushed by lsalzman@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/70079816fdc3 Better anti-aliasing for subpixel rectangles. r=aosmond
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 129 Branch

Reproducible on Firefox 128.0 on Ubuntu 22 using the testcase from Comment 0.
Verified as fixed on Firefox 129.0b2 and Firefox Nightly 130.0a1 on Ubuntu 22, macOS 14, Windows 10.

Status: RESOLVED → VERIFIED
Flags: qe-verify+
Regressions: 1911019

Please nominate this and bug 1911019 for ESR128 approval when you get a chance. They graft cleanly.

Flags: needinfo?(lsalzman)
Flags: needinfo?(lsalzman)

Comment on attachment 9409931 [details]
Bug 1874314 - Better anti-aliasing for subpixel rectangles. r?aosmond

ESR Uplift Approval Request

  • If this is not a sec:{high,crit} bug, please state case for ESR consideration: Rendering artifacts in Canvas2D.
  • User impact if declined: Rendering artifacts in Canvas2D.
  • Fix Landed on Version: 129
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): Seems stable in nightly.
Attachment #9409931 - Flags: approval-mozilla-esr128?

It should be noted that the follow-up in bug 1911019 is also required to uplift to ESR to fully fix this.

Comment on attachment 9409931 [details]
Bug 1874314 - Better anti-aliasing for subpixel rectangles. r?aosmond

Approved for 128.2esr.

Attachment #9409931 - Flags: approval-mozilla-esr128? → approval-mozilla-esr128+

Reproducible on Firefox 128.0 on Ubuntu 22 using the testcase from Comment 0.
Verified as fixed on Firefox ESR 128.2.0 on Ubuntu 22, macOS 14, Windows 10.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: