Skip to content

Commit

Permalink
winit: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TornaxO7 committed Oct 25, 2023
1 parent 6d0fa16 commit 55ae059
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 53 deletions.
12 changes: 6 additions & 6 deletions examples/bunnymark/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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
{
Expand Down
57 changes: 29 additions & 28 deletions examples/common/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ fn start<E: Example>(
event_loop,
instance,
size,
surface,
mut surface,
adapter,
device,
queue,
Expand All @@ -268,7 +268,7 @@ fn start<E: Example>(
event_loop,
instance,
size,
surface,
mut surface,
adapter,
device,
queue,
Expand Down Expand Up @@ -304,7 +304,7 @@ fn start<E: Example>(
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, .. },
..
Expand All @@ -313,6 +313,7 @@ fn start<E: Example>(
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 {
Expand Down Expand Up @@ -392,7 +393,7 @@ fn start<E: Example>(
},
_ => {}
}
});
}).unwrap();
}

#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -557,29 +558,29 @@ impl<E: Example + WasmNotSend + WasmNotSync> From<ExampleTestParams<E>> 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
Expand Down Expand Up @@ -629,7 +630,7 @@ impl<E: Example + WasmNotSend + WasmNotSync> From<ExampleTestParams<E>> for GpuT
}

fn resize_window<E: Example>(
example: E,
example: &mut E,
size: PhysicalSize<u32>,
config: &mut SurfaceConfiguration,
surface: &mut Surface,
Expand Down
46 changes: 27 additions & 19 deletions examples/msaa-line/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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;
}
}
_ => {}
},
_ => {}
}
}
Expand Down

0 comments on commit 55ae059

Please sign in to comment.