Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <html> | |
| 2 <head> | |
| 3 <script type="text/javascript"> | |
| 4 var frameCountWarmup = 5; | |
|
nduca
2011/12/21 20:24:23
You might want a
/**
* @fileoverview Blahblahblah
jbates
2011/12/22 02:41:17
Done.
| |
| 5 var frameCount = 0; | |
| 6 var numFrames = 0; | |
| 7 var inputDirty = false; | |
| 8 var inputHeavy = false; | |
| 9 var rafHeavy = false; | |
| 10 var paintHeavy = false; | |
| 11 var mode = "webgl"; | |
|
nduca
2011/12/21 20:24:23
single quotes in js
jbates
2011/12/22 02:41:17
Done.
| |
| 12 var delayTimeMS = 0; | |
| 13 var canvasWidth = 0; | |
| 14 var clearColorGreen = 0; | |
| 15 var gl = null; | |
| 16 var mouse_x = 0; | |
|
nduca
2011/12/21 20:24:23
mouseX, expect_y
jbates
2011/12/22 02:41:17
Done.
| |
| 17 var expect_y = 0; | |
| 18 | |
| 19 function getParam(key) { | |
|
nduca
2011/12/21 20:24:23
You'd be better served having this return a dictio
jbates
2011/12/22 02:41:17
Done.
| |
| 20 var query = window.location.href.split('?')[1]; | |
|
nduca
2011/12/21 20:24:23
window.location.query.substring(1)?
jbates
2011/12/22 02:41:17
Done.
| |
| 21 if(!query) | |
|
nduca
2011/12/21 20:24:23
On your linux box, run gjslint --strict --check_ht
jbates
2011/12/22 02:41:17
Done.
| |
| 22 return ""; | |
| 23 var params = query.split('&'); | |
| 24 for(var i = 0, len = params.length; i < len; i++) { | |
| 25 var pair = params[i].split('='); | |
| 26 if (key == pair[0]) | |
| 27 return pair[1]; | |
| 28 } | |
| 29 return ""; | |
| 30 } | |
| 31 | |
| 32 function parseParams() { | |
| 33 numFrames = parseInt(getParam("numFrames")); | |
| 34 expect_y = parseInt(getParam("y")); | |
| 35 inputDirty = (getParam("inputDirty") == "true"); | |
| 36 inputHeavy = (getParam("inputHeavy") == "true"); | |
| 37 rafHeavy = (getParam("rafHeavy") == "true"); | |
| 38 paintHeavy = (getParam("paintHeavy") == "true"); | |
|
nduca
2011/12/21 20:24:23
So you have to put &paintHeavy=true in the uri? Wh
jbates
2011/12/22 02:41:17
Done.
| |
| 39 mode = getParam("mode"); | |
| 40 delayTimeMS = parseInt(getParam("delayTimeMS")); | |
| 41 canvasWidth = parseInt(getParam("canvasWidth")); | |
| 42 clearColorGreen = parseInt(getParam("clearColorGreen")); | |
| 43 } | |
| 44 | |
| 45 function setCoordinates(e) { | |
| 46 // Ignore mouse events with wrong Y coordinate. | |
| 47 if (e.clientY != expect_y) | |
| 48 return; | |
| 49 | |
| 50 mouse_x = e.clientX; | |
| 51 if (inputDirty) { | |
| 52 document.getElementById("text").firstChild.nodeValue = | |
|
nduca
2011/12/21 20:24:23
nodeValue -> textContent
jbates
2011/12/22 02:41:17
Done.
| |
| 53 mouse_x.toString(); | |
| 54 } | |
| 55 if (inputHeavy) { | |
| 56 delay(delayTimeMS); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 function init() { | |
| 61 parseParams(); | |
| 62 | |
| 63 if (mode == "webgl") { | |
| 64 var canvas = document.getElementById("canvas"); | |
| 65 if (!canvas) | |
| 66 return false; | |
| 67 canvas.width = canvasWidth; | |
| 68 canvas.height = canvasWidth; | |
| 69 try { | |
| 70 gl = canvas.getContext("webgl", { antialias: true }); | |
| 71 } catch(e) {} | |
| 72 if (!gl) { | |
| 73 try { | |
| 74 gl = canvas.getContext("experimental-webgl"); | |
| 75 } catch(e) { | |
| 76 return false; | |
| 77 } | |
| 78 } | |
| 79 return true; | |
| 80 } else if (mode == "software") { | |
| 81 var table = document.getElementById("table"); | |
| 82 table.style.backgroundColor = '#ff00ff'; | |
| 83 return true; | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 function runTest() { | |
|
nduca
2011/12/21 20:24:23
by the name, i assumed this was called by dom auto
jbates
2011/12/22 02:41:17
Done.
| |
| 88 if (init()) | |
| 89 window.webkitRequestAnimationFrame(draw); | |
| 90 else | |
| 91 endTest(); | |
| 92 } | |
| 93 | |
| 94 function delay(milliseconds) { | |
|
nduca
2011/12/21 20:24:23
s/delay/sleep/?
jbates
2011/12/22 02:41:17
Done.
| |
| 95 var start = new Date(); | |
| 96 var now = null; | |
| 97 do { now = new Date(); } | |
|
nduca
2011/12/21 20:24:23
I think you can do this as two lines:
var start =
jbates
2011/12/22 02:41:17
Done.
| |
| 98 while (now - start < milliseconds); | |
| 99 } | |
| 100 | |
| 101 function xColorString() { | |
|
nduca
2011/12/21 20:24:23
pass in x_ instead and give this a sane name? Or j
jbates
2011/12/22 02:41:17
Done.
| |
| 102 var hexColor = mouse_x.toString(16); | |
| 103 var color = "#000000"; | |
| 104 return color.substring(0, 7 - hexColor.length) + hexColor; | |
| 105 } | |
| 106 | |
| 107 function draw() { | |
| 108 frameCount++; | |
| 109 if (frameCount == numFrames) { | |
| 110 endTest(); | |
| 111 } | |
| 112 | |
| 113 if (rafHeavy) { | |
| 114 delay(delayTimeMS); | |
| 115 } | |
| 116 | |
| 117 if (mode == "webgl") { | |
| 118 gl.viewport(0, 0, canvasWidth, canvasWidth); | |
| 119 if (paintHeavy) { | |
| 120 gl.clearColor(0, 0, 0.0, 1.0); | |
| 121 for (var i = 0; i < 1000; ++i) | |
| 122 gl.clear(gl.COLOR_BUFFER_BIT); | |
| 123 } | |
| 124 gl.clearColor(mouse_x, clearColorGreen, 0.0, 1.0); | |
| 125 gl.clear(gl.COLOR_BUFFER_BIT); | |
| 126 } else if (mode == "software") { | |
| 127 var table = document.getElementById("table"); | |
| 128 table.style.backgroundColor = xColorString(); | |
| 129 // When no inputs are coming in, the first table won't change. Since we | |
| 130 // still need to cause a paint, toggle the color of another element: | |
| 131 var table2 = document.getElementById("table2"); | |
| 132 table2.style.backgroundColor = (frameCount & 1) ? 'red' : 'black'; | |
| 133 if (paintHeavy) { | |
| 134 var body = document.getElementById("body"); | |
| 135 body.style.backgroundColor = (frameCount & 1) ? 'black' : 'red'; | |
| 136 } | |
| 137 } | |
| 138 | |
| 139 window.webkitRequestAnimationFrame(draw); | |
| 140 } | |
| 141 | |
| 142 function endTest() { | |
| 143 domAutomationController.setAutomationId(1); | |
| 144 domAutomationController.send("FINISHED"); | |
| 145 } | |
| 146 </script> | |
| 147 </head> | |
| 148 <body id="body" style="margin:0px" onload="runTest()" | |
| 149 onmousemove="setCoordinates(event)"> | |
| 150 <table id="table" width="10" height="10"><tr/></table> | |
|
nduca
2011/12/21 20:24:23
Any reason you're using a table rather than just a
jbates
2011/12/22 02:41:17
div didn't maintain its size for some reason, so I
| |
| 151 <table id="table2" width="10" height="10"><tr/></table> | |
| 152 <canvas id="canvas" width="10" height="10"></canvas> | |
|
nduca
2011/12/21 20:24:23
why initialize widths here if you initialize it up
jbates
2011/12/22 02:41:17
Done.
| |
| 153 <p><b id="text">x</b></p> | |
| 154 </body> | |
| 155 </html> | |
| OLD | NEW |