Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <script src =../../resources/testharness.js></script> | |
| 3 <script src =../../resources/testharnessreport.js></script> | |
| 4 <body> | |
| 5 <canvas id="output"></canvas> | |
| 6 </body> | |
| 7 <script> | |
| 8 | |
| 9 // When WebGL contexts are created with preserveDrawingBuffer set | |
| 10 // to false, there is a risk that stream capture will occur after | |
| 11 // the canvas has cleared its contents. This test verifies that | |
| 12 // this is not the case. | |
| 13 | |
| 14 var canvas = document.getElementById('output'); | |
| 15 var framesToTest = 4; | |
| 16 const ON_DATA_AVAILABLE_THRESHOLD = 10; | |
| 17 | |
| 18 function drawWebGL() { | |
| 19 var gl = canvas.getContext('webgl', { preserveDrawingBuffer: false }); | |
| 20 gl.clearColor(0, 1, 0, 1); | |
| 21 gl.clear(gl.COLOR_BUFFER_BIT); | |
| 22 if (framesToTest > 0) | |
| 23 requestAnimationFrame(drawWebGL); | |
| 24 }; | |
| 25 | |
| 26 async_test(function(test) { | |
| 27 var video = document.createElement('video'); | |
| 28 var stream = canvas.captureStream(); | |
| 29 video.srcObject = stream; | |
| 30 recorder = new MediaRecorder(stream); | |
| 31 var testCtx = document.createElement('canvas').getContext('2d'); | |
| 32 | |
| 33 recorder.ondataavailable = function(event) { | |
| 34 if (event.data.size > ON_DATA_AVAILABLE_THRESHOLD) { | |
| 35 test.step(function() { | |
| 36 testCtx.drawImage(video, 0, 0); | |
|
emircan
2017/03/22 18:26:26
Sorry I forgot about this earlier when we talked a
| |
| 37 var data = testCtx.getImageData(0, 0, 1, 1).data; | |
| 38 // Equality is approximate because the video encoding is lossy. | |
| 39 assert_approx_equals(data[0], 0, 4, 'The red component.'); | |
| 40 assert_approx_equals(data[1], 255, 4, 'The green component.'); | |
| 41 assert_approx_equals(data[2], 0, 4, 'The blue component.'); | |
| 42 assert_approx_equals(data[3], 255, 4, 'The alpha component.'); | |
| 43 }); | |
| 44 framesToTest = framesToTest - 1 | |
| 45 if (framesToTest == 0) { | |
| 46 test.done(); | |
| 47 } | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 recorder.start(0); | |
| 52 drawWebGL(); | |
| 53 }, 'Encode succeeds with captureStream() on an animated canvas with WebGL.'); | |
| 54 | |
| 55 </script> | |
| OLD | NEW |