Open Bug 2097484 Opened 9 days ago Updated 8 days ago

Drawing an unchanged OffscreenCanvas or `<canvas>` with drawImage re-sends its pixels on every call, and the accelerated canvas falls back to software for good

Categories

(Core :: Graphics: Canvas2D, defect)

Firefox 160
defect

Tracking

()

UNCONFIRMED

People

(Reporter: lucas.a.polito, Unassigned)

Details

Attachments

(2 files)

Attached file HTML and JS repro —

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:161.0) Gecko/20100101 Firefox/161.0

Steps to reproduce

  1. In about:config, set gfx.canvas.accelerated.debug to true, so an accelerated canvas shows a green square in its top-right corner.
  2. Open the attached repro.html?src=offscreen. It renders 150 short labels once, each into its own 120 × 28 OffscreenCanvas, then draws them rotated onto one full-window canvas every frame with drawImage. Nothing is drawn into the small canvases after the first frame.
  3. Wait about 3 seconds for the median frame time to show, and look at the canvas's top-right corner.
  4. Repeat with ?src=bitmap, which draws the same labels from ImageBitmaps made with transferToImageBitmap().

Actual results

With ?src=offscreen (and ?src=canvas, which uses <canvas> elements), the green square disappears after the first frames and the canvas is drawn in software for as long as the page is open: 33.3 ms median frames for both, on a 2× Retina window at 1440 × 900 in Playwright's Firefox 159. The profiler shows RecordedSourceSurfaceCreation and memory copies under every drawImage, and PCanvas::Msg_AddBuffer sending the pixels to the GPU process, though the source canvases haven't changed. With ?src=bitmap, the canvas stays accelerated, at 16.7 ms (60 fps).

Expected results

Drawing an unchanged canvas again reuses the copy already sent, as with an ImageBitmap, so pre-rendering into a canvas (as MDN advises) doesn't move the destination canvas to software.

Also seen: the move to software is permanent, even when only the first frames fail. In a real app (Feels on Wheels), the first spin after loading renders hundreds of new labels, and the canvas never comes back to the GPU after that, though later frames would pass. With gfx.canvas.accelerated.profile-frames set to 0, it runs at 60 fps on the GPU instead of 20 fps in software on a 2019 MacBook Pro.

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

Attachment

General

Creator:
Created:
Updated:
Size: