From eb3bed5f534399fa90aa8a0bf03b2a3c787e7c57 Mon Sep 17 00:00:00 2001 From: chirsz Date: Wed, 17 Sep 2025 15:35:30 -0400 Subject: [PATCH] [deno] add `resize` method to `UnsafeWindowSurface` (cherry-picked from denoland/deno#29254) --- deno_webgpu/byow.rs | 12 ++++++++++++ deno_webgpu/surface.rs | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/deno_webgpu/byow.rs b/deno_webgpu/byow.rs index 4c2bed922..0571a80d7 100644 --- a/deno_webgpu/byow.rs +++ b/deno_webgpu/byow.rs @@ -163,6 +163,18 @@ impl UnsafeWindowSurface { context.present().map_err(JsErrorBox::from_err) } + + #[fast] + fn resize(&self, width: u32, height: u32, scope: &mut v8::HandleScope) { + self.width.replace(width); + self.height.replace(height); + + let Some(context) = self.context.try_unwrap(scope) else { + return; + }; + + context.resize_configure(width, height); + } } struct UnsafeWindowSurfaceOptions { diff --git a/deno_webgpu/surface.rs b/deno_webgpu/surface.rs index bbecdbc31..0a042a954 100644 --- a/deno_webgpu/surface.rs +++ b/deno_webgpu/surface.rs @@ -32,6 +32,8 @@ pub struct Configuration { pub device: Ptr, pub usage: u32, pub format: GPUTextureFormat, + pub surface_config: + wgpu_types::SurfaceConfiguration>, } pub struct GPUCanvasContext { @@ -97,6 +99,7 @@ impl GPUCanvasContext { device, usage: configuration.usage, format: configuration.format, + surface_config: conf, }); Ok(()) @@ -173,6 +176,27 @@ impl GPUCanvasContext { Ok(()) } + + pub fn resize_configure(&self, width: u32, height: u32) { + self.width.replace(width); + self.height.replace(height); + + let mut config = self.config.borrow_mut(); + let Some(config) = &mut *config else { + return; + }; + + config.surface_config.width = width; + config.surface_config.height = height; + + let err = config.device.instance.surface_configure( + self.surface_id, + config.device.id, + &config.surface_config, + ); + + config.device.error_handler.push_error(err); + } } #[derive(WebIDL)]