summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/mozilla/tests/webgpu/webgpu/web_platform/canvas/getCurrentTexture.spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/mozilla/tests/webgpu/webgpu/web_platform/canvas/getCurrentTexture.spec.js')
-rw-r--r--testing/web-platform/mozilla/tests/webgpu/webgpu/web_platform/canvas/getCurrentTexture.spec.js75
1 files changed, 61 insertions, 14 deletions
diff --git a/testing/web-platform/mozilla/tests/webgpu/webgpu/web_platform/canvas/getCurrentTexture.spec.js b/testing/web-platform/mozilla/tests/webgpu/webgpu/web_platform/canvas/getCurrentTexture.spec.js
index 00e8c3ec24..729a7cdfaf 100644
--- a/testing/web-platform/mozilla/tests/webgpu/webgpu/web_platform/canvas/getCurrentTexture.spec.js
+++ b/testing/web-platform/mozilla/tests/webgpu/webgpu/web_platform/canvas/getCurrentTexture.spec.js
@@ -40,6 +40,27 @@ class GPUContextTest extends GPUTest {
return ctx;
}
+
+ expectTextureDestroyed(texture, expectDestroyed = true) {
+ this.expectValidationError(() => {
+ // Try using the texture in a render pass. Because it's a canvas texture
+ // it should have RENDER_ATTACHMENT usage.
+ assert((texture.usage & GPUTextureUsage.RENDER_ATTACHMENT) !== 0);
+ const encoder = this.device.createCommandEncoder();
+ const pass = encoder.beginRenderPass({
+ colorAttachments: [
+ {
+ view: texture.createView(),
+ loadOp: 'clear',
+ storeOp: 'store'
+ }]
+
+ });
+ pass.end();
+ // Submitting should generate a validation error if the texture is destroyed.
+ this.queue.submit([encoder.finish()]);
+ }, expectDestroyed);
+ }
}
export const g = makeTestGroup(GPUContextTest);
@@ -170,7 +191,7 @@ fn((t) => {
// Ensure that each frame a new texture object is returned.
t.expect(currentTexture !== prevTexture);
- // Ensure that texture contents are transparent black.
+ // Ensure that the texture's initial contents are transparent black.
t.expectSingleColor(currentTexture, currentTexture.format, {
size: [currentTexture.width, currentTexture.height, 1],
exp: { R: 0, G: 0, B: 0, A: 0 }
@@ -178,7 +199,8 @@ fn((t) => {
}
if (clearTexture) {
- // Clear the texture to test that texture contents don't carry over from frame to frame.
+ // Fill the texture with a non-zero color, to test that texture
+ // contents don't carry over from frame to frame.
const encoder = t.device.createCommandEncoder();
const pass = encoder.beginRenderPass({
colorAttachments: [
@@ -215,10 +237,8 @@ fn((t) => {
}
}
- // Call frameCheck for the first time from requestAnimationFrame
- // To make sure two frameChecks are run in different frames for onscreen canvas.
- // offscreen canvas doesn't care.
- requestAnimationFrame(frameCheck);
+ // Render the first frame immediately. The rest will be triggered recursively.
+ frameCheck();
});
});
@@ -235,6 +255,8 @@ fn((t) => {
// Trigger a resize by changing the width.
ctx.canvas.width = 4;
+ t.expectTextureDestroyed(prevTexture);
+
// When the canvas resizes the texture returned by getCurrentTexture should immediately begin
// returning a new texture matching the update dimensions.
let currentTexture = ctx.getCurrentTexture();
@@ -263,7 +285,6 @@ fn((t) => {
t.expect(currentTexture.height === ctx.canvas.height);
t.expect(prevTexture.width === 4);
t.expect(prevTexture.height === 2);
- prevTexture = currentTexture;
// Ensure that texture contents are transparent black.
t.expectSingleColor(currentTexture, currentTexture.format, {
@@ -271,13 +292,31 @@ fn((t) => {
exp: { R: 0, G: 0, B: 0, A: 0 }
});
- // Simply setting the canvas width and height values to their current values should not trigger
- // a change in the texture.
- ctx.canvas.width = 4;
- ctx.canvas.height = 4;
-
- currentTexture = ctx.getCurrentTexture();
- t.expect(prevTexture === currentTexture);
+ // HTMLCanvasElement behaves differently than OffscreenCanvas
+ if (t.params.canvasType === 'onscreen') {
+ // Ensure canvas goes back to defaults when set to negative numbers.
+ ctx.canvas.width = -1;
+ currentTexture = ctx.getCurrentTexture();
+ t.expect(currentTexture.width === 300);
+ t.expect(currentTexture.height === 4);
+
+ ctx.canvas.height = -1;
+ currentTexture = ctx.getCurrentTexture();
+ t.expect(currentTexture.width === 300);
+ t.expect(currentTexture.height === 150);
+
+ // Setting the canvas width and height values to their current values should
+ // still trigger a change in the texture.
+ prevTexture = ctx.getCurrentTexture();
+ const { width, height } = ctx.canvas;
+ ctx.canvas.width = width;
+ ctx.canvas.height = height;
+
+ t.expectTextureDestroyed(prevTexture);
+
+ currentTexture = ctx.getCurrentTexture();
+ t.expect(prevTexture !== currentTexture);
+ }
});
g.test('expiry').
@@ -307,6 +346,14 @@ u //
combine('prevFrameCallsite', ['runInNewCanvasFrame', 'requestAnimationFrame']).
combine('getCurrentTextureAgain', [true, false])
).
+beforeAllSubcases((t) => {
+ if (
+ t.params.prevFrameCallsite === 'requestAnimationFrame' &&
+ typeof requestAnimationFrame === 'undefined')
+ {
+ throw new SkipTestCase('requestAnimationFrame not available');
+ }
+}).
fn((t) => {
const { canvasType, prevFrameCallsite, getCurrentTextureAgain } = t.params;
const ctx = t.initCanvasContext(t.params.canvasType);