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

Side by Side Diff: LayoutTests/fast/canvas/webgl/resources/tex-image-and-sub-image-2d-with-svg-image.js

Issue 1315233003: WebGL's SVGImage buffer should be cleared (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: review comments Created 5 years, 3 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
« no previous file with comments | « no previous file | LayoutTests/fast/canvas/webgl/resources/transparent-green.svg » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 function generateTest(pixelFormat, pixelType, pathToTestRoot, prologue) { 1 function generateTest(pixelFormat, pixelType, pathToTestRoot, prologue) {
2 var wtu = WebGLTestUtils; 2 var wtu = WebGLTestUtils;
3 var gl = null; 3 var gl = null;
4 var textureLoc = null; 4 var textureLoc = null;
5 var successfullyParsed = false; 5 var successfullyParsed = false;
6 var imgCanvas; 6 var imgCanvas;
7 var red = [255, 0, 0]; 7 var black = [0, 0, 0];
8 var green = [0, 255, 0]; 8 var green = [0, 255, 0];
9 var image = new Image();
10 var imageLoaded = false;
11 var poisonImage = new Image();
12 var poisonImageLoaded = false;
9 13
10 var init = function() 14 var init = function()
11 { 15 {
12 if (window.initNonKhronosFramework) { 16 if (window.initNonKhronosFramework) {
13 window.initNonKhronosFramework(true); 17 window.initNonKhronosFramework(true);
14 } 18 }
15 19
16 description('Verify texImage2D and texSubImage2D code paths taking SVG imag e elements'); 20 description('Verify texImage2D and texSubImage2D code paths taking SVG imag e elements');
17 21
18 gl = wtu.create3DContext("example"); 22 gl = wtu.create3DContext("example");
19 23
20 if (!prologue(gl)) { 24 if (!prologue(gl)) {
21 finishTest(); 25 finishTest();
22 return; 26 return;
23 } 27 }
24 28
25 var program = wtu.setupTexturedQuad(gl); 29 var program = wtu.setupTexturedQuad(gl);
26 30
27 gl.clearColor(0,0,0,1); 31 gl.clearColor(0,0,0,1);
28 gl.clearDepth(1); 32 gl.clearDepth(1);
29 33
30 textureLoc = gl.getUniformLocation(program, "tex"); 34 textureLoc = gl.getUniformLocation(program, "tex");
31 35
32 var image = new Image();
33 image.width = 10; 36 image.width = 10;
34 image.height = 10; 37 image.height = 10;
35 image.onload = function () { 38 image.onload = function () {
36 runTest(image); 39 imageLoaded = true;
40 runTest();
37 } 41 }
38 image.src = pathToTestRoot + "/resources/red-green.svg"; 42 image.src = pathToTestRoot + "/resources/transparent-green.svg";
43
44 poisonImage.width = 10;
45 poisonImage.height = 10;
46 poisonImage.onload = function () {
47 poisonImageLoaded = true;
48 runTest();
49 }
50 poisonImage.src = pathToTestRoot + "/resources/red-green.svg";
51
39 } 52 }
40 53
41 function runOneIteration(image, useTexSubImage2D, flipY, topColor, bottomColor) 54 function runOneIteration(useTexSubImage2D, flipY, topColor, bottomColor)
42 { 55 {
43 debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') + 56 debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') +
44 ' with flipY=' + flipY); 57 ' with flipY=' + flipY);
45 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); 58 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
46 var texture = gl.createTexture(); 59 var texture = gl.createTexture();
47 // Bind the texture to texture unit 0. 60 // Bind the texture to texture unit 0.
48 gl.bindTexture(gl.TEXTURE_2D, texture); 61 gl.bindTexture(gl.TEXTURE_2D, texture);
49 // Set up texture parameters. 62 // Set up texture parameters.
50 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); 63 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
51 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); 64 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
52 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 65 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
53 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 66 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
54 // Set up pixel store parameters. 67 // Set up pixel store parameters.
55 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY); 68 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
56 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false); 69 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
57 gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE); 70 gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
58 // Upload the image into the texture. 71 // Upload the image into the texture.
59 if (useTexSubImage2D) { 72 if (useTexSubImage2D) {
60 // Initialize the texture to black first. 73 // Initialize the texture to black first.
61 gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], image.width, image.hei ght, 0, 74 gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], image.width, image.hei ght, 0,
62 gl[pixelFormat], gl[pixelType], null); 75 gl[pixelFormat], gl[pixelType], null);
76 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl[pixelFormat], gl[pixelType] , poisonImage);
63 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl[pixelFormat], gl[pixelType] , image); 77 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl[pixelFormat], gl[pixelType] , image);
64 } else 78 } else {
79 gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], gl[pixelFormat], gl[pi xelType], poisonImage);
65 gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], gl[pixelFormat], gl[pi xelType], image); 80 gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], gl[pixelFormat], gl[pi xelType], image);
81 }
66 82
67 // Point the uniform sampler to texture unit 0. 83 // Point the uniform sampler to texture unit 0.
68 gl.uniform1i(textureLoc, 0); 84 gl.uniform1i(textureLoc, 0);
69 // Draw the triangles. 85 // Draw the triangles.
70 wtu.drawQuad(gl, [0, 255, 0, 255]); 86 wtu.drawQuad(gl, [0, 255, 0, 255]);
71 // Check a few pixels near the top and bottom and make sure they have 87 // Check a few pixels near the top and bottom and make sure they have
72 // the right color. 88 // the right color.
73 debug("Checking lower left corner"); 89 debug("Checking lower left corner");
74 wtu.checkCanvasRect(gl, 4, 4, 2, 2, bottomColor, 90 wtu.checkCanvasRect(gl, 4, 4, 2, 2, bottomColor,
75 "shouldBe " + bottomColor); 91 "shouldBe " + bottomColor);
76 debug("Checking upper left corner"); 92 debug("Checking upper left corner");
77 wtu.checkCanvasRect(gl, 4, gl.canvas.height - 8, 2, 2, topColor, 93 wtu.checkCanvasRect(gl, 4, gl.canvas.height - 8, 2, 2, topColor,
78 "shouldBe " + topColor); 94 "shouldBe " + topColor);
79 } 95 }
80 96
81 function runTest(image) 97 function runTest()
82 { 98 {
83 runOneIteration(image, false, true, red, green); 99 if (!imageLoaded || !poisonImageLoaded)
84 runOneIteration(image, false, false, green, red); 100 return;
85 runOneIteration(image, true, true, red, green); 101
86 runOneIteration(image, true, false, green, red); 102 runOneIteration(false, true, black, green);
103 runOneIteration(false, false, green, black);
104 runOneIteration(true, true, black, green);
105 runOneIteration(true, false, green, black);
87 finishTest(); 106 finishTest();
88 } 107 }
89 108
90 return init; 109 return init;
91 } 110 }
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/fast/canvas/webgl/resources/transparent-green.svg » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698