Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Capturing a canvas that is not in the DOM can lead to erratic frame r…
…ates or no frame emission at all https://bugs.webkit.org/show_bug.cgi?id=240380 Patch by Dan Glastonbury <djg@apple.com> on 2022-05-25 Reviewed by Simon Fraser. * Source/WebCore/dom/Document.cpp: (WebCore::Document::canvasChanged): Schedule a rendering update whenever a canvas with out a rect needing display preparation is added. This ensures that the prepareForDisplay is called on all pending canvases, since this is handled in doAfterUpdateRendering. * Source/WebCore/dom/Document.h: Update size of RenderingUpdateState to accomodate PrepareCanvasesForDisplay. * Source/WebCore/page/Page.cpp: * Source/WebCore/page/Page.h: Introduce new RenderingUpdateStep, PrepareCanvasesForDisplay, which signals that prepareCanvasesForDisplayInNeeded() needs to be called from doAfterRenderingUpdate(). Update size of RenderingUpdateState to accomodate PrepareCanvasesForDisplay. * LayoutTests/fast/mediacapturefromelement/CanvasCaptureMediaStream-capture-out-of-DOM-canvas-expected.txt: Added. * LayoutTests/fast/mediacapturefromelement/CanvasCaptureMediaStream-capture-out-of-DOM-canvas.html: Test that frame rate of captured video from out-of-DOM canvas is with in 25% of the generating frame rate. Canonical link: https://commits.webkit.org/250996@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294864 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
1 parent
abe1582
commit 994751c42e3184931d43481820724f17d77f23ff
Showing
7 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,4 @@ | ||
|
||
|
||
PASS check frame of capture canvas is sufficient | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,46 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Capture canvas to video track framerate</title> | ||
<script src="../../resources/testharness.js"></script> | ||
<script src="../../resources/testharnessreport.js"></script> | ||
<script src="../../webrtc/routines.js"></script> | ||
</head> | ||
<body> | ||
<video id="video" autoplay playsInline controls width="200px"></video> | ||
<script> | ||
promise_test(async (t) => { | ||
const canvas = document.createElement('canvas'); | ||
canvas.width = 200; | ||
canvas.height = 200; | ||
|
||
const ctx = canvas.getContext('2d'); | ||
|
||
let frames = 0; | ||
const loop = () => { | ||
frames += 1; | ||
ctx.fillStyle = (ctx.fillStyle !== '#ff0000') ? 'red' : 'green'; | ||
ctx.fillRect(0, 0, canvas.width, canvas.height); | ||
setTimeout(loop, 1000/30); | ||
} | ||
|
||
loop(); | ||
|
||
const stream = canvas.captureStream(); | ||
video.srcObject = stream; | ||
video.play(); | ||
|
||
const frameRate = await computeFrameRate(stream, video); | ||
|
||
// If the test was unable to generate any frames then nothing meaningful can be determined. Our test only makes sense if we have sufficient fps. | ||
if (frames <= 10) | ||
return; | ||
|
||
// Check that the difference in expected and observed frame rates is < 25% | ||
const percentDiff = Math.abs(frameRate - frames) / frames * 100; | ||
assert_less_than(percentDiff, 25, `frame rate difference between ${frames} & ${frameRate} is below 25%`); | ||
}, "check frame of capture canvas is sufficient"); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters