Skip to content

Commit eb3bed5

Browse files
chirsz-everErichDonGubler
authored andcommitted
[deno] add resize method to UnsafeWindowSurface
(cherry-picked from denoland/deno#29254)
1 parent b6b951d commit eb3bed5

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

deno_webgpu/byow.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@ impl UnsafeWindowSurface {
163163

164164
context.present().map_err(JsErrorBox::from_err)
165165
}
166+
167+
#[fast]
168+
fn resize(&self, width: u32, height: u32, scope: &mut v8::HandleScope) {
169+
self.width.replace(width);
170+
self.height.replace(height);
171+
172+
let Some(context) = self.context.try_unwrap(scope) else {
173+
return;
174+
};
175+
176+
context.resize_configure(width, height);
177+
}
166178
}
167179

168180
struct UnsafeWindowSurfaceOptions {

deno_webgpu/surface.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ pub struct Configuration {
3232
pub device: Ptr<GPUDevice>,
3333
pub usage: u32,
3434
pub format: GPUTextureFormat,
35+
pub surface_config:
36+
wgpu_types::SurfaceConfiguration<Vec<wgpu_types::TextureFormat>>,
3537
}
3638

3739
pub struct GPUCanvasContext {
@@ -97,6 +99,7 @@ impl GPUCanvasContext {
9799
device,
98100
usage: configuration.usage,
99101
format: configuration.format,
102+
surface_config: conf,
100103
});
101104

102105
Ok(())
@@ -173,6 +176,27 @@ impl GPUCanvasContext {
173176

174177
Ok(())
175178
}
179+
180+
pub fn resize_configure(&self, width: u32, height: u32) {
181+
self.width.replace(width);
182+
self.height.replace(height);
183+
184+
let mut config = self.config.borrow_mut();
185+
let Some(config) = &mut *config else {
186+
return;
187+
};
188+
189+
config.surface_config.width = width;
190+
config.surface_config.height = height;
191+
192+
let err = config.device.instance.surface_configure(
193+
self.surface_id,
194+
config.device.id,
195+
&config.surface_config,
196+
);
197+
198+
config.device.error_handler.push_error(err);
199+
}
176200
}
177201

178202
#[derive(WebIDL)]

0 commit comments

Comments
 (0)