From 0cb00a6e89d83d4e16e6616f7af8819bd894b0da Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Sun, 22 Sep 2024 09:10:54 +0530 Subject: BREAKING(webgpu/unstable): move `width` and `height` options to `UnsafeWindowSurface` constructor (#24200) Fixes https://github.com/denoland/deno/issues/23508 `width` and `height` are required to configure the wgpu surface because Deno is headless and depends on user to create a window. The options were non-standard extension of `GPUCanvasConfiguration#configure`. This PR adds a required options parameter with the `width` and `height` options to `Deno.UnsafeWindowSurface` constructor. ```typescript // Old, non-standard extension of GPUCanvasConfiguration const surface = new Deno.UnsafeWindowSurface("x11", displayHandle, windowHandle); const context = surface.getContext(); context.configure({ width: 600, height: 800, /* ... */ }); ``` ```typescript // New const surface = new Deno.UnsafeWindowSurface({ system: "x11", windowHandle, displayHandle, width: 600, height: 800, }); const context = surface.getContext(); context.configure({ /* ... */ }); ``` --- tests/unit/webgpu_test.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'tests/unit') diff --git a/tests/unit/webgpu_test.ts b/tests/unit/webgpu_test.ts index ae584a587..6c91abe4a 100644 --- a/tests/unit/webgpu_test.ts +++ b/tests/unit/webgpu_test.ts @@ -236,13 +236,32 @@ Deno.test({ assertThrows( () => { - new Deno.UnsafeWindowSurface("cocoa", null, null); + new Deno.UnsafeWindowSurface({ + system: "cocoa", + windowHandle: null, + displayHandle: null, + width: 0, + height: 0, + }); }, ); device.destroy(); }); +Deno.test(function webgpuWindowSurfaceNoWidthHeight() { + assertThrows( + () => { + // @ts-expect-error width and height are required + new Deno.UnsafeWindowSurface({ + system: "x11", + windowHandle: null, + displayHandle: null, + }); + }, + ); +}); + Deno.test(function getPreferredCanvasFormat() { const preferredFormat = navigator.gpu.getPreferredCanvasFormat(); assert(preferredFormat === "bgra8unorm" || preferredFormat === "rgba8unorm"); -- cgit v1.2.3