2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
10 <link rel=
"stylesheet" href=
"../../../resources/js-test-style.css"/>
11 <script src=
"../../../js/js-test-pre.js"></script>
12 <script src=
"../../../js/webgl-test-utils.js"></script>
15 <canvas id=
"c" width=
"16" height=
"16"></canvas>
16 <div id=
"description"></div>
17 <div id=
"console"></div>
20 description('Tests canvas remains unchanged after it is used in webgl texutre');
22 debug("This is a regression test for <a href='https://bugs.chromium.org/p/chromium/issues/detail?id=446380'>Chromium Issue 446380</a>");
25 var wtu
= WebGLTestUtils
;
26 var gl
= wtu
.create3DContext("c", undefined, 2);
28 function checkSourceCanvasImageData(imageDataBefore
, imageDataAfter
) {
29 if (imageDataBefore
.length
!= imageDataAfter
.length
) {
30 testFailed("The size of image data in source canvas become different after it is used in webgl texture.");
33 for (var i
= 0; i
< imageDataAfter
.length
; i
++) {
34 if (imageDataBefore
[i
] != imageDataAfter
[i
]) {
35 testFailed("Pixel values in source canvas have changed after canvas used in webgl texture.");
39 testPassed("Pixel values in source canvas remain unchanged after canvas used in webgl texture.");
42 function runTest(width
, height
) {
43 var canvas
= document
.createElement("canvas");
45 canvas
.height
= height
;
46 var ctx
= canvas
.getContext("2d");
47 ctx
.fillStyle
= "rgba(1, 63, 127, 1)";
48 ctx
.fillRect(0, 0, canvas
.width
, canvas
.height
);
49 var refCanvas
= document
.createElement("canvas");
50 refCanvas
.width
= width
;
51 refCanvas
.height
= height
;
52 var refCtx
= refCanvas
.getContext("2d");
53 refCtx
.fillStyle
= "rgba(1, 63, 127, 1)";
54 refCtx
.fillRect(0, 0, canvas
.width
, canvas
.height
);
55 // A refCanvas with same data as canvas is used to get original image data, since
56 // getImageData may change hardware accelerated status of canvas and we don't want to
57 // omit testing for hardware accelerated canvas.
58 var imageDataBefore
= refCtx
.getImageData(0, 0, refCanvas
.width
, refCanvas
.height
);
59 var tex
= gl
.createTexture();
60 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
61 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, gl
.RGBA
, gl
.UNSIGNED_BYTE
, canvas
);
62 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "TexImage2D should succeed");
63 checkSourceCanvasImageData(imageDataBefore
, ctx
.getImageData(0, 0, canvas
.width
, canvas
.height
));
64 gl
.deleteTexture(tex
);