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 src="../resources/webgl-test-utils.js"></script> |
michael@0 | 14 | <script> |
michael@0 | 15 | var wtu = WebGLTestUtils; |
michael@0 | 16 | var gl = null; |
michael@0 | 17 | var textureLoc = null; |
michael@0 | 18 | var successfullyParsed = false; |
michael@0 | 19 | var imgCanvas; |
michael@0 | 20 | var red = [255, 0, 0]; |
michael@0 | 21 | var green = [0, 255, 0]; |
michael@0 | 22 | |
michael@0 | 23 | function init() |
michael@0 | 24 | { |
michael@0 | 25 | if (window.initNonKhronosFramework) { |
michael@0 | 26 | window.initNonKhronosFramework(true); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | description('Verify texImage2D and texSubImage2D code paths taking Images'); |
michael@0 | 30 | |
michael@0 | 31 | gl = wtu.create3DContext("example"); |
michael@0 | 32 | var program = wtu.setupTexturedQuad(gl); |
michael@0 | 33 | |
michael@0 | 34 | gl.clearColor(0,0,0,1); |
michael@0 | 35 | gl.clearDepth(1); |
michael@0 | 36 | |
michael@0 | 37 | textureLoc = gl.getUniformLocation(program, "tex"); |
michael@0 | 38 | |
michael@0 | 39 | wtu.loadTexture(gl, "../resources/red-green.png", runTest); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | // These two declarations need to be global for "shouldBe" to see them |
michael@0 | 43 | var buf = null; |
michael@0 | 44 | var idx = 0; |
michael@0 | 45 | var pixel = [0, 0, 0]; |
michael@0 | 46 | var correctColor = null; |
michael@0 | 47 | |
michael@0 | 48 | function runOneIteration(image, useTexSubImage2D, flipY, topColor, bottomColor) |
michael@0 | 49 | { |
michael@0 | 50 | debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') + |
michael@0 | 51 | ' with flipY=' + flipY); |
michael@0 | 52 | gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
michael@0 | 53 | // Disable any writes to the alpha channel |
michael@0 | 54 | gl.colorMask(1, 1, 1, 0); |
michael@0 | 55 | var texture = gl.createTexture(); |
michael@0 | 56 | // Bind the texture to texture unit 0 |
michael@0 | 57 | gl.bindTexture(gl.TEXTURE_2D, texture); |
michael@0 | 58 | // Set up texture parameters |
michael@0 | 59 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
michael@0 | 60 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
michael@0 | 61 | // Set up pixel store parameters |
michael@0 | 62 | gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY); |
michael@0 | 63 | gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false); |
michael@0 | 64 | gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE); |
michael@0 | 65 | // Upload the image into the texture |
michael@0 | 66 | if (useTexSubImage2D) { |
michael@0 | 67 | // Initialize the texture to black first |
michael@0 | 68 | gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, image.width, image.height, 0, |
michael@0 | 69 | gl.RGBA, gl.UNSIGNED_BYTE, null); |
michael@0 | 70 | gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, image); |
michael@0 | 71 | } else { |
michael@0 | 72 | gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | // Point the uniform sampler to texture unit 0 |
michael@0 | 76 | gl.uniform1i(textureLoc, 0); |
michael@0 | 77 | // Draw the triangles |
michael@0 | 78 | wtu.drawQuad(gl, [0, 0, 0, 255]); |
michael@0 | 79 | // Check a few pixels near the top and bottom and make sure they have |
michael@0 | 80 | // the right color. |
michael@0 | 81 | debug("Checking lower left corner"); |
michael@0 | 82 | wtu.checkCanvasRect(gl, 4, 4, 2, 2, bottomColor, |
michael@0 | 83 | "shouldBe " + bottomColor); |
michael@0 | 84 | debug("Checking upper left corner"); |
michael@0 | 85 | wtu.checkCanvasRect(gl, 4, gl.canvas.height - 8, 2, 2, topColor, |
michael@0 | 86 | "shouldBe " + topColor); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | function runTestOnImage(image) { |
michael@0 | 90 | runOneIteration(image, false, true, red, green); |
michael@0 | 91 | runOneIteration(image, false, false, green, red); |
michael@0 | 92 | runOneIteration(image, true, true, red, green); |
michael@0 | 93 | runOneIteration(image, true, false, green, red); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | function runTest(image) |
michael@0 | 97 | { |
michael@0 | 98 | runTestOnImage(image); |
michael@0 | 99 | |
michael@0 | 100 | imgCanvas = document.createElement("canvas"); |
michael@0 | 101 | imgCanvas.width = 1; |
michael@0 | 102 | imgCanvas.height = 2; |
michael@0 | 103 | var imgCtx = imgCanvas.getContext("2d"); |
michael@0 | 104 | var imgData = imgCtx.createImageData(1, 2); |
michael@0 | 105 | imgData.data[0] = red[0]; |
michael@0 | 106 | imgData.data[1] = red[1]; |
michael@0 | 107 | imgData.data[2] = red[2]; |
michael@0 | 108 | imgData.data[3] = 255; |
michael@0 | 109 | imgData.data[4] = green[0]; |
michael@0 | 110 | imgData.data[5] = green[1]; |
michael@0 | 111 | imgData.data[6] = green[2]; |
michael@0 | 112 | imgData.data[7] = 255; |
michael@0 | 113 | imgCtx.putImageData(imgData, 0, 0); |
michael@0 | 114 | |
michael@0 | 115 | // apparently Image is different than <img>. |
michael@0 | 116 | var newImage = new Image(); |
michael@0 | 117 | newImage.onload = function() { |
michael@0 | 118 | runTest2(newImage); |
michael@0 | 119 | }; |
michael@0 | 120 | newImage.src = imgCanvas.toDataURL(); |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | function runTest2(image) { |
michael@0 | 124 | runTestOnImage(image); |
michael@0 | 125 | |
michael@0 | 126 | var newImage = document.createElement("img"); |
michael@0 | 127 | newImage.onload = function() { |
michael@0 | 128 | runTest3(newImage); |
michael@0 | 129 | }; |
michael@0 | 130 | newImage.src = imgCanvas.toDataURL(); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | function runTest3(image) { |
michael@0 | 134 | runTestOnImage(image); |
michael@0 | 135 | |
michael@0 | 136 | glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors"); |
michael@0 | 137 | finishTest(); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | </script> |
michael@0 | 141 | </head> |
michael@0 | 142 | <body onload="init()"> |
michael@0 | 143 | <canvas id="example" width="32px" height="32px"></canvas> |
michael@0 | 144 | <div id="description"></div> |
michael@0 | 145 | <div id="console"></div> |
michael@0 | 146 | </body> |
michael@0 | 147 | </html> |
michael@0 | 148 | |
michael@0 | 149 |