Closed Bug 1758968 Opened 2 years ago Closed 2 years ago

HTML Canvas clipping region is broken if shadows are present

Categories

(Core :: Graphics: Canvas2D, defect, P3)

24 Branch
Unspecified
Windows
defect

Tracking

()

RESOLVED FIXED
100 Branch
Tracking Status
firefox-esr91 --- wontfix
firefox98 --- wontfix
firefox99 --- fixed
firefox100 --- fixed

People

(Reporter: simon.sarris, Assigned: lsalzman)

References

(Regression)

Details

(Keywords: regression)

Attachments

(2 files)

Attached file shadowBug.html

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36

Steps to reproduce:

This can be easily reproduced with code such as:

<canvas id="canvas" style="border: solid 3px red; width:150px; height:150px;"></canvas>
<script>
var can = document.getElementById('canvas');
can.width = 300;
can.height = 300;
var ctx = can.getContext('2d');
ctx.scale(2,2); // higher density

ctx.shadowOffsetX = 24;
ctx.shadowOffsetY = 24;
ctx.shadowColor = 'blue';
ctx.shadowBlur = 20;
ctx.font = "24px sans-serif";

ctx.rect(40,40,40,40);
ctx.clip();

ctx.fillText("Some text", 50, 35);
ctx.fillRect(50,50,40,80);
<script>

You can see a live version of this bug, here: https://codepen.io/simonsarris/pen/YzEmLgo

I have also attached an .html file with commentary and a reference image for how it ought to look.

This is a serious bug for canvas users, so I suspect it may be a regression, but I have not looked at older versions of Firefox.

Actual results:

No clipping occurs.

Expected results:

Clipping.

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

Component: Untriaged → Canvas: 2D
Product: Firefox → Core
Severity: -- → S2
Priority: -- → P1

Lee, looks like we might want to get an assignee on this. Also feel free to adjust the P&S if you feel it is inaccurate.

Blocks: gfx-triage
Flags: needinfo?(lsalzman)

Does this happen only on Windows? Or other platforms? I can't reproduce on Linux.

Flags: needinfo?(lsalzman) → needinfo?(simon.sarris)

Have only tested in Windows 10, where it fails. It may be Windows specific.

Flags: needinfo?(simon.sarris)
Regressed by: 883004

Seems like this bug dates back to the original implementation in bug 883004.

OS: Unspecified → Windows
Priority: P1 → P3
Version: Firefox 98 → 24 Branch

:bas.schouten, since you are the author of the regressor, bug 883004, could you take a look?
For more information, please visit auto_nag documentation.

Flags: needinfo?(bas)

DrawSurfaceWithShadow is supposed to ignore transforms but still support clipping.
It appears that DrawTargetD2D1 for some reason never actually implemented clipping.

The DrawImage calls on the DC just need to happen within the bounds of PrepareForDrawing
and FinalizeDrawing. Since PrepareForDrawing handles the overriding of the blend mode
via SetPrimitiveBlend, we need to use DrawImage with D2D1_COMPOSITE_MODE_SOURCE_OVER
so that it will blend appropriately.

Assignee: nobody → lsalzman
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Flags: needinfo?(bas)
No longer blocks: gfx-triage
Pushed by lsalzman@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/a992c118a124
Clip drawing in DrawTargetD2D1::DrawSurfaceWithShadow. r=gfx-reviewers,nical
Has Regression Range: --- → yes
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 100 Branch

The patch landed in nightly and beta is affected.
:lsalzman, is this bug important enough to require an uplift?
If not please set status_beta to wontfix.

For more information, please visit auto_nag documentation.

Flags: needinfo?(lsalzman)

Comment on attachment 9267317 [details]
Bug 1758968 - Clip drawing in DrawTargetD2D1::DrawSurfaceWithShadow. r?jrmuizel

Beta/Release Uplift Approval Request

  • User impact if declined: Broken clipping of shadows in Canvas2D on Windows.
  • Is this code covered by automated tests?: Yes
  • Has the fix been verified in Nightly?: Yes
  • Needs manual test from QE?: No
  • If yes, steps to reproduce:
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky):
  • String changes made/needed:
Flags: needinfo?(lsalzman)
Attachment #9267317 - Flags: approval-mozilla-beta?

Comment on attachment 9267317 [details]
Bug 1758968 - Clip drawing in DrawTargetD2D1::DrawSurfaceWithShadow. r?jrmuizel

Approved for 99.0b4. Thanks.

Attachment #9267317 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: