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)
Tracking
()
People
(Reporter: lucas.a.polito, Unassigned)
Details
Attachments
(2 files)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:161.0) Gecko/20100101 Firefox/161.0
Steps to reproduce
- In
about:config, setgfx.canvas.accelerated.debugtotrue, so an accelerated canvas shows a green square in its top-right corner. - Open the attached
repro.html?src=offscreen. It renders 150 short labels once, each into its own 120 × 28OffscreenCanvas, then draws them rotated onto one full-window canvas every frame withdrawImage. Nothing is drawn into the small canvases after the first frame. - Wait about 3 seconds for the median frame time to show, and look at the canvas's top-right corner.
- Repeat with
?src=bitmap, which draws the same labels fromImageBitmaps made withtransferToImageBitmap().
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.
| Reporter | ||
Comment 1•9 days ago
|
||
Description
•