[deno] add resize method to UnsafeWindowSurface

(cherry-picked from denoland/deno#29254)
This commit is contained in:
chirsz 2025-09-17 15:35:30 -04:00 committed by Erich Gubler
parent b6b951d467
commit eb3bed5f53
2 changed files with 36 additions and 0 deletions

View File

@ -163,6 +163,18 @@ impl UnsafeWindowSurface {
context.present().map_err(JsErrorBox::from_err) 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 { struct UnsafeWindowSurfaceOptions {

View File

@ -32,6 +32,8 @@ pub struct Configuration {
pub device: Ptr<GPUDevice>, pub device: Ptr<GPUDevice>,
pub usage: u32, pub usage: u32,
pub format: GPUTextureFormat, pub format: GPUTextureFormat,
pub surface_config:
wgpu_types::SurfaceConfiguration<Vec<wgpu_types::TextureFormat>>,
} }
pub struct GPUCanvasContext { pub struct GPUCanvasContext {
@ -97,6 +99,7 @@ impl GPUCanvasContext {
device, device,
usage: configuration.usage, usage: configuration.usage,
format: configuration.format, format: configuration.format,
surface_config: conf,
}); });
Ok(()) Ok(())
@ -173,6 +176,27 @@ impl GPUCanvasContext {
Ok(()) 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)] #[derive(WebIDL)]