Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1408)

Side by Side Diff: content/test/data/media/canvas_capture.html

Issue 2632593003: Notify listeners on OffScreenCanvas changes (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <title>Media Capture from DOM Elements (video/audio) Browser Test</title> 4 <title>Media Capture from Canvas ElementsBrowser Test</title>
5 </head> 5 </head>
6 <body> 6 <body>
7 <div> Capture and playback from video/audio elements.</div> 7 <div> Capture and playback from canvas elements.</div>
8 </body> 8 </body>
9 <script type="text/javascript" src="webrtc_test_utilities.js"></script> 9 <script type="text/javascript" src="webrtc_test_utilities.js"></script>
10 <script> 10 <script>
11 11
12 'use strict'; 12 'use strict';
13 13
14 const NUMBER_OF_EVENTS_TO_RECORD = 15; 14 const NUMBER_OF_EVENTS_TO_RECORD = 15;
15 const ON_DATA_AVAILABLE_THRESHOLD = 10; 15 const ON_DATA_AVAILABLE_THRESHOLD = 10;
16 16
17 function checkForRedraw(canvas, drawCounter, drawFunction) { 17 function checkForRedraw(canvas, drawCounter, drawFunction) {
18 if (++drawCounter <= NUMBER_OF_EVENTS_TO_RECORD) 18 if (++drawCounter <= NUMBER_OF_EVENTS_TO_RECORD)
19 requestAnimationFrame(function(){drawFunction(canvas, drawCounter)}) 19 requestAnimationFrame(function(){drawFunction(canvas, drawCounter)})
20 } 20 }
21 21
22 function draw2d(canvas, drawCounter) { 22 function draw2d(canvas, drawCounter) {
23 var ctx = canvas.getContext('2d'); 23 var ctx = canvas.getContext('2d');
24 ctx.fillStyle = 'green'; 24 ctx.fillStyle = 'green';
25 ctx.fillRect(0, 0, canvas.width, canvas.height); 25 ctx.fillRect(0, 0, canvas.width, canvas.height);
26 checkForRedraw(canvas, drawCounter, draw2d); 26 checkForRedraw(canvas, drawCounter, draw2d);
27 }; 27 };
28 28
29 function drawWebGL(canvas, drawCounter) { 29 function drawWebGL(canvas, drawCounter) {
30 var gl = canvas.getContext('webgl'); 30 var gl = canvas.getContext('webgl');
31 gl.clearColor(0, 1, 0, 1); 31 gl.clearColor(0, 1, 0, 1);
32 gl.clear(gl.COLOR_BUFFER_BIT); 32 gl.clear(gl.COLOR_BUFFER_BIT);
33 checkForRedraw(canvas, drawCounter, drawWebGL); 33 checkForRedraw(canvas, drawCounter, drawWebGL);
34 }; 34 };
35 35
36 function drawOffscreenCanvasCommit(canvas, drawCounter) {
37 var ctx = canvas.getContext('2d');
38 ctx.fillStyle = 'green';
39 ctx.fillRect(0, 0, canvas.width, canvas.height);
40 ctx.commit();
41 checkForRedraw(canvas, drawCounter, drawOffscreenCanvasCommit);
42 };
43
36 function testCanvasCapture(drawFunction) { 44 function testCanvasCapture(drawFunction) {
37 var canvas = document.createElement('canvas'); 45 var canvas = document.createElement('canvas');
46 canvas.width = canvas.height = 64;
38 document.body.appendChild(canvas); 47 document.body.appendChild(canvas);
39 48
40 var stream = canvas.captureStream(); 49 var stream = canvas.captureStream();
41 assertTrue(stream, 'Error creating MediaStream'); 50 assertTrue(stream, 'Error creating MediaStream');
42 assertEquals(1, stream.getVideoTracks().length); 51 assertEquals(1, stream.getVideoTracks().length);
43 assertEquals(0, stream.getAudioTracks().length); 52 assertEquals(0, stream.getAudioTracks().length);
44 53
45 var recorded_events = 0; 54 var recorded_events = 0;
46 const recorder = new MediaRecorder(stream); 55 const recorder = new MediaRecorder(stream);
47 assertTrue(recorder, 'Error creating recorder out of the MediaStream'); 56 assertTrue(recorder, 'Error creating recorder out of the MediaStream');
48 57
49 recorder.ondataavailable = function(event) { 58 recorder.ondataavailable = function(event) {
50 if (event.data.size > ON_DATA_AVAILABLE_THRESHOLD) { 59 if (event.data.size > ON_DATA_AVAILABLE_THRESHOLD) {
51 if (++recorded_events == NUMBER_OF_EVENTS_TO_RECORD) 60 if (++recorded_events == NUMBER_OF_EVENTS_TO_RECORD)
52 reportTestSuccess(); 61 reportTestSuccess();
53 } 62 }
54 }; 63 };
55 64
56 recorder.start(0); 65 recorder.start(0);
57 drawFunction(canvas, 0); 66 if (drawFunction.toString() == drawOffscreenCanvasCommit.toString()) {
67 var offscreen = canvas.transferControlToOffscreen();
68 drawFunction(offscreen, 0);
69 } else {
70 drawFunction(canvas, 0);
71 }
58 } 72 }
59 73
60 </script> 74 </script>
61 </body> 75 </body>
62 </html> 76 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698