Skip to content

Commit

Permalink
Remove OffscreenCanvas commit() requirement (#2848)
Browse files Browse the repository at this point in the history
The commit() method of OffscreenCanvas contexts was controversial and
has not been shipped by any browser. Rewrite the OffscreenCanvas tests
to not require it.

For background, see:
w3ctag/design-reviews#288
https://groups.google.com/a/chromium.org/d/topic/blink-dev/hRZ_P2o-aEk/discussion
  • Loading branch information
jdarpinian authored and kenrussell committed Apr 5, 2019
1 parent 34c1b95 commit f565809
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,37 @@
<script>
"use strict";
description("This test checks whether OffscreenCanvas webgl context honors the preserveDrawingBuffer flag.");
var wtu = WebGLTestUtils;

function getPixelsFromOffscreenWebgl(preserveFlag) {
const nextFrame = async () => new Promise(r => requestAnimationFrame(r));

async function getPixelsFromOffscreenWebgl(preserveFlag, color, msg) {
var canvas = document.createElement("canvas");
var offscreenCanvas = transferredOffscreenCanvasCreation(canvas, 10, 10);
var gl = offscreenCanvas.getContext("webgl", {preserveDrawingBuffer: preserveFlag});

// Draw some color on gl and commit
// Draw some color on gl
gl.clearColor(1, 0, 1, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.commit();

await nextFrame();
var pixels = new Uint8Array(4);
gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
return pixels;
wtu.checkCanvas(gl, color, msg);
}

if (!window.OffscreenCanvas) {
testPassed("No OffscreenCanvas support");
} else {
// Test if OffscreenCanvas.webgl retains context if preserveDrawingBuffer is true.
var pixelsPreserve = getPixelsFromOffscreenWebgl(true);
shouldBe(pixelsPreserve, [255,0,255,255]);

// Test if OffscreenCanvas.webgl loses context if presereDrawingbuffer is false.
var pixelsNoPreserve = getPixelsFromOffscreenWebgl(false);
shouldBe(pixelsNoPreserve, [0,0,0,0]);
}
(async () => {
if (!window.OffscreenCanvas) {
testPassed("No OffscreenCanvas support");
} else {
// Test if OffscreenCanvas.webgl retains context if preserveDrawingBuffer is true.
await getPixelsFromOffscreenWebgl(true, [255,0,255,255], "should be preserved");

var successfullyParsed = true;
// Test if OffscreenCanvas.webgl loses context if presereDrawingbuffer is false.
await getPixelsFromOffscreenWebgl(false, [0, 0, 0, 0], "should not be preserved");
finishTest();
}
})();

</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<html>
<head>
<meta charset="utf-8">
<title>Resizing Test for OffscreenCanvas</title>
<title>Resizing Test for OffscreenCanvas commit()</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
Expand All @@ -39,7 +39,7 @@
<div id="console"></div>
<script>
"use strict";
description("This test ensures that the OffscreenCanvas context returns the correct image size after resizing.");
description("This test ensures that the OffscreenCanvas context returns the correct image size after resizing and calling commit().");

function testResizeOnNewOffscreenCanvas() {
var canvas = new OffscreenCanvas(10, 20);
Expand Down Expand Up @@ -102,6 +102,9 @@
if (!window.OffscreenCanvas) {
testPassed("No OffscreenCanvas support");
finishTest();
} else if (!new OffscreenCanvas(10, 20).getContext("webgl").commit) {
testPassed("commit() not supported");
finishTest();
} else {
testResizeOnNewOffscreenCanvas();
testResizeOnTransferredOffscreenCanvas();
Expand Down
1 change: 0 additions & 1 deletion sdk/tests/js/tests/canvas-tests-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ var webgl1Methods = [
"vertexAttrib4fv",
"vertexAttribPointer",
"viewport",
"commit"
];

var webgl2Methods = [
Expand Down

0 comments on commit f565809

Please sign in to comment.