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

Side by Side Diff: conformance/resources/tex-image-and-sub-image-2d-with-video.js

Issue 42083002: Add ToT WebGL conformance tests : part 10 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/webgl/sdk/tests/
Patch Set: Created 7 years, 1 month 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
Property Changes:
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
OLDNEW
(Empty)
1 /*
2 ** Copyright (c) 2012 The Khronos Group Inc.
3 **
4 ** Permission is hereby granted, free of charge, to any person obtaining a
5 ** copy of this software and/or associated documentation files (the
6 ** "Materials"), to deal in the Materials without restriction, including
7 ** without limitation the rights to use, copy, modify, merge, publish,
8 ** distribute, sublicense, and/or sell copies of the Materials, and to
9 ** permit persons to whom the Materials are furnished to do so, subject to
10 ** the following conditions:
11 **
12 ** The above copyright notice and this permission notice shall be included
13 ** in all copies or substantial portions of the Materials.
14 **
15 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
22 */
23
24 // This block needs to be outside the onload handler in order for this
25 // test to run reliably in WebKit's test harness (at least the
26 // Chromium port). https://bugs.webkit.org/show_bug.cgi?id=87448
27 initTestingHarness();
28
29 var old = debug;
30 var debug = function(msg) {
31 console.log(msg);
32 old(msg);
33 };
34
35 function generateTest(pixelFormat, pixelType, prologue) {
36 var wtu = WebGLTestUtils;
37 var gl = null;
38 var textureLoc = null;
39 var successfullyParsed = false;
40
41 // Test each format separately because many browsers implement each
42 // differently. Some might be GPU accelerated, some might not. Etc...
43 var videos = [
44 { src: "../resources/red-green.mp4" , type: 'video/mp4; codecs="av c1.42E01E, mp4a.40.2"', },
45 { src: "../resources/red-green.webmvp8.webm", type: 'video/webm; codecs="v p8, vorbis"', },
46 { src: "../resources/red-green.theora.ogv", type: 'video/ogg; codecs="th eora, vorbis"', },
47 ];
48
49 var videoNdx = 0;
50 var video;
51
52 function runNextVideo() {
53 if (video) {
54 video.pause();
55 }
56
57 if (videoNdx == videos.length) {
58 finishTest();
59 return;
60 }
61
62 var info = videos[videoNdx++];
63 debug("");
64 debug("testing: " + info.type);
65 video = document.createElement("video");
66 var canPlay = true;
67 if (!video.canPlayType) {
68 testFailed("video.canPlayType required method missing");
69 runNextVideo();
70 return;
71 }
72
73 if(!video.canPlayType(info.type).replace(/no/, '')) {
74 debug(info.type + " unsupported");
75 runNextVideo();
76 return;
77 };
78
79 document.body.appendChild(video);
80 video.type = info.type;
81 video.src = info.src;
82 wtu.startPlayingAndWaitForVideo(video, runTest);
83 }
84
85 var init = function()
86 {
87 description('Verify texImage2D and texSubImage2D code paths taking video elements (' + pixelFormat + '/' + pixelType + ')');
88
89 gl = wtu.create3DContext("example");
90
91 if (!prologue(gl)) {
92 finishTest();
93 return;
94 }
95
96 var program = wtu.setupTexturedQuad(gl);
97
98 gl.clearColor(0,0,0,1);
99 gl.clearDepth(1);
100
101 textureLoc = gl.getUniformLocation(program, "tex");
102 runNextVideo();
103 }
104
105 function runOneIteration(videoElement, useTexSubImage2D, flipY, topColor, bo ttomColor)
106 {
107 debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') +
108 ' with flipY=' + flipY);
109 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
110 // Disable any writes to the alpha channel
111 gl.colorMask(1, 1, 1, 0);
112 var texture = gl.createTexture();
113 // Bind the texture to texture unit 0
114 gl.bindTexture(gl.TEXTURE_2D, texture);
115 // Set up texture parameters
116 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
117 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
118 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
119 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
120 // Set up pixel store parameters
121 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
122 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
123 // Upload the videoElement into the texture
124 if (useTexSubImage2D) {
125 // Initialize the texture to black first
126 gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat],
127 videoElement.videoWidth, videoElement.videoHeight, 0,
128 gl[pixelFormat], gl[pixelType], null);
129 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl[pixelFormat], gl[pixelTy pe], videoElement);
130 } else {
131 gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], gl[pixelFormat], gl [pixelType], videoElement);
132 }
133
134 var c = document.createElement("canvas");
135 c.width = 16;
136 c.height = 16;
137 c.style.border = "1px solid black";
138 var ctx = c.getContext("2d");
139 ctx.drawImage(videoElement, 0, 0, 16, 16);
140 document.body.appendChild(c);
141
142 // Point the uniform sampler to texture unit 0
143 gl.uniform1i(textureLoc, 0);
144 // Draw the triangles
145 wtu.clearAndDrawUnitQuad(gl, [0, 0, 0, 255]);
146 // Check a few pixels near the top and bottom and make sure they have
147 // the right color.
148 var tolerance = 5;
149 debug("Checking lower left corner");
150 wtu.checkCanvasRect(gl, 4, 4, 2, 2, bottomColor,
151 "shouldBe " + bottomColor, tolerance);
152 debug("Checking upper left corner");
153 wtu.checkCanvasRect(gl, 4, gl.canvas.height - 8, 2, 2, topColor,
154 "shouldBe " + topColor, tolerance);
155 }
156
157 function runTest(videoElement)
158 {
159 var red = [255, 0, 0];
160 var green = [0, 255, 0];
161 runOneIteration(videoElement, false, true, red, green);
162 runOneIteration(videoElement, false, false, green, red);
163 runOneIteration(videoElement, true, true, red, green);
164 runOneIteration(videoElement, true, false, green, red);
165
166 glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
167
168 runNextVideo();
169 }
170
171 return init;
172 }
OLDNEW
« no previous file with comments | « conformance/resources/tex-image-and-sub-image-2d-with-svg-image.js ('k') | conformance/resources/vertexShader.vert » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698