Bump raw window handle to 0.6.0 (#4202)

Co-authored-by: junglie85 <junglie85@gmail.com>
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
This commit is contained in:
authored and GitHub committed 2023-10-27 05:24:46 +00:00
1 parent 2a9fdf9aa1
commit 4c5a817071
20 files changed
+1185 -660

No files matched your search

+106 -132
View File
@@ -9,8 +9,9 @@ use web_sys::{ImageBitmapRenderingContext, OffscreenCanvas};
use wgpu::{WasmNotSend, WasmNotSync};
use wgpu_test::GpuTestConfiguration;
use winit::{
event::{self, WindowEvent},
event::{self, KeyEvent, WindowEvent},
event_loop::{ControlFlow, EventLoop},
keyboard::{Key, NamedKey},
};
#[allow(dead_code)]
@@ -31,9 +32,11 @@ pub trait Example: 'static + Sized {
fn optional_features() -> wgpu::Features {
wgpu::Features::empty()
}
fn required_features() -> wgpu::Features {
wgpu::Features::empty()
}
fn required_downlevel_capabilities() -> wgpu::DownlevelCapabilities {
wgpu::DownlevelCapabilities {
flags: wgpu::DownlevelFlags::empty(),
@@ -41,27 +44,31 @@ pub trait Example: 'static + Sized {
..wgpu::DownlevelCapabilities::default()
}
}
fn required_limits() -> wgpu::Limits {
wgpu::Limits::downlevel_webgl2_defaults() // These downlevel limits will allow the code to run on all possible hardware
}
fn init(
config: &wgpu::SurfaceConfiguration,
adapter: &wgpu::Adapter,
device: &wgpu::Device,
queue: &wgpu::Queue,
) -> Self;
fn resize(
&mut self,
config: &wgpu::SurfaceConfiguration,
device: &wgpu::Device,
queue: &wgpu::Queue,
);
fn update(&mut self, event: WindowEvent);
fn render(&mut self, view: &wgpu::TextureView, device: &wgpu::Device, queue: &wgpu::Queue);
}
struct Setup {
window: winit::window::Window,
event_loop: EventLoop<()>,
instance: wgpu::Instance,
size: winit::dpi::PhysicalSize<u32>,
@@ -85,7 +92,7 @@ async fn setup<E: Example>(title: &str) -> Setup {
env_logger::init();
};
let event_loop = EventLoop::new();
let event_loop = EventLoop::new().unwrap();
let mut builder = winit::window::WindowBuilder::new();
builder = builder.with_title(title);
#[cfg(windows_OFF)] // TODO
@@ -109,8 +116,10 @@ async fn setup<E: Example>(title: &str) -> Setup {
.and_then(|win| win.document())
.and_then(|doc| doc.body())
.and_then(|body| {
body.append_child(&web_sys::Element::from(window.canvas()))
.ok()
body.append_child(&web_sys::Element::from(
window.canvas().expect("Couldn't get canvas"),
))
.ok()
})
.expect("couldn't append canvas to document body");
}
@@ -133,6 +142,7 @@ async fn setup<E: Example>(title: &str) -> Setup {
let bitmap_renderer = window
.canvas()
.expect("Couldn't get html canvas")
.get_context("bitmaprenderer")
.expect("couldn't create ImageBitmapRenderingContext (Result)")
.expect("couldn't create ImageBitmapRenderingContext (Option)")
@@ -230,7 +240,6 @@ async fn setup<E: Example>(title: &str) -> Setup {
.expect("Unable to find a suitable GPU adapter!");
Setup {
window,
event_loop,
instance,
size,
@@ -245,7 +254,6 @@ async fn setup<E: Example>(title: &str) -> Setup {
fn start<E: Example>(
#[cfg(not(target_arch = "wasm32"))] Setup {
window,
event_loop,
instance,
size,
@@ -255,7 +263,6 @@ fn start<E: Example>(
queue,
}: Setup,
#[cfg(target_arch = "wasm32")] Setup {
window,
event_loop,
instance,
size,
@@ -282,113 +289,103 @@ fn start<E: Example>(
let (mut frame_count, mut accum_time) = (0, 0.0);
log::info!("Entering render loop...");
event_loop.run(move |event, _, control_flow| {
let _ = (&instance, &adapter); // force ownership by the closure
*control_flow = if cfg!(feature = "metal-auto-capture") {
ControlFlow::Exit
} else {
ControlFlow::Poll
};
match event {
event::Event::RedrawEventsCleared => {
window.request_redraw();
}
event::Event::WindowEvent {
event:
WindowEvent::Resized(size)
| WindowEvent::ScaleFactorChanged {
new_inner_size: &mut size,
..
},
..
} => {
log::info!("Resizing to {:?}", size);
config.width = size.width.max(1);
config.height = size.height.max(1);
example.resize(&config, &device, &queue);
surface.configure(&device, &config);
}
event::Event::WindowEvent { event, .. } => match event {
WindowEvent::KeyboardInput {
input:
event::KeyboardInput {
virtual_keycode: Some(event::VirtualKeyCode::Escape),
state: event::ElementState::Pressed,
..
},
..
}
| WindowEvent::CloseRequested => {
*control_flow = ControlFlow::Exit;
}
#[cfg(not(target_arch = "wasm32"))]
WindowEvent::KeyboardInput {
input:
event::KeyboardInput {
virtual_keycode: Some(event::VirtualKeyCode::R),
state: event::ElementState::Pressed,
..
},
event_loop
.run(move |event, target| {
let _ = (&instance, &adapter); // force ownership by the closure
target.set_control_flow(ControlFlow::Poll);
if cfg!(feature = "metal-auto-capture") {
target.exit();
};
match event {
event::Event::WindowEvent {
event: WindowEvent::Resized(size),
..
} => {
println!("{:#?}", instance.generate_report());
config.width = size.width.max(1);
config.height = size.height.max(1);
example.resize(&config, &device, &queue);
surface.configure(&device, &config);
}
_ => {
example.update(event);
}
},
event::Event::RedrawRequested(_) => {
#[cfg(not(target_arch = "wasm32"))]
{
accum_time += last_frame_inst.elapsed().as_secs_f32();
last_frame_inst = Instant::now();
frame_count += 1;
if frame_count == 100 {
println!(
"Avg frame time {}ms",
accum_time * 1000.0 / frame_count as f32
);
accum_time = 0.0;
frame_count = 0;
event::Event::WindowEvent { event, .. } => match event {
WindowEvent::KeyboardInput {
event:
KeyEvent {
logical_key: Key::Named(NamedKey::Escape),
..
},
..
}
}
let frame = match surface.get_current_texture() {
Ok(frame) => frame,
Err(_) => {
surface.configure(&device, &config);
surface
.get_current_texture()
.expect("Failed to acquire next surface texture!")
| WindowEvent::CloseRequested => {
target.exit();
}
};
let view = frame.texture.create_view(&wgpu::TextureViewDescriptor {
format: Some(surface_view_format),
..wgpu::TextureViewDescriptor::default()
});
example.render(&view, &device, &queue);
frame.present();
#[cfg(target_arch = "wasm32")]
{
if let Some(offscreen_canvas_setup) = &offscreen_canvas_setup {
let image_bitmap = offscreen_canvas_setup
.offscreen_canvas
.transfer_to_image_bitmap()
.expect("couldn't transfer offscreen canvas to image bitmap.");
offscreen_canvas_setup
.bitmap_renderer
.transfer_from_image_bitmap(&image_bitmap);
log::info!("Transferring OffscreenCanvas to ImageBitmapRenderer");
#[cfg(not(target_arch = "wasm32"))]
WindowEvent::KeyboardInput {
event:
KeyEvent {
logical_key: Key::Character(s),
..
},
..
} if s == "r" => {
println!("{:#?}", instance.generate_report());
}
}
event::WindowEvent::RedrawRequested => {
#[cfg(not(target_arch = "wasm32"))]
{
accum_time += last_frame_inst.elapsed().as_secs_f32();
last_frame_inst = Instant::now();
frame_count += 1;
if frame_count == 100 {
println!(
"Avg frame time {}ms",
accum_time * 1000.0 / frame_count as f32
);
accum_time = 0.0;
frame_count = 0;
}
}
let frame = match surface.get_current_texture() {
Ok(frame) => frame,
Err(_) => {
surface.configure(&device, &config);
surface
.get_current_texture()
.expect("Failed to acquire next surface texture!")
}
};
let view = frame.texture.create_view(&wgpu::TextureViewDescriptor {
format: Some(surface_view_format),
..wgpu::TextureViewDescriptor::default()
});
example.render(&view, &device, &queue);
frame.present();
#[cfg(target_arch = "wasm32")]
{
if let Some(offscreen_canvas_setup) = &offscreen_canvas_setup {
let image_bitmap = offscreen_canvas_setup
.offscreen_canvas
.transfer_to_image_bitmap()
.expect("couldn't transfer offscreen canvas to image bitmap.");
offscreen_canvas_setup
.bitmap_renderer
.transfer_from_image_bitmap(&image_bitmap);
log::info!("Transferring OffscreenCanvas to ImageBitmapRenderer");
}
}
}
_ => example.update(event),
},
_ => {}
}
_ => {}
}
});
})
.unwrap();
}
#[cfg(not(target_arch = "wasm32"))]
@@ -511,30 +508,7 @@ impl<E: Example + WasmNotSend + WasmNotSync> From<ExampleTestParams<E>> for GpuT
&ctx.queue,
);
{
example.render(&dst_view, &ctx.device, &ctx.queue);
// Handle specific case for bunnymark
#[allow(deprecated)]
if params.image_path == "/examples/bunnymark/screenshot.png" {
// Press spacebar to spawn bunnies
example.update(winit::event::WindowEvent::KeyboardInput {
input: winit::event::KeyboardInput {
scancode: 0,
state: winit::event::ElementState::Pressed,
virtual_keycode: Some(winit::event::VirtualKeyCode::Space),
modifiers: winit::event::ModifiersState::empty(),
},
device_id: unsafe { winit::event::DeviceId::dummy() },
is_synthetic: false,
});
// Step 3 extra frames
for _ in 0..3 {
example.render(&dst_view, &ctx.device, &ctx.queue);
}
}
}
example.render(&dst_view, &ctx.device, &ctx.queue);
let mut cmd_buf = ctx
.device