From e0c8666e54430ab4378e316c2a2382b8d4a8a710 Mon Sep 17 00:00:00 2001 From: Christopher Cameron Date: Wed, 20 Sep 2023 15:16:15 +0200 Subject: [PATCH 1/5] Add drawingBufferStorage test --- .../2.0.0/conformance/canvas/00_test_list.txt | 1 + .../canvas/drawingbuffer-storage-test.html | 229 ++++++++++++++++++ 2 files changed, 230 insertions(+) create mode 100644 conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html diff --git a/conformance-suites/2.0.0/conformance/canvas/00_test_list.txt b/conformance-suites/2.0.0/conformance/canvas/00_test_list.txt index b1d74fca26..bd90b8a1c0 100644 --- a/conformance-suites/2.0.0/conformance/canvas/00_test_list.txt +++ b/conformance-suites/2.0.0/conformance/canvas/00_test_list.txt @@ -2,6 +2,7 @@ buffer-offscreen-test.html buffer-preserve-test.html canvas-test.html canvas-zero-size.html +drawingbuffer-storage-test.html drawingbuffer-static-canvas-test.html --min-version 1.0.2 drawingbuffer-hd-dpi-test.html drawingbuffer-test.html diff --git a/conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html b/conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html new file mode 100644 index 0000000000..b86415ebf7 --- /dev/null +++ b/conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html @@ -0,0 +1,229 @@ + + + + + + +WebGL drawingBufferStorage Conformance Tests + + + + + +
+
+ + + + From 288299532b2b04b70145873f1a6525900802815e Mon Sep 17 00:00:00 2001 From: Christopher Cameron Date: Wed, 20 Sep 2023 15:37:25 +0200 Subject: [PATCH 2/5] Update drawingBufferStorage tests --- .../canvas/drawingbuffer-storage-test.html | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html b/conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html index b86415ebf7..e03809c1d4 100644 --- a/conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html +++ b/conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html @@ -163,6 +163,7 @@ testFailed("context does not exist"); return; } + debug('Testing alpha:false'); // Report RGB8 for the format. shouldBe('gl.drawingBufferFormat', 'gl.RGB8'); @@ -176,7 +177,7 @@ var canvas = document.createElement("canvas"); canvas.width = 16; canvas.height = 16; - gl = wtu.create3DContext(canvas, {alpha:false}); + gl = wtu.create3DContext(canvas); if (!gl) { testFailed("context does not exist"); return; @@ -191,7 +192,7 @@ var canvas = document.createElement("canvas"); canvas.width = 16; canvas.height = 16; - gl = wtu.create3DContext(canvas, {alpha:false}); + gl = wtu.create3DContext(canvas); if (!gl) { testFailed("context does not exist"); return; @@ -200,16 +201,16 @@ debug('Testing maximum size'); gl.drawingBufferStorage(gl.RGBA8, maxRenderbufferSize, maxRenderbufferSize); shouldBe('gl.getError()', 'gl.NONE'); - - debug('Testing over-maximum width'); - gl.drawingBufferStorage(gl.RGBA8, maxRenderbufferSize+1, 16); - shouldBe('gl.getError()', 'gl.INVALID_VALUE'); - - debug('Testing over-maximum height'); - gl.drawingBufferStorage(gl.RGBA8, 16, maxRenderbufferSize+1); - shouldBe('gl.getError()', 'gl.INVALID_VALUE'); shouldBe('gl.drawingBufferWidth', 'maxRenderbufferSize'); shouldBe('gl.drawingBufferHeight', 'maxRenderbufferSize'); + + debug('Testing over-maximum width and ehgith'); + gl.drawingBufferStorage(gl.RGBA8, maxRenderbufferSize+1, 16); + shouldBe('gl.getError()', 'gl.INVALID_VALUE'); + gl.drawingBufferStorage(gl.RGBA8, 16, maxRenderbufferSize+1); + shouldBe('gl.getError()', 'gl.INVALID_VALUE'); + shouldBe('gl.drawingBufferWidth', 'maxRenderbufferSize'); + shouldBe('gl.drawingBufferHeight', 'maxRenderbufferSize'); } var wtu = WebGLTestUtils; From 2469589403a24e5c090c933a4ed19ca520bd4d35 Mon Sep 17 00:00:00 2001 From: Christopher Cameron Date: Wed, 20 Sep 2023 20:29:02 +0200 Subject: [PATCH 3/5] Include draw to canvas --- .../canvas/drawingbuffer-storage-test.html | 121 +++++++++++++----- 1 file changed, 88 insertions(+), 33 deletions(-) diff --git a/conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html b/conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html index e03809c1d4..7a2272b494 100644 --- a/conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html +++ b/conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html @@ -89,32 +89,6 @@ return 1.0; } -function testClear(f, size, clearColor, expectedPixel, tolerance) { - format = f; - width = size[0]; - height = size[1]; - - gl.drawingBufferStorage(format, width, height); - shouldBe('gl.getError()', 'gl.NO_ERROR'); - - shouldBe('gl.drawingBufferFormat', 'format'); - shouldBe('gl.drawingBufferWidth', 'width'); - shouldBe('gl.drawingBufferHeight', 'height'); - - gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]); - gl.clear(gl.COLOR_BUFFER_BIT); - - var buf; - if (format == gl.RGBA16F) { - buf = new Float32Array(4); - gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.FLOAT, buf); - } else { - buf = new Uint8Array(4); - gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf); - } - testPixel(expectedPixel, buf, tolerance); -} - function testClearColor() { // Make a fresh canvas. var canvas = document.createElement("canvas"); @@ -129,24 +103,51 @@ testPassed("context exists"); shouldBe('gl.drawingBufferFormat', 'gl.RGBA8'); - if (!(`drawingBufferStorage` in gl)) { - testPassed("drawingBufferStorage not present -- skipping test"); - return; + let testCase = function(f, size, clearColor, expectedPixel, tolerance) { + format = f; + width = size[0]; + height = size[1]; + + gl.drawingBufferStorage(format, width, height); + shouldBe('gl.getError()', 'gl.NO_ERROR'); + + shouldBe('gl.drawingBufferFormat', 'format'); + shouldBe('gl.drawingBufferWidth', 'width'); + shouldBe('gl.drawingBufferHeight', 'height'); + + gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]); + gl.clear(gl.COLOR_BUFFER_BIT); + + var buf; + if (format == gl.RGBA16F) { + buf = new Float32Array(4); + gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.FLOAT, buf); + } else { + buf = new Uint8Array(4); + gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf); + } + testPixel(expectedPixel, buf, tolerance); } - testPassed("context has drawingBufferStorage"); + debug('Testing RGBA8'); - testClear(gl.RGBA8, [16, 32], [16 / 255, 32 / 255, 64 / 255, 128 / 255], [16, 32, 64, 128], 0); + testCase(gl.RGBA8, [16, 32], + [16 / 255, 32 / 255, 64 / 255, 128 / 255], + [16, 32, 64, 128], + 0); debug('Testing SRGB8_ALPHA8'); - testClear(gl.SRGB8_ALPHA8, [16, 32], + testCase(gl.SRGB8_ALPHA8, [16, 32], [srgbToLinear(64/255), srgbToLinear(16/255), srgbToLinear(32/255), 128 / 255], [64, 16, 32, 128], 1); if (gl.getExtension('EXT_color_buffer_float')) { debug('Testing RGBA16F'); - testClear(gl.RGBA16F, [18, 28], [0.25, 0.5, 0.75, 0.125], [0.25, 0.5, 0.75, 0.125], 0.00001); + testCase(gl.RGBA16F, [18, 28], + [0.25, 0.5, 0.75, 0.125], + [0.25, 0.5, 0.75, 0.125], + 0.00001); } else { debug('Skipping RGBA16F'); } @@ -213,6 +214,59 @@ shouldBe('gl.drawingBufferHeight', 'maxRenderbufferSize'); } +function testDrawToCanvas() { + let canvasGL = document.createElement("canvas"); + canvasGL.width = 16; + canvasGL.height = 16; + gl = wtu.create3DContext(canvasGL); + if (!gl) { + testFailed("context does not exist"); + return; + } + + let canvas2D = document.createElement("canvas"); + canvas2D.width = 16; + canvas2D.height = 16; + let ctx = canvas2D.getContext('2d'); + let imageData = new ImageData(16, 16); + + let testCase = function(f, clearColor, canvasColor, tolerance) { + gl.drawingBufferStorage(f, 16, 16); + gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]); + gl.clear(gl.COLOR_BUFFER_BIT); + + ctx.putImageData(imageData, 0, 0); + ctx.drawImage(canvasGL, 0, 0); + testPixel(canvasColor, ctx.getImageData(8, 8, 1, 1).data, tolerance); + } + + debug('Drawing RGBA to canvas'); + testCase(gl.RGBA8, [16/255, 32/255, 64/255, 64/255], [64, 128, 255, 64], 0); + + debug('Drawing opaque SRGB8_ALPHA8 to canvas'); + testCase(gl.SRGB8_ALPHA8, + [srgbToLinear(64/255), srgbToLinear(32/255), srgbToLinear(16/255), 1.0], + [64, 32, 16, 255], + 1); + + debug('Drawing transparent SRGB8_ALPHA8 to canvas'); + // We set the tolerance to 5 because of compounding error. The backbuffer + // may be off by 1, and then un-premultiplying alpha of 64/55 will multiply + // that error by 4. Then add one to be safe. + testCase(gl.SRGB8_ALPHA8, + [srgbToLinear(32/255), srgbToLinear(64/255), srgbToLinear(16/255), 64/255], + [128, 255, 64, 64], + 5); + + if (gl.getExtension('EXT_color_buffer_float')) { + debug('Drawing transparent RGBA16F to canvas'); + testCase(gl.RGBA16F, + [32/255, 64/255, 16/255, 64/255], + [128, 255, 64, 64], + 1); + } +} + var wtu = WebGLTestUtils; initialize(); if (hasDrawingBufferStorage) { @@ -220,6 +274,7 @@ testNoAlpha(); testMissingExtension(); testMaxSize(); + testDrawToCanvas(); } debug("") From 43f4003f8ea60f8ee52f6e6b8b1d90b457c705ce Mon Sep 17 00:00:00 2001 From: Christopher Cameron Date: Wed, 20 Sep 2023 20:50:20 +0200 Subject: [PATCH 4/5] Fix lint errors --- .../conformance/canvas/drawingbuffer-storage-test.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html b/conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html index 7a2272b494..00afb90ca6 100644 --- a/conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html +++ b/conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html @@ -234,17 +234,17 @@ gl.drawingBufferStorage(f, 16, 16); gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]); gl.clear(gl.COLOR_BUFFER_BIT); - + ctx.putImageData(imageData, 0, 0); ctx.drawImage(canvasGL, 0, 0); testPixel(canvasColor, ctx.getImageData(8, 8, 1, 1).data, tolerance); } - + debug('Drawing RGBA to canvas'); testCase(gl.RGBA8, [16/255, 32/255, 64/255, 64/255], [64, 128, 255, 64], 0); debug('Drawing opaque SRGB8_ALPHA8 to canvas'); - testCase(gl.SRGB8_ALPHA8, + testCase(gl.SRGB8_ALPHA8, [srgbToLinear(64/255), srgbToLinear(32/255), srgbToLinear(16/255), 1.0], [64, 32, 16, 255], 1); From 586a8067865f9effe65ed5c8ee7547c5b688c755 Mon Sep 17 00:00:00 2001 From: Kenneth Russell Date: Thu, 21 Sep 2023 23:36:49 -0700 Subject: [PATCH 5/5] Minor fixups before merging --- .../2.0.0/conformance/canvas/00_test_list.txt | 1 - .../conformance2/canvas/00_test_list.txt | 1 + .../canvas/drawingbuffer-storage-test.html | 40 +++++-------------- 3 files changed, 10 insertions(+), 32 deletions(-) rename {conformance-suites/2.0.0/conformance => sdk/tests/conformance2}/canvas/drawingbuffer-storage-test.html (82%) diff --git a/conformance-suites/2.0.0/conformance/canvas/00_test_list.txt b/conformance-suites/2.0.0/conformance/canvas/00_test_list.txt index bd90b8a1c0..b1d74fca26 100644 --- a/conformance-suites/2.0.0/conformance/canvas/00_test_list.txt +++ b/conformance-suites/2.0.0/conformance/canvas/00_test_list.txt @@ -2,7 +2,6 @@ buffer-offscreen-test.html buffer-preserve-test.html canvas-test.html canvas-zero-size.html -drawingbuffer-storage-test.html drawingbuffer-static-canvas-test.html --min-version 1.0.2 drawingbuffer-hd-dpi-test.html drawingbuffer-test.html diff --git a/sdk/tests/conformance2/canvas/00_test_list.txt b/sdk/tests/conformance2/canvas/00_test_list.txt index 35e011f3bf..878a2797c4 100644 --- a/sdk/tests/conformance2/canvas/00_test_list.txt +++ b/sdk/tests/conformance2/canvas/00_test_list.txt @@ -1 +1,2 @@ +--min-version 2.0.1 drawingbuffer-storage-test.html --min-version 2.0.1 to-data-url-with-pack-params.html diff --git a/conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html b/sdk/tests/conformance2/canvas/drawingbuffer-storage-test.html similarity index 82% rename from conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html rename to sdk/tests/conformance2/canvas/drawingbuffer-storage-test.html index 00afb90ca6..8c07b7a750 100644 --- a/conformance-suites/2.0.0/conformance/canvas/drawingbuffer-storage-test.html +++ b/sdk/tests/conformance2/canvas/drawingbuffer-storage-test.html @@ -1,30 +1,8 @@ - @@ -52,7 +30,7 @@ function initialize() { var canvas = document.createElement("canvas"); - gl = wtu.create3DContext(canvas, {antialias: false}); + gl = wtu.create3DContext(canvas, {antialias: false}, 2); if (!gl) { testFailed("context does not exist"); return [0, 0]; @@ -95,7 +73,7 @@ canvas.width = 16; canvas.height = 16; - gl = wtu.create3DContext(canvas, {antialias: false}); + gl = wtu.create3DContext(canvas, {antialias: false}, 2); if (!gl) { testFailed("context does not exist"); return; @@ -159,7 +137,7 @@ var canvas = document.createElement("canvas"); canvas.width = 16; canvas.height = 16; - gl = wtu.create3DContext(canvas, {alpha:false}); + gl = wtu.create3DContext(canvas, {alpha:false}, 2); if (!gl) { testFailed("context does not exist"); return; @@ -178,7 +156,7 @@ var canvas = document.createElement("canvas"); canvas.width = 16; canvas.height = 16; - gl = wtu.create3DContext(canvas); + gl = wtu.create3DContext(canvas, undefined, 2); if (!gl) { testFailed("context does not exist"); return; @@ -193,7 +171,7 @@ var canvas = document.createElement("canvas"); canvas.width = 16; canvas.height = 16; - gl = wtu.create3DContext(canvas); + gl = wtu.create3DContext(canvas, undefined, 2); if (!gl) { testFailed("context does not exist"); return; @@ -218,7 +196,7 @@ let canvasGL = document.createElement("canvas"); canvasGL.width = 16; canvasGL.height = 16; - gl = wtu.create3DContext(canvasGL); + gl = wtu.create3DContext(canvasGL, undefined, 2); if (!gl) { testFailed("context does not exist"); return;