Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | <!-- |
michael@0 | 2 | Copyright (c) 2011 The Chromium Authors. All rights reserved. |
michael@0 | 3 | Use of this source code is governed by a BSD-style license that can be |
michael@0 | 4 | found in the LICENSE file. |
michael@0 | 5 | --> |
michael@0 | 6 | <!DOCTYPE html> |
michael@0 | 7 | <html> |
michael@0 | 8 | <head> |
michael@0 | 9 | <meta charset="utf-8"> |
michael@0 | 10 | <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
michael@0 | 11 | <script src="../../resources/js-test-pre.js"></script> |
michael@0 | 12 | <script src="../resources/webgl-test.js"></script> |
michael@0 | 13 | <script id="vshader" type="x-shader/x-vertex"> |
michael@0 | 14 | attribute vec3 pos; |
michael@0 | 15 | attribute vec4 colorIn; |
michael@0 | 16 | varying vec4 color; |
michael@0 | 17 | |
michael@0 | 18 | void main() |
michael@0 | 19 | { |
michael@0 | 20 | color = colorIn; |
michael@0 | 21 | gl_Position = vec4(pos.xyz, 1.0); |
michael@0 | 22 | } |
michael@0 | 23 | </script> |
michael@0 | 24 | |
michael@0 | 25 | <script id="fshader" type="x-shader/x-fragment"> |
michael@0 | 26 | precision mediump float; |
michael@0 | 27 | varying vec4 color; |
michael@0 | 28 | |
michael@0 | 29 | void main() |
michael@0 | 30 | { |
michael@0 | 31 | gl_FragColor = color; |
michael@0 | 32 | } |
michael@0 | 33 | </script> |
michael@0 | 34 | </head> |
michael@0 | 35 | <body> |
michael@0 | 36 | <canvas id="example" width="32px" height="32px"></canvas> |
michael@0 | 37 | <div id="description"></div> |
michael@0 | 38 | <div id="console"></div> |
michael@0 | 39 | <script> |
michael@0 | 40 | var successfullyParsed = false; |
michael@0 | 41 | |
michael@0 | 42 | // The below declarations need to be global for "shouldBe" to see them |
michael@0 | 43 | var gl = null; |
michael@0 | 44 | var array = null; |
michael@0 | 45 | var pixel = [ 0, 0, 0, 0 ]; |
michael@0 | 46 | var expectedColor = [ 0, 0, 0, 0 ]; |
michael@0 | 47 | |
michael@0 | 48 | function calculatePixelBytes(format, type) |
michael@0 | 49 | { |
michael@0 | 50 | var size = 0; |
michael@0 | 51 | switch (format) { |
michael@0 | 52 | case gl.ALPHA: |
michael@0 | 53 | size = 1; |
michael@0 | 54 | break; |
michael@0 | 55 | case gl.RGB: |
michael@0 | 56 | size = 3; |
michael@0 | 57 | break; |
michael@0 | 58 | case gl.RGBA: |
michael@0 | 59 | size = 4; |
michael@0 | 60 | break; |
michael@0 | 61 | default: |
michael@0 | 62 | return -1; |
michael@0 | 63 | } |
michael@0 | 64 | switch (type) { |
michael@0 | 65 | case gl.UNSIGNED_BYTE: |
michael@0 | 66 | break; |
michael@0 | 67 | case gl.UNSIGNED_SHORT_5_6_5: |
michael@0 | 68 | if (format != gl.RGB) |
michael@0 | 69 | return -1; |
michael@0 | 70 | size = 2; |
michael@0 | 71 | break; |
michael@0 | 72 | case gl.UNSIGNED_SHORT_4_4_4_4: |
michael@0 | 73 | case gl.UNSIGNED_SHORT_5_5_5_1: |
michael@0 | 74 | if (format != gl.RGBA) |
michael@0 | 75 | return -1; |
michael@0 | 76 | size = 2; |
michael@0 | 77 | break; |
michael@0 | 78 | default: |
michael@0 | 79 | return -1; |
michael@0 | 80 | } |
michael@0 | 81 | return size; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | function calculatePaddingBytes(bytesPerPixel, packAlignment, width) |
michael@0 | 85 | { |
michael@0 | 86 | var padding = 0; |
michael@0 | 87 | switch (packAlignment) { |
michael@0 | 88 | case 1: |
michael@0 | 89 | case 2: |
michael@0 | 90 | case 4: |
michael@0 | 91 | case 8: |
michael@0 | 92 | padding = (bytesPerPixel * width) % packAlignment; |
michael@0 | 93 | if (padding > 0) |
michael@0 | 94 | padding = packAlignment - padding; |
michael@0 | 95 | break; |
michael@0 | 96 | default: |
michael@0 | 97 | return -1; |
michael@0 | 98 | } |
michael@0 | 99 | return padding; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | function packColor(format, type, r, g, b, a) |
michael@0 | 103 | { |
michael@0 | 104 | // FIXME: not sure if the color packing is correct for UNSIGNED_SHORT_*. |
michael@0 | 105 | var color = [ 0, 0, 0, 0 ]; |
michael@0 | 106 | switch (type) { |
michael@0 | 107 | case gl.UNSIGNED_BYTE: |
michael@0 | 108 | switch (format) { |
michael@0 | 109 | case gl.ALPHA: |
michael@0 | 110 | color[0] = a; |
michael@0 | 111 | break; |
michael@0 | 112 | case gl.RGB: |
michael@0 | 113 | color[0] = r; |
michael@0 | 114 | color[1] = g; |
michael@0 | 115 | color[2] = b; |
michael@0 | 116 | break; |
michael@0 | 117 | case gl.RGBA: |
michael@0 | 118 | color[0] = r; |
michael@0 | 119 | color[1] = g; |
michael@0 | 120 | color[2] = b; |
michael@0 | 121 | color[3] = a; |
michael@0 | 122 | break; |
michael@0 | 123 | default: |
michael@0 | 124 | return null; |
michael@0 | 125 | } |
michael@0 | 126 | break; |
michael@0 | 127 | case gl.UNSIGNED_SHORT_5_6_5: |
michael@0 | 128 | if (format != gl.RGB) |
michael@0 | 129 | return null; |
michael@0 | 130 | r >>= 3; |
michael@0 | 131 | g >>= 2; |
michael@0 | 132 | b >>= 3; |
michael@0 | 133 | color[0] = (r << 11) + (g << 5) + b; |
michael@0 | 134 | break; |
michael@0 | 135 | case gl.UNSIGNED_SHORT_4_4_4_4: |
michael@0 | 136 | if (format != gl.RGBA) |
michael@0 | 137 | return null; |
michael@0 | 138 | r >>= 4; |
michael@0 | 139 | g >>= 4; |
michael@0 | 140 | b >>= 4; |
michael@0 | 141 | a >>= 4; |
michael@0 | 142 | color[0] = (r << 12) + (g << 8) + (b << 4) + a; |
michael@0 | 143 | break; |
michael@0 | 144 | case gl.UNSIGNED_SHORT_5_5_5_1: |
michael@0 | 145 | if (format != gl.RGBA) |
michael@0 | 146 | return null; |
michael@0 | 147 | r >>= 3; |
michael@0 | 148 | g >>= 3; |
michael@0 | 149 | b >>= 3; |
michael@0 | 150 | a >>= 7; |
michael@0 | 151 | color[0] = (r << 11) + (g << 6) + (b << 1) + a; |
michael@0 | 152 | break; |
michael@0 | 153 | Default: |
michael@0 | 154 | return null; |
michael@0 | 155 | } |
michael@0 | 156 | return color; |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | function runTestIteration(format, type, packAlignment, width, height) |
michael@0 | 160 | { |
michael@0 | 161 | debug("Testing PACK_ALIGNMENT = " + packAlignment + ", width = " + width + ", height = " + height); |
michael@0 | 162 | gl.clearColor(1, 0.4, 0, 1); |
michael@0 | 163 | gl.clear(gl.COLOR_BUFFER_BIT); |
michael@0 | 164 | gl.pixelStorei(gl.PACK_ALIGNMENT, packAlignment); |
michael@0 | 165 | glErrorShouldBe(gl, gl.NO_ERROR); |
michael@0 | 166 | var bytesPerPixel = calculatePixelBytes(format, type); |
michael@0 | 167 | var padding = calculatePaddingBytes(bytesPerPixel, packAlignment, width); |
michael@0 | 168 | var size = bytesPerPixel * width * height + padding * (height - 1); |
michael@0 | 169 | if (type != gl.UNSIGNED_BYTE) { |
michael@0 | 170 | throw "test error: only UNSIGNED_BYTE is valid to ReadPixels"; |
michael@0 | 171 | } |
michael@0 | 172 | if (size < 0) |
michael@0 | 173 | size = 0; |
michael@0 | 174 | array = new Uint8Array(size); |
michael@0 | 175 | gl.readPixels(0, 0, width, height, format, type, array); |
michael@0 | 176 | if (width < 0 || height < 0) { |
michael@0 | 177 | glErrorShouldBe(gl, gl.INVALID_VALUE); |
michael@0 | 178 | return; |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | glErrorShouldBe(gl, gl.NO_ERROR); |
michael@0 | 182 | if (!array.length) |
michael@0 | 183 | return; |
michael@0 | 184 | |
michael@0 | 185 | // Check the last pixel of the last row. |
michael@0 | 186 | var bytesPerRow = width * bytesPerPixel + padding; |
michael@0 | 187 | var pos = bytesPerRow * (height - 1) + (width - 1) * bytesPerPixel; |
michael@0 | 188 | var numComponents = bytesPerPixel; |
michael@0 | 189 | for (var i = 0; i < numComponents; ++i) |
michael@0 | 190 | pixel[i] = array[pos + i]; |
michael@0 | 191 | for (var i = numComponents; i < 4; ++i) |
michael@0 | 192 | pixel[i] = 0; |
michael@0 | 193 | expectedColor = packColor(format, type, 255, 102, 0, 255); |
michael@0 | 194 | shouldBeNonNull("expectedColor"); |
michael@0 | 195 | shouldBe("pixel", "expectedColor"); |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | description('Verify readPixels() works fine with various PACK_ALIGNMENT values.'); |
michael@0 | 199 | |
michael@0 | 200 | shouldBeNonNull("gl = initWebGL('example', 'vshader', 'fshader', [ 'pos', 'colorIn' ], [ 0, 0, 0, 1 ], 1)"); |
michael@0 | 201 | gl.disable(gl.BLEND); |
michael@0 | 202 | |
michael@0 | 203 | var formats = [ gl.RGBA ]; |
michael@0 | 204 | var formatNames = [ "RGBA" ]; |
michael@0 | 205 | |
michael@0 | 206 | for (var i = 0; i < formats.length; ++i) { |
michael@0 | 207 | var format = formats[i]; |
michael@0 | 208 | |
michael@0 | 209 | debug("Testing format = " + formatNames[i] + " and type = UNSIGNED_BYTE"); |
michael@0 | 210 | runTestIteration(format, gl.UNSIGNED_BYTE, 1, 1, 2); |
michael@0 | 211 | runTestIteration(format, gl.UNSIGNED_BYTE, 2, 1, 2); |
michael@0 | 212 | runTestIteration(format, gl.UNSIGNED_BYTE, 4, 1, 2); |
michael@0 | 213 | runTestIteration(format, gl.UNSIGNED_BYTE, 8, 1, 2); |
michael@0 | 214 | runTestIteration(format, gl.UNSIGNED_BYTE, 4, 2, 2); |
michael@0 | 215 | runTestIteration(format, gl.UNSIGNED_BYTE, 8, 2, 2); |
michael@0 | 216 | runTestIteration(format, gl.UNSIGNED_BYTE, 4, 3, 2); |
michael@0 | 217 | runTestIteration(format, gl.UNSIGNED_BYTE, 8, 3, 2); |
michael@0 | 218 | runTestIteration(format, gl.UNSIGNED_BYTE, 4, 4, 2); |
michael@0 | 219 | runTestIteration(format, gl.UNSIGNED_BYTE, 8, 4, 2); |
michael@0 | 220 | runTestIteration(format, gl.UNSIGNED_BYTE, 8, 5, 1); |
michael@0 | 221 | runTestIteration(format, gl.UNSIGNED_BYTE, 4, 5, 2); |
michael@0 | 222 | runTestIteration(format, gl.UNSIGNED_BYTE, 8, 5, 2); |
michael@0 | 223 | runTestIteration(format, gl.UNSIGNED_BYTE, 8, 6, 2); |
michael@0 | 224 | runTestIteration(format, gl.UNSIGNED_BYTE, 8, 7, 2); |
michael@0 | 225 | runTestIteration(format, gl.UNSIGNED_BYTE, 8, 8, 2); |
michael@0 | 226 | runTestIteration(format, gl.UNSIGNED_BYTE, 1, 0, 0); |
michael@0 | 227 | runTestIteration(format, gl.UNSIGNED_BYTE, 2, 0, 0); |
michael@0 | 228 | runTestIteration(format, gl.UNSIGNED_BYTE, 4, 0, 0); |
michael@0 | 229 | runTestIteration(format, gl.UNSIGNED_BYTE, 8, 0, 0); |
michael@0 | 230 | runTestIteration(format, gl.UNSIGNED_BYTE, 1, -1, 1); |
michael@0 | 231 | runTestIteration(format, gl.UNSIGNED_BYTE, 2, 1, -1); |
michael@0 | 232 | runTestIteration(format, gl.UNSIGNED_BYTE, 4, 0, -1); |
michael@0 | 233 | runTestIteration(format, gl.UNSIGNED_BYTE, 8, -1, -1); |
michael@0 | 234 | } |
michael@0 | 235 | |
michael@0 | 236 | successfullyParsed = true; |
michael@0 | 237 | </script> |
michael@0 | 238 | <script>finishTest();</script> |
michael@0 | 239 | </body> |
michael@0 | 240 | </html> |