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

Side by Side Diff: third_party/webgl/conformance-suites/1.0.0/conformance/canvas-test.html

Issue 9360034: Remove everthing except conformance tests in the deps/third_party/webgl (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/
Patch Set: Created 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 <!--
2 Copyright (c) 2009 The Chromium Authors. All rights reserved.
3 Use of this source code is governed by a BSD-style license that can be
4 found in the LICENSE file.
5 -->
6 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
7 "http://www.w3.org/TR/html4/loose.dtd">
8 <html>
9 <head>
10 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
11 <title>WebGL Canvas Conformance Tests</title>
12 <link rel="stylesheet" href="../resources/js-test-style.css"/>
13 <script src="../resources/desktop-gl-constants.js" type="text/javascript"></scri pt>
14 <script src="../resources/js-test-pre.js"></script>
15 <script src="resources/webgl-test.js"></script>
16 </head>
17 <body>
18 <div id="description"></div>
19 <div id="console"></div>
20 <canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
21 <canvas id="canvas2d" width="40" height="40"> </canvas>
22 <script>
23 if (window.initNonKhronosFramework) {
24 window.initNonKhronosFramework(true);
25 }
26
27 description("This test ensures WebGL implementations interact correctly with the canvas tag.");
28
29 debug("");
30 debug("Canvas.getContext");
31
32 var err;
33 var canvas = document.getElementById("canvas");
34 var canvas2d = document.getElementById("canvas2d");
35 var ctx2d = canvas2d.getContext("2d");
36 var gl = create3DContext(canvas);
37 if (!gl) {
38 testFailed("context does not exist");
39 } else {
40 testPassed("context exists");
41
42 debug("");
43 debug("Checking canvas and WebGL interaction");
44
45 // Check that a canvas with no width or height is 300x150 pixels
46 shouldBe('canvas.width', '300');
47 shouldBe('canvas.height', '150');
48
49 // Check get a 4 value gl parameter as a csv string.
50 function getValue4v(name) {
51 var v = gl.getParameter(name);
52 var result = '' +
53 v[0] + ',' +
54 v[1] + ',' +
55 v[2] + ',' +
56 v[3];
57 return result;
58 }
59
60 function getViewport() {
61 return getValue4v(gl.VIEWPORT);
62 }
63
64 function getClearColor() {
65 return getValue4v(gl.COLOR_CLEAR_VALUE);
66 }
67
68 function isAboutEqual(a, b) {
69 return Math.abs(a - b) < 0.01;
70 }
71
72 function isAboutEqualInt(a, b) {
73 return Math.abs(a - b) < 3;
74 }
75
76 function checkCanvasContentIs(r3d,g3d,b3d,a3d) {
77 var r2d;
78 var g2d;
79 var b2d;
80 var a2d;
81
82 function checkPixel(x, y, r3d,g3d,b3d,a3d) {
83 var offset = (y * 40 + x) * 4;
84 r2d = imgData.data[offset];
85 g2d = imgData.data[offset + 1];
86 b2d = imgData.data[offset + 2];
87 a2d = imgData.data[offset + 3];
88 //debug('' + x + ', ' + y + "(" + offset + ") = " + r2d + ", " + g2d + ", " + b2d + ", " + a2d);
89 return isAboutEqualInt(r2d, r3d) &&
90 isAboutEqualInt(g2d, g3d) &&
91 isAboutEqualInt(b2d, b3d) &&
92 isAboutEqualInt(a2d, a3d);
93 }
94
95 function checkPixels(r3d,g3d,b3d,a3d) {
96 return checkPixel(0, 0, r3d, g3d, b3d, a3d) &&
97 checkPixel(0, 39, r3d, g3d, b3d, a3d) &&
98 checkPixel(39, 0, r3d, g3d, b3d, a3d) &&
99 checkPixel(39, 39, r3d, g3d, b3d, a3d) &&
100 checkPixel(0, 0, r3d, g3d, b3d, a3d);
101 };
102
103 // Set to just take the color from the 3d canvas
104 ctx2d.globalCompositeOperation = 'copy';
105
106 // fill 2d canvas with orange
107 ctx2d.fillStyle = "rgb(255,192,128)";
108 ctx2d.fillRect (0, 0, 40, 40);
109
110 // get the image data
111 var imgData = ctx2d.getImageData(0, 0, 40, 40);
112
113 // check it got cleared.
114 if (!checkPixels(255, 192, 128, 255)) {
115 testFailed("unable to fill 2d context.");
116 return;
117 }
118
119 // draw 3d canvas on top.
120 ctx2d.drawImage(canvas, 0,0, 40, 40);
121
122 // get the image data
123 var imgData = ctx2d.getImageData(0, 0, 40, 40);
124
125 // Check it's the expected color.
126 if (!checkPixels(r3d, g3d, b3d, a3d)) {
127 testFailed("pixels are " + r2d + "," + g2d + "," + b2d + "," + a2d +
128 " expected " + r3d + "," + g3d + "," + b3d + "," + a3d);
129 } else {
130 testPassed("pixels are " + r3d + "," + g3d + "," + b3d + "," + a3d);
131 }
132 }
133
134 checkCanvasContentIs(0, 0, 0, 0);
135 shouldBe('getViewport()', '"0,0,300,150"');
136
137 // Change the display size of the canvas and check
138 // the viewport size does not change.
139 debug("");
140 debug("change display size of canvas and see that viewport does not change");
141 canvas.style.width = "100px";
142 canvas.style.height = "25px";
143 var intervalId;
144 intervalId = window.setInterval(function() {
145 if (canvas.clientWidth == 100 &&
146 canvas.clientHeight == 25) {
147 window.clearInterval(intervalId);
148 shouldBe('getViewport()', '"0,0,300,150"');
149 shouldBe('canvas.width', '300');
150 shouldBe('canvas.height', '150');
151
152 // Change the actual size of the canvas
153 // Check that the viewport does not change.
154 // Check that the clear color does not change.
155 // Check that the color mask does not change.
156 debug("");
157 debug("change the actual size of the canvas and see that the viewport does not change");
158 gl.clearColor(0.25, 0.5, 0.75, 1);
159 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
160 checkCanvasContentIs(64, 128, 192, 255);
161 gl.colorMask(0,0,0,0);
162 glErrorShouldBe(gl, gl.NO_ERROR, "No GL errors before resizing the canvas" );
163 canvas.width = 400;
164 canvas.height = 10;
165 err = gl.getError();
166 // Some implementations might lost the context when resizing
167 if (err != gl.CONTEXT_LOST_WEBGL) {
168 shouldBe("err", "gl.NO_ERROR");
169 var v = gl.getParameter(gl.COLOR_CLEAR_VALUE);
170 assertMsg(isAboutEqual(v[0], 0.25) &&
171 isAboutEqual(v[1], 0.5) &&
172 isAboutEqual(v[2], 0.75) &&
173 isAboutEqual(v[3], 1),
174 "gl.clearColor should not change after canvas resize");
175 v = gl.getParameter(gl.COLOR_WRITEMASK);
176 assertMsg(isAboutEqual(v[0], 0) &&
177 isAboutEqual(v[1], 0) &&
178 isAboutEqual(v[2], 0) &&
179 isAboutEqual(v[3], 0),
180 "gl.colorMask should not change after canvas resize");
181 shouldBe('getViewport()', '"0,0,300,150"');
182 checkCanvasContentIs(0, 0, 0, 0);
183 }
184
185 debug("");
186 finishTest();
187 }
188 }, 1000/30);
189 }
190 </script>
191 <script>
192 </script>
193
194 </body>
195 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698