Closed Bug 1950085 Opened 20 days ago Closed 18 days ago

canvas.drawImage() doesn’t render SVG with clip-path and mix-blend-mode as expected

Categories

(Core :: Graphics: Canvas2D, defect)

Firefox 135
Desktop
All
defect

Tracking

()

RESOLVED FIXED
137 Branch
Tracking Status
firefox-esr115 --- wontfix
firefox-esr128 --- wontfix
firefox135 --- wontfix
firefox136 --- wontfix
firefox137 --- fixed

People

(Reporter: account-bugzilla, Assigned: lsalzman)

References

(Blocks 1 open bug, Regression)

Details

(Keywords: regression)

Attachments

(7 files)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36

Steps to reproduce:

Load an SVG image with an <img /> tag. The loaded SVG contains a clip-path that is applied to a group. Inside the group, there is an image element that is rendered with a mix-blend-mode.

  • USerAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:135.0) Gecko/20100101 Firefox/135.0
  • Browser: Firefox 135.0.1
  • Operating System: Mac OS 15.3 (24D60)
  • Hardware: Apple M3 Pro

Actual results:

When using this SVG image and rendering it on a canvas with drawImage(), the offset of the clip-path to the right and bottom is displayed as a stretched image.

Expected results:

The result of drawImage() should render the image on the canvas exactly as the original image.

The screenshot shows the actual rendering issue in Firefox. At the top, there is an <img> element that loads the SVG. This image is then used to call drawImage() on the <canvas> element, which is rendered at the bottom.

Status: UNCONFIRMED → NEW
Ever confirmed: true
OS: Unspecified → All
Hardware: Unspecified → Desktop
Blocks: gpu-canvas
Component: Untriaged → Graphics: Canvas2D
Product: Firefox → Core

Set release status flags based on info from the regressing bug 1910138

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

For more information, please visit BugBot documentation.

Timothy, this seems like a bug in SVG rendering.

Severity: -- → S3
Flags: needinfo?(lsalzman) → needinfo?(tnikkel)
Assignee: nobody → lsalzman
Status: NEW → ASSIGNED

I need to clarify my description of the bug. After further testing, I’ve realized that it is not related to clip-path. Instead, it is specifically caused by mix-blend-mode applied to a group. As a result, the actual positions of the objects inside the group are lost, causing them to shift to the coordinate origin (top/left = 0,0). This leads to an offset on the bottom/right, appearing as a glitch/distortion. I will add an other example...

Attached file Archive 2.zip

A new example with mix-blend-mode only.

Attached image mix-blend-mode-only.png

The left side shows the SVG loaded into an <img>, while the right side displays the SVG rendered on a <canvas> using canvasContext2d.drawImage().

Pushed by lsalzman@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/555f78811ae0 Handle offset surfaces in DrawTargetWebgl::DrawSurface. r=aosmond
Status: ASSIGNED → RESOLVED
Closed: 18 days ago
Resolution: --- → FIXED
Target Milestone: --- → 137 Branch

The patch landed in nightly and beta is affected.
:lsalzman, is this bug important enough to require an uplift?

  • If yes, please nominate the patch for beta approval.
  • If no, please set status-firefox136 to wontfix.

For more information, please visit BugBot documentation.

Flags: needinfo?(lsalzman)

:smolnar, I've tested the nightly build 137.0a1 (2025-02-26) with my attached file Archive2.zip. The positioning works fine, but there is still a glitch with on the border of the shape... see screenshot

For offset surfaces, the source rect to DrawSurface may not actually be entirely filled by
the surface's contents. In this case, we need to clip the source and dest rects to reflect
the actual surface content bounds.

This required some collateral modifications to make using offset surfaces safe in a few other
places in DrawTargets in general.

Pushed by lsalzman@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/5587ed6a3e35 Ensure DrawTargetWebgl::DrawSurface clips drawing to surface bounds. r=aosmond
Flags: needinfo?(tnikkel)
Flags: needinfo?(lsalzman)
Flags: qe-verify+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: