Bug 240380

Summary: Capturing a canvas that is not in the DOM can lead to erratic frame rates or no frame emission at all
Product: WebKit Reporter: youenn fablet <youennf>
Component: MediaAssignee: Dan Glastonbury <djg>
Status: RESOLVED FIXED    
Severity: Normal CC: claudio.destro, eric.carlson, kkinnunen, sabouhallawa, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   

Description youenn fablet 2022-05-13 05:05:20 PDT
Capturing a canvas that is not in the DOM can lead to erratic frame rates or no frame emission at all
Comment 1 Radar WebKit Bug Importer 2022-05-13 05:05:45 PDT
<rdar://problem/93239022>
Comment 2 Said Abou-Hallawa 2022-05-13 11:49:39 PDT
Test case is https://jsfiddle.net/0b3dqxeg/
Comment 3 Claudio Destro 2022-05-16 23:10:56 PDT
Hi hope this helps:

in our solution, canvas with CSS fixed position works
Comment 4 Claudio Destro 2022-05-16 23:15:39 PDT
Example missing (sorry):

modify the test case to:

<canvas id="canvas2" style="position: fixed; bottom: 0; right: 0; width: 100px"></canvas>

videos still not playing in 15.4 desktop (they show a red background and nothing else happens)
Comment 5 youenn fablet 2022-05-17 02:39:00 PDT
I did some investigations:
- CanvasCaptureMediaStreamTrack::Source::canvasChanged is correctly called each time the not-in-dom canvas is changed but it returns early due to m_canvas->renderingContext()->needsPreparationForDisplay() returning true.
- Normally, the page will call updateRendering which will make the actual preparation happening, which in turn will tell CanvasCaptureMediaStreamTrack::Source to generate a frame. This is what happens when canvas is in the DOM. When canvas is not in the DOM, Page::updateRendering is not called as often and this impacts the canvas track frame rate.
Comment 6 Dan Glastonbury 2022-05-22 21:18:37 PDT
Pull request: https://github.com/WebKit/WebKit/pull/901
Comment 7 EWS 2022-05-25 20:16:07 PDT
Committed r294864 (250996@main): <https://commits.webkit.org/250996@main>

Reviewed commits have been landed. Closing PR #901 and removing active labels.