Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
|
bajones
2013/09/26 22:27:23
This test spins through random color clears on a c
| |
| 2 <html> | |
| 3 <head> | |
| 4 <title>Synchronized screenshot test</title> | |
| 5 <style> | |
| 6 html, body { margin: 0; } | |
| 7 #log { height: 150px; overflow: auto; width: 512px; } | |
| 8 #log.failed { background-color: #FFAAAA; } | |
| 9 </style> | |
| 10 </head> | |
| 11 <body> | |
| 12 <canvas id="src-canvas" width="256" height="256"></canvas> | |
| 13 <canvas id="dest-canvas" width="256" height="256"></canvas><br/> | |
| 14 <div id="log"></div> | |
| 15 | |
| 16 <script> | |
| 17 "use strict"; | |
| 18 | |
| 19 (function () { | |
| 20 var log = document.getElementById("log"); | |
| 21 var canvas1 = document.getElementById("src-canvas"); | |
| 22 var canvas2 = document.getElementById("dest-canvas"); | |
| 23 | |
| 24 if (!window.chrome || !window.chrome.gpuBenchmarking || | |
| 25 !window.chrome.gpuBenchmarking.beginWindowSnapshotPNG) { | |
| 26 canvas1.style.display = "none"; | |
| 27 canvas2.style.display = "none"; | |
| 28 log.innerHTML = "chrome.gpuBenchmarking.beginWindowSnapshotPNG not avail able.<br/>" + | |
| 29 "Please make sure Chrome was launched with --enable-gpu- benchmarking." | |
| 30 return; | |
| 31 } | |
| 32 | |
| 33 var totalTests = 100; | |
| 34 var testInterval = 75; | |
| 35 var testStartDelay = 1000; | |
| 36 var testCount = 0; | |
| 37 var allPassed = true; | |
| 38 | |
| 39 var ctx1 = canvas1.getContext("2d"); | |
| 40 var ctx2 = canvas2.getContext("2d"); | |
| 41 | |
| 42 var clearColor = [0, 0, 0]; | |
| 43 var screenshotClearColor = [0, 0, 0]; | |
| 44 var validatedColor = [0, 0, 0]; | |
| 45 function draw() { | |
| 46 if (testCount == totalTests || !allPassed) | |
| 47 return; | |
| 48 | |
| 49 clearColor[0] = Math.floor(Math.random() * 256.0); | |
| 50 clearColor[1] = Math.floor(Math.random() * 256.0); | |
| 51 clearColor[2] = Math.floor(Math.random() * 256.0); | |
| 52 | |
| 53 ctx1 | |
| 54 ctx1.fillStyle="RGB(" + | |
| 55 clearColor[0] + "," + | |
| 56 clearColor[1] + "," + | |
| 57 clearColor[2] + ")"; | |
| 58 ctx1.fillRect(0,0,canvas1.width,canvas1.height); | |
| 59 | |
| 60 window.requestAnimationFrame(draw); | |
| 61 }; | |
| 62 draw(); | |
| 63 | |
| 64 var snapshotImg = new Image(); | |
| 65 var snapshotBtn = document.getElementById("snapshot"); | |
| 66 var snapshotColorSpan = document.getElementById("snapshotColorSpan"); | |
| 67 var validatedColorSpan = document.getElementById("validatedColorSpan"); | |
| 68 | |
| 69 | |
| 70 function colorsMatch(a, b) { | |
| 71 return (Math.abs(a[0] - b[0]) < 2 && | |
| 72 Math.abs(a[1] - b[1]) < 2 && | |
| 73 Math.abs(a[2] - b[2]) < 2); | |
| 74 } | |
| 75 | |
| 76 function logTest(id, a, b) { | |
| 77 var entry = document.createElement("div"); | |
| 78 var match = colorsMatch(a, b); | |
| 79 entry.innerHTML = "Test " + id + ": " + | |
| 80 "[" + a[0] +", " + a[1] +", " + a[2] +"] " + | |
| 81 "~= " + | |
| 82 "[" + b[0] +", " + b[1] +", " + b[2] +"] " + | |
| 83 ": " + | |
| 84 (match ? "<b style='color: green'>Pass</b>" : "<b style='color: red'>F ail</b>"); | |
| 85 log.insertBefore(entry, log.firstChild); | |
| 86 return match; | |
| 87 } | |
| 88 | |
| 89 // Take snapshots at an arbitrary interval and ensure that the resulting | |
| 90 // image matches the color we last cleared the webgl canvas with | |
| 91 function testSnapshot() { | |
| 92 ++testCount; | |
| 93 | |
| 94 screenshotClearColor[0] = clearColor[0]; | |
| 95 screenshotClearColor[1] = clearColor[1]; | |
| 96 screenshotClearColor[2] = clearColor[2]; | |
| 97 | |
| 98 window.chrome.gpuBenchmarking.beginWindowSnapshotPNG( | |
| 99 function(s) { | |
| 100 snapshotImg.src = "data:image/png;base64," + s.data; | |
| 101 ctx2.drawImage(snapshotImg,0,0); | |
| 102 | |
| 103 var img_data = ctx2.getImageData(0, 0, 1, 1); | |
| 104 validatedColor[0] = img_data.data[0]; | |
| 105 validatedColor[1] = img_data.data[1]; | |
| 106 validatedColor[2] = img_data.data[2]; | |
| 107 | |
| 108 allPassed = allPassed && logTest(testCount, screenshotClearColor, va lidatedColor); | |
| 109 if (!allPassed) | |
| 110 log.classList.add("failed"); | |
| 111 | |
| 112 if (testCount < totalTests || !allPassed) | |
| 113 setTimeout(testSnapshot, testInterval); | |
| 114 } | |
| 115 ); | |
| 116 } | |
| 117 setTimeout(testSnapshot, testStartDelay); | |
| 118 })(); | |
| 119 </script> | |
| 120 </body> | |
| 121 </html> | |
| OLD | NEW |