diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/canvas/test/webgl-mochitest/test_backbuffer_channels.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/canvas/test/webgl-mochitest/test_backbuffer_channels.html')
-rw-r--r-- | dom/canvas/test/webgl-mochitest/test_backbuffer_channels.html | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/dom/canvas/test/webgl-mochitest/test_backbuffer_channels.html b/dom/canvas/test/webgl-mochitest/test_backbuffer_channels.html new file mode 100644 index 0000000000..ef880f9c22 --- /dev/null +++ b/dom/canvas/test/webgl-mochitest/test_backbuffer_channels.html @@ -0,0 +1,111 @@ +<!DOCTYPE HTML> +<title>WebGL test: bug 958723</title> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<link rel="stylesheet" href="/tests/SimpleTest/test.css"> +<script src="driver-info.js"></script> +<script src="webgl-util.js"></script> +<body> +<script> + +function TestAttribs(attribs) { + ok(true, 'Testing attribs: ' + JSON.stringify(attribs)); + var canvas = document.createElement('canvas'); + var gl = canvas.getContext('experimental-webgl', attribs); + ok(gl, 'No tested attribs should result in failure to create a context'); + if (!gl) + return; + + var actual = gl.getContextAttributes(); + + ok(actual.alpha == attribs.alpha, + 'Resulting `alpha` should match request.'); + ok(actual.premultipliedAlpha == attribs.premultipliedAlpha, + 'Resulting `premultipliedAlpha` should match request.'); + ok(actual.preserveDrawingBuffer == attribs.preserveDrawingBuffer, + 'Resulting `preserveDrawingBuffer` should match request.'); + + // "The depth, stencil and antialias attributes, when set to true, are + // requests, not requirements." + if (!attribs.antialias) { + ok(!actual.antialias, 'No `antialias` if not requested.'); + } + if (!attribs.depth) { + ok(!actual.depth, 'No `depth` if not requested.'); + } + if (!attribs.stencil) { + ok(!actual.stencil, 'No `stencil` if not requested.'); + } + + var hasAlpha = !!gl.getParameter(gl.ALPHA_BITS); + var hasDepth = !!gl.getParameter(gl.DEPTH_BITS); + var hasStencil = !!gl.getParameter(gl.STENCIL_BITS); + var hasAntialias = !!gl.getParameter(gl.SAMPLES); + + ok(hasAlpha == actual.alpha, 'Bits should match `alpha` attrib.'); + ok(hasAntialias == actual.antialias, 'Bits should match `antialias` attrib.'); + ok(hasDepth == actual.depth, 'Bits should match `depth` attrib.'); + ok(hasStencil == actual.stencil, 'Bits should match `stencil` attrib.'); +} + +function CloneAttribs(attribs) { + return { + alpha: attribs.alpha, + antialias: attribs.antialias, + depth: attribs.depth, + premultipliedAlpha: attribs.premultipliedAlpha, + preserveDrawingBuffer: attribs.preserveDrawingBuffer, + stencil: attribs.stencil, + }; +} + +function SplitForAttrib(list, attrib) { + var ret = []; + + for (var i in list) { + var cur = list[i]; + if (cur[attrib]) + throw 'Attrib is already true.'; + + var clone = CloneAttribs(cur); + clone[attrib] = true; + + ret.push(cur); + ret.push(clone); + } + + return ret; +} + +function GenAttribList() { + var base = { + alpha: false, + antialias: false, + depth: false, + premultipliedAlpha: false, + preserveDrawingBuffer: false, + stencil: false, + }; + var list = [base]; + list = SplitForAttrib(list, 'alpha'); + list = SplitForAttrib(list, 'antialias'); + list = SplitForAttrib(list, 'depth'); + list = SplitForAttrib(list, 'premultipliedAlpha'); + list = SplitForAttrib(list, 'preserveDrawingBuffer'); + list = SplitForAttrib(list, 'stencil'); + + if (list.length != 1<<6) + throw 'Attribs list length wrong: ' + list.length; + + return list; +} + +var list = GenAttribList(); +for (var i in list) { + var attribs = list[i]; + TestAttribs(attribs); +} + +ok(true, 'Test complete.'); + +</script> + |