test(client): allow rendering UI snapshots at higher pixel density

This commit is contained in:
Loki 2026-10-25 10:23:15 +01:00
parent 8dcd3311bc
commit 3d43c98c9e
Signed by: boba
GPG key ID: 253067914055423B

View file

@ -12,18 +12,29 @@ impl Platform for HeadlessPlatform {
}
}
/// Pixel density of the headless snapshots, 1 by default. `VNOX_UI_SNAPSHOT_SCALE=2` renders
/// the 1280x800 window at 2560x1600 for crisp screenshots.
fn snapshot_scale() -> u32 {
std::env::var("VNOX_UI_SNAPSHOT_SCALE")
.ok()
.and_then(|value| value.parse::<u32>().ok())
.map_or(1, |value| value.clamp(1, 4))
}
fn render(window: &MainWindow, surface: &MinimalSoftwareWindow, name: &str) {
window.window().request_redraw();
let mut pixels = SharedPixelBuffer::<Rgb8Pixel>::new(1280, 800);
let scale = snapshot_scale();
let (width, height) = (1280 * scale, 800 * scale);
let mut pixels = SharedPixelBuffer::<Rgb8Pixel>::new(width, height);
assert!(surface.draw_if_needed(|renderer| {
renderer.render(pixels.make_mut_slice(), 1280);
renderer.render(pixels.make_mut_slice(), width as usize);
}));
if let Some(directory) = std::env::var_os("VNOX_UI_SNAPSHOT_DIR") {
std::fs::create_dir_all(&directory).unwrap();
let mut file =
std::fs::File::create(std::path::PathBuf::from(directory).join(format!("{name}.ppm")))
.unwrap();
write!(file, "P6\n1280 800\n255\n").unwrap();
write!(file, "P6\n{width} {height}\n255\n").unwrap();
file.write_all(pixels.as_bytes()).unwrap();
}
}
@ -94,7 +105,13 @@ fn native_shell_keeps_drafts_settings_and_models_between_ticks() {
};
sync();
window.show().unwrap();
surface.set_size(PhysicalSize::new(1280, 800));
let scale = snapshot_scale();
window
.window()
.dispatch_event(WindowEvent::ScaleFactorChanged {
scale_factor: scale as f32,
});
surface.set_size(PhysicalSize::new(1280 * scale, 800 * scale));
render(&window, &surface, "native-chat");
// Drive the real native editor, not only the generated callback surface.