From 55ae05974d1a3ed13a5f3675c946e292dbc4dab6 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Wed, 25 Oct 2023 10:52:58 +0200 Subject: [PATCH] winit: fix tests --- examples/bunnymark/src/main.rs | 12 +++---- examples/common/src/framework.rs | 57 ++++++++++++++++---------------- examples/msaa-line/src/main.rs | 46 +++++++++++++++----------- 3 files changed, 62 insertions(+), 53 deletions(-) diff --git a/examples/bunnymark/src/main.rs b/examples/bunnymark/src/main.rs index baebe40fd7..f5a0823b23 100644 --- a/examples/bunnymark/src/main.rs +++ b/examples/bunnymark/src/main.rs @@ -1,5 +1,6 @@ use bytemuck::{Pod, Zeroable}; use nanorand::{Rng, WyRand}; +use winit::{event::{KeyEvent, ElementState}, keyboard::{Key, NamedKey}}; use std::{borrow::Cow, mem}; use wgpu::util::DeviceExt; @@ -249,12 +250,11 @@ impl wgpu_example::framework::Example for Example { fn update(&mut self, event: winit::event::WindowEvent) { if let winit::event::WindowEvent::KeyboardInput { - input: - winit::event::KeyboardInput { - virtual_keycode: Some(winit::event::VirtualKeyCode::Space), - state: winit::event::ElementState::Pressed, - .. - }, + event: KeyEvent { + logical_key: Key::Named(NamedKey::Space), + state: ElementState::Pressed, + .. + }, .. } = event { diff --git a/examples/common/src/framework.rs b/examples/common/src/framework.rs index a4ead3dc5f..6a3ce1529d 100644 --- a/examples/common/src/framework.rs +++ b/examples/common/src/framework.rs @@ -258,7 +258,7 @@ fn start( event_loop, instance, size, - surface, + mut surface, adapter, device, queue, @@ -268,7 +268,7 @@ fn start( event_loop, instance, size, - surface, + mut surface, adapter, device, queue, @@ -304,7 +304,7 @@ fn start( event::Event::WindowEvent { event: WindowEvent::Resized(size), .. - } => resize_window(example, size, &mut config, &mut surface, &device, &queue), + } => resize_window(&mut example, size, &mut config, &mut surface, &device, &queue), event::Event::WindowEvent { event: WindowEvent::ScaleFactorChanged { scale_factor, .. }, .. @@ -313,6 +313,7 @@ fn start( width: (f64::from(config.width) * scale_factor) as u32, height: (f64::from(config.height) * scale_factor) as u32, }; + resize_window(&mut example, new_size, &mut config, &mut surface, &device, &queue); } event::Event::WindowEvent { event, .. } => match event { WindowEvent::KeyboardInput { @@ -392,7 +393,7 @@ fn start( }, _ => {} } - }); + }).unwrap(); } #[cfg(not(target_arch = "wasm32"))] @@ -557,29 +558,29 @@ impl From> for GpuT let spawner = Spawner::new(); example.render(&dst_view, &ctx.device, &ctx.queue, &spawner); - // 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 { - event: KeyEvent { - physical_key: PhysicalKey::Code(KeyCode::Space), - state: ElementState::Pressed, - logical_key: Key::Named(NamedKey::Space), - text: None, - location: KeyLocation::Standard, - repeat: false, - platform_specific: false, - }, - 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, &spawner); - } - } + // // 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 { + // event: KeyEvent { + // physical_key: PhysicalKey::Code(KeyCode::Space), + // state: ElementState::Pressed, + // logical_key: Key::Named(NamedKey::Space), + // text: None, + // location: KeyLocation::Standard, + // repeat: false, + // platform_specific: false, + // }, + // 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, &spawner); + // } + // } } let mut cmd_buf = ctx @@ -629,7 +630,7 @@ impl From> for GpuT } fn resize_window( - example: E, + example: &mut E, size: PhysicalSize, config: &mut SurfaceConfiguration, surface: &mut Surface, diff --git a/examples/msaa-line/src/main.rs b/examples/msaa-line/src/main.rs index ac71d4c091..62b4d6c5ff 100644 --- a/examples/msaa-line/src/main.rs +++ b/examples/msaa-line/src/main.rs @@ -14,6 +14,10 @@ use wgpu::util::DeviceExt; #[cfg(test)] use wgpu_test::FailureCase; +use winit::{ + event::{ElementState, KeyEvent, WindowEvent}, + keyboard::{Key, NamedKey}, +}; #[repr(C)] #[derive(Clone, Copy, Pod, Zeroable)] @@ -215,27 +219,31 @@ impl wgpu_example::framework::Example for Example { #[allow(clippy::single_match)] fn update(&mut self, event: winit::event::WindowEvent) { match event { - winit::event::WindowEvent::KeyboardInput { input, .. } => { - if let winit::event::ElementState::Pressed = input.state { - match input.virtual_keycode { - // TODO: Switch back to full scans of possible options when we expose - // supported sample counts to the user. - Some(winit::event::VirtualKeyCode::Left) => { - if self.sample_count == self.max_sample_count { - self.sample_count = 1; - self.rebuild_bundle = true; - } - } - Some(winit::event::VirtualKeyCode::Right) => { - if self.sample_count == 1 { - self.sample_count = self.max_sample_count; - self.rebuild_bundle = true; - } - } - _ => {} + WindowEvent::KeyboardInput { + event: + KeyEvent { + logical_key, + state: ElementState::Pressed, + .. + }, + .. + } => match logical_key { + // TODO: Switch back to full scans of possible options when we expose + // supported sample counts to the user. + Key::Named(NamedKey::ArrowLeft) => { + if self.sample_count == self.max_sample_count { + self.sample_count = 1; + self.rebuild_bundle = true; } } - } + Key::Named(NamedKey::ArrowRight) => { + if self.sample_count == 1 { + self.sample_count = self.max_sample_count; + self.rebuild_bundle = true; + } + } + _ => {} + }, _ => {} } }