mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
[deno] add resize method to UnsafeWindowSurface
(cherry-picked from denoland/deno#29254)
This commit is contained in:
parent
b6b951d467
commit
eb3bed5f53
@ -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 {
|
||||
|
||||
@ -32,6 +32,8 @@ pub struct Configuration {
|
||||
pub device: Ptr<GPUDevice>,
|
||||
pub usage: u32,
|
||||
pub format: GPUTextureFormat,
|
||||
pub surface_config:
|
||||
wgpu_types::SurfaceConfiguration<Vec<wgpu_types::TextureFormat>>,
|
||||
}
|
||||
|
||||
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)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user