mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Tests: trim redundant work out of slow ui-egui unit tests (#15368)
Same code paths and assertions, fewer pixels, harnesses and frames: - every_adjustment_layer_edits_through_properties: one app per mode and depth instead of one per kind (all 16 kinds still run in all 6 settings), three drag moves and two frames after each new layer. - canvas_mips_preserve_opaque_pixels_and_partial_updates: 767 x 431 instead of 1791 x 1083; still odd sides and two partially redrawn mip levels. - blend_hover_* (4 of 5): the 1024 x 768 fixture and every view halved; the background-redraw case keeps its size. - every_paragraph_box_handle_resizes_the_box_with_snapping_on: zooms 25 % and 200 % only. - the wheel tests: 3 and 4 frames per notch instead of 30 and 40; the view is already settled then. - Shift-letter cycle: two frames per press instead of three. - guide and Cmd stand-in tables: drop rows whose tool shares a family and pointer kind with a row that stays. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
57feba3fc8
commit
e9f698d91c
9 files changed
+85
-33
No files matched your search
@@ -36,12 +36,14 @@ fn blend_hover_pattern_tiles_and_multiple_views_reuse_current_pixels() {
|
||||
let Some(rs) = render_state() else { return };
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
|
||||
app.set_wgpu(rs);
|
||||
app.run("file.new", json!({"width":1024,"height":768,"background":"#336699"})).unwrap();
|
||||
// Half the 1024 × 768 canvas these views were first written for (see `check_blend_viewport`): `a` still runs off
|
||||
// the right edge and `b` still lies apart from it.
|
||||
app.run("file.new", json!({"width":512,"height":384,"background":"#336699"})).unwrap();
|
||||
let layer = app.run("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap();
|
||||
app.run("edit.fill", json!({"color":"#cc8844"})).unwrap();
|
||||
let ctx = app.ctx().clone();
|
||||
let a = DRect::new(724, 200, 1324, 500);
|
||||
let b = DRect::new(0, 200, 300, 500);
|
||||
let a = DRect::new(362, 100, 662, 250);
|
||||
let b = DRect::new(0, 100, 150, 250);
|
||||
assert!(ensure_gpu(&mut app, &ctx, 0, a, None));
|
||||
app.ui.view.pattern_preview = true;
|
||||
crate::blend_preview::hover(&mut app, &[photocraft_doc::LayerId(layer)], Some(BlendMode::Multiply));
|
||||
@@ -136,7 +138,11 @@ fn check_blend_viewport(cpu_fallback: bool, multiple_layers: bool) {
|
||||
let Some(rs) = render_state() else { return };
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
|
||||
app.set_wgpu(rs);
|
||||
app.run("file.new", json!({"width":1024,"height":768,"background":"#336699"})).unwrap();
|
||||
// Every view and count below is half of the 1024 × 768 fixture first used: the clip to the view
|
||||
// (`blend_preview::clip_damage`) and the catch-up (`blend_preview::uncovered`) are rectangle arithmetic with no
|
||||
// size threshold, and the canvas stays far below the background redraw's (that case is
|
||||
// `blend_hover_during_background_redraw_restores_committed_pixels`). The whole-canvas pixel checks cost a quarter.
|
||||
app.run("file.new", json!({"width":512,"height":384,"background":"#336699"})).unwrap();
|
||||
let layer = app.run("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap();
|
||||
app.run("edit.fill", json!({"color":"#cc8844"})).unwrap();
|
||||
if cpu_fallback {
|
||||
@@ -150,7 +156,7 @@ fn check_blend_viewport(cpu_fallback: bool, multiple_layers: bool) {
|
||||
layers.push(photocraft_doc::LayerId(other));
|
||||
}
|
||||
let ctx = app.ctx().clone();
|
||||
let visible = DRect::new(256, 256, 512, 512);
|
||||
let visible = DRect::new(128, 128, 256, 256);
|
||||
assert!(ensure_gpu(&mut app, &ctx, 0, visible, None));
|
||||
assert!(app.redraws.is_empty(), "small fixture must finish synchronously");
|
||||
if cpu_fallback {
|
||||
@@ -161,23 +167,23 @@ fn check_blend_viewport(cpu_fallback: bool, multiple_layers: bool) {
|
||||
let original = gpu.read_texels(id.0).unwrap();
|
||||
crate::blend_preview::hover(&mut app, &layers, Some(BlendMode::Multiply));
|
||||
assert!(ensure_gpu(&mut app, &ctx, 0, visible, None));
|
||||
println!("BLEND_VIEWPORT kind={} pixels={} expected={} adapter={:?}", app.perf.last_refresh, app.perf.last_refresh_px, 256 * 256, app.perf.gpu_info);
|
||||
assert_eq!(app.perf.last_refresh_px, 256 * 256, "hover must not recomposite offscreen pixels of a full-canvas layer");
|
||||
println!("BLEND_VIEWPORT kind={} pixels={} expected={} adapter={:?}", app.perf.last_refresh, app.perf.last_refresh_px, 128 * 128, app.perf.gpu_info);
|
||||
assert_eq!(app.perf.last_refresh_px, 128 * 128, "hover must not recomposite offscreen pixels of a full-canvas layer");
|
||||
assert_visible_pixels(&mut app, visible);
|
||||
app.perf.last_refresh_px = 0;
|
||||
assert!(ensure_gpu(&mut app, &ctx, 0, visible, None));
|
||||
assert_eq!(app.perf.last_refresh_px, 0, "unchanged view and mode must reuse the texture");
|
||||
let zoomed_out = DRect::new(128, 128, 640, 640);
|
||||
let zoomed_out = DRect::new(64, 64, 320, 320);
|
||||
assert!(ensure_gpu(&mut app, &ctx, 0, zoomed_out, None));
|
||||
assert_eq!(app.perf.last_refresh_px, 512 * 512, "zooming out catches up the larger visible area");
|
||||
let panned = DRect::new(640, 256, 896, 512);
|
||||
assert_eq!(app.perf.last_refresh_px, 256 * 256, "zooming out catches up the larger visible area");
|
||||
let panned = DRect::new(320, 128, 448, 256);
|
||||
assert!(ensure_gpu(&mut app, &ctx, 0, panned, None));
|
||||
assert_eq!(app.perf.last_refresh_px, 256 * 256, "newly exposed pixels must catch up without a mode change");
|
||||
assert_eq!(app.perf.last_refresh_px, 128 * 128, "newly exposed pixels must catch up without a mode change");
|
||||
crate::blend_preview::hover(&mut app, &layers, Some(BlendMode::Screen));
|
||||
assert!(ensure_gpu(&mut app, &ctx, 0, panned, None));
|
||||
assert_eq!(app.perf.last_refresh_px, 256 * 256);
|
||||
assert_eq!(app.perf.last_refresh_px, 128 * 128);
|
||||
assert!(ensure_gpu(&mut app, &ctx, 0, visible, None));
|
||||
assert_eq!(app.perf.last_refresh_px, 256 * 256, "returning view must show the current mode");
|
||||
assert_eq!(app.perf.last_refresh_px, 128 * 128, "returning view must show the current mode");
|
||||
assert_visible_pixels(&mut app, visible);
|
||||
assert_visible_pixels(&mut app, panned);
|
||||
crate::blend_preview::hover(&mut app, &layers, None);
|
||||
@@ -189,7 +195,7 @@ fn check_blend_viewport(cpu_fallback: bool, multiple_layers: bool) {
|
||||
assert!(ensure_gpu(&mut app, &ctx, 0, visible, None));
|
||||
let bounds = app.session.active().unwrap().doc.bounds();
|
||||
assert_visible_pixels(&mut app, bounds);
|
||||
app.run("file.new", json!({"width":1024,"height":768,"background":"white"})).unwrap();
|
||||
app.run("file.new", json!({"width":512,"height":384,"background":"white"})).unwrap();
|
||||
assert!(ensure_gpu(&mut app, &ctx, 1, visible, None));
|
||||
app.session.set_active(0);
|
||||
app.sync_views();
|
||||
|
||||
@@ -125,7 +125,11 @@ fn canvas_textures_the_gpu_refuses_leave_it_working(gpu: &GpuCanvas) {
|
||||
|
||||
fn check_mips(gpu: &GpuCanvas) {
|
||||
for depth in [SampleType::U8, SampleType::U16, SampleType::F32] {
|
||||
for (w, h) in [(1791, 1083), (513, 1), (1, 513)] {
|
||||
// 767 × 431 is a single tile (`DEFAULT_TILE`) with odd sides down the chain (767, 383, 191, 95 and 431,
|
||||
// 215, 107, 53), and its levels 1 and 2 are over `WHOLE_MIP_SIDE` (128), so the patch below redraws two
|
||||
// levels by their damage (`mip_damage`) before the chain is redrawn whole: the paths 1791 × 1083 took, at
|
||||
// a sixth of the pixels. The larger driver case stays in `partial_updates_match_a_full_rebuild_at_every_mip_level`.
|
||||
for (w, h) in [(767, 431), (513, 1), (1, 513)] {
|
||||
let mut full = Buffer::filled(Rect::from_xywh(0, 0, w, h), [0.25, 0.5, 0.75, 1.0]);
|
||||
// Reusing the key also covers replacing textures after a size or depth change.
|
||||
gpu.upload_buffer_full(1, &full, depth);
|
||||
|
||||
@@ -97,8 +97,9 @@ fn drag(h: &mut Harness<'_, Box<PhotocraftApp>>, from: Pos2, to: Pos2) {
|
||||
h.run_steps(1);
|
||||
h.drag_at(from);
|
||||
h.run_steps(1);
|
||||
for i in 1..=6 {
|
||||
h.hover_at(from + (to - from) * (i as f32 / 6.0));
|
||||
// Three moves give the gesture several previews before its one commit, which is what the history check needs.
|
||||
for i in 1..=3 {
|
||||
h.hover_at(from + (to - from) * (i as f32 / 3.0));
|
||||
h.run_steps(1);
|
||||
}
|
||||
h.drop_at(to);
|
||||
@@ -137,8 +138,21 @@ fn sliders(h: &Harness<'_, Box<PhotocraftApp>>) -> Vec<Rect> {
|
||||
#[test]
|
||||
fn every_adjustment_layer_edits_through_properties() {
|
||||
for (mode, depth) in [("rgb", 8), ("rgb", 16), ("rgb", 32), ("gray", 8), ("cmyk", 8), ("lab", 16)] {
|
||||
for kind in ALL_KINDS {
|
||||
let mut h = app_harness(kind, mode, depth);
|
||||
// One app per document setting, not one per kind: each kind deletes the previous kind's layer and adds its
|
||||
// own over the same two-tone background, so its editor opens on the stack a fresh app had (the Properties
|
||||
// session is per layer, `PropertiesAdjust::new`). Every kind still runs in every mode and depth: the
|
||||
// composite of each adjustment differs per mode and depth, and no other test runs all of them.
|
||||
let mut h = app_harness(ALL_KINDS[0], mode, depth);
|
||||
for (i, kind) in ALL_KINDS.into_iter().enumerate() {
|
||||
if i > 0 {
|
||||
let (previous, _) = layer(&h);
|
||||
h.state_mut().run("layer.delete", json!({"layer": previous.0})).unwrap();
|
||||
h.state_mut().run(&format!("layer.newAdjustmentLayer.{kind}"), json!({})).unwrap();
|
||||
// The Properties panel shows the new layer's editor on the next frame; the second leaves its widgets
|
||||
// laid out for the queries below.
|
||||
h.run_steps(2);
|
||||
}
|
||||
assert_eq!(h.state().session.active().unwrap().doc.layers.len(), 2, "{kind} {mode}: the background and this kind's layer");
|
||||
let (_, before) = layer(&h);
|
||||
let steps = history_len(&h);
|
||||
let slider = sliders(&h).first().copied();
|
||||
|
||||
@@ -59,6 +59,12 @@ fn the_wheel_over_a_field_steps_it_without_a_click() {
|
||||
assert_eq!(view(&h), before, "the canvas didn't move");
|
||||
}
|
||||
|
||||
/// Frames a wheel event gets to play out (0.25 s each, the harness's default step). egui's wheel smoothing reaches
|
||||
/// 90 % in 0.1 s and takes the rest under one point at once, so the smoothed tail of a notch (about 50 points) ends
|
||||
/// within three frames even at a 0.1 s step; four leave one to spare: the view after
|
||||
/// them is the one the old forty left.
|
||||
const TAIL_STEPS: usize = 4;
|
||||
|
||||
/// How far a wheel of `delta` lines with `modifiers` over the canvas moves the view, a Smoothing
|
||||
/// field focused or not, once egui's smoothed scroll has run out. The field isn't stepped.
|
||||
fn canvas_pan(focus: bool, delta: egui::Vec2, modifiers: egui::Modifiers) -> (f32, [f32; 2]) {
|
||||
@@ -78,7 +84,7 @@ fn canvas_pan(focus: bool, delta: egui::Vec2, modifiers: egui::Modifiers) -> (f3
|
||||
phase: egui::TouchPhase::Move,
|
||||
modifiers,
|
||||
});
|
||||
h.run_steps(40);
|
||||
h.run_steps(TAIL_STEPS);
|
||||
assert!(h.query_all_by_role(Role::SpinButton).any(|n| n.value().as_deref() == Some("10")), "focus {focus}: the field wasn't stepped");
|
||||
let after = view(&h);
|
||||
(after.0 / before.0, [after.1[0] - before.1[0], after.1[1] - before.1[1]])
|
||||
|
||||
@@ -84,16 +84,17 @@ const GUIDE: egui::CursorIcon = egui::CursorIcon::ResizeHorizontal;
|
||||
#[test]
|
||||
fn command_over_a_guide_takes_it_where_command_is_the_move_tool() {
|
||||
let takes = |tool, latched| (tool, false, latched, true);
|
||||
// One tool per family (`canvas::tools::family`): whether the guides take ⌘ is decided by family
|
||||
// (`rulers::moves_with_command`, `tools::takes_command_stand_in`), and the painting family refuses a ⌘ press the
|
||||
// same way for all its tools (`PaintTool::takes`). Within it, one tool per kind of pointer (`cursor_policy`): the
|
||||
// Brush's tip with its centre mark, the Clone Stamp's and Quick Selection's tips without one, the Paint Bucket's
|
||||
// click-tool pointer. The Eraser, Dodge, Spot Healing Brush and Smudge are more Brush-like tips.
|
||||
let rows = [
|
||||
takes(Tool::Brush, false),
|
||||
takes(Tool::Eraser, false),
|
||||
takes(Tool::Gradient, false),
|
||||
takes(Tool::PaintBucket, false),
|
||||
takes(Tool::CloneStamp, false),
|
||||
takes(Tool::Eyedropper, false),
|
||||
takes(Tool::Dodge, false),
|
||||
takes(Tool::SpotHealing, false),
|
||||
takes(Tool::Smudge, false),
|
||||
takes(Tool::QuickSelection, false),
|
||||
takes(Tool::RectMarquee, false),
|
||||
takes(Tool::Lasso, false),
|
||||
@@ -102,10 +103,8 @@ fn command_over_a_guide_takes_it_where_command_is_the_move_tool() {
|
||||
takes(Tool::Frame, false),
|
||||
takes(Tool::Artboard, false),
|
||||
takes(Tool::Brush, true),
|
||||
takes(Tool::Eraser, true),
|
||||
takes(Tool::RectMarquee, true),
|
||||
(Tool::Brush, true, false, false),
|
||||
(Tool::Eraser, true, false, false),
|
||||
(Tool::Frame, true, false, false),
|
||||
(Tool::Pen, false, false, false),
|
||||
(Tool::Hand, false, false, false),
|
||||
|
||||
@@ -347,8 +347,10 @@ const CTRL_ALT: Modifiers = Modifiers { alt: true, ctrl: true, shift: false, mac
|
||||
/// The tools that keep ⌘ for themselves leave the layer alone.
|
||||
#[test]
|
||||
fn cmd_gives_the_move_tool_only_where_the_tool_does_not_take_cmd() {
|
||||
let moves =
|
||||
[Tool::Brush, Tool::Eraser, Tool::Gradient, Tool::CloneStamp, Tool::Eyedropper, Tool::Move, Tool::RectMarquee, Tool::EllipseMarquee, Tool::Lasso];
|
||||
// The Eraser is left out: it is in the Brush's family (`canvas::tools::family`), which refuses a ⌘ press the same
|
||||
// way for every tool (`PaintTool::takes`); the Elliptical Marquee is the Rectangular one's marquee pass with
|
||||
// another shape (`selection.rs`, `MarqueeKind`).
|
||||
let moves = [Tool::Brush, Tool::Gradient, Tool::CloneStamp, Tool::Eyedropper, Tool::Move, Tool::RectMarquee, Tool::Lasso];
|
||||
for tool in moves {
|
||||
let mut h = harness(tool);
|
||||
let id = with_layer(&mut h);
|
||||
|
||||
@@ -261,9 +261,14 @@ fn the_wheel_reaches_12800_percent_and_stops_dead_there() {
|
||||
h.hover_at(p);
|
||||
h.run_steps(2);
|
||||
let d0 = doc_at(&h, p);
|
||||
// Frames after each notch (0.25 s each, the harness's default step): a notch lands within two (egui's wheel
|
||||
// smoothing reaches 90 % in 0.1 s and takes the rest under one point at once), and the old clamp pulled the zoom
|
||||
// back on every frame, so three show it: the zoom and centre
|
||||
// after them are the ones the old thirty left.
|
||||
const NOTCH_STEPS: usize = 3;
|
||||
for _ in 0..14 {
|
||||
wheel(&h, 1.0, Modifiers::ALT);
|
||||
h.run_steps(30);
|
||||
h.run_steps(NOTCH_STEPS);
|
||||
}
|
||||
assert_eq!(zoom(&h), max_zoom(), "a notch past the limit lands on it exactly");
|
||||
let d1 = doc_at(&h, p);
|
||||
@@ -271,13 +276,13 @@ fn the_wheel_reaches_12800_percent_and_stops_dead_there() {
|
||||
let c = h.state().ui.views[0].center;
|
||||
for _ in 0..4 {
|
||||
wheel(&h, 1.0, Modifiers::ALT);
|
||||
h.run_steps(30);
|
||||
h.run_steps(NOTCH_STEPS);
|
||||
}
|
||||
assert_eq!(zoom(&h), max_zoom());
|
||||
assert_eq!(h.state().ui.views[0].center, c, "at the limit the image doesn't move");
|
||||
// One notch back: 12800 / 1.1, still around the pointer.
|
||||
wheel(&h, -1.0, Modifiers::ALT);
|
||||
h.run_steps(30);
|
||||
h.run_steps(NOTCH_STEPS);
|
||||
assert!((zoom(&h) - max_zoom() / 1.1).abs() < 1e-2, "{}", zoom(&h));
|
||||
let d2 = doc_at(&h, p);
|
||||
assert!((d2[0] - d0[0]).abs() < 0.02 && (d2[1] - d0[1]).abs() < 0.02, "{d0:?} -> {d2:?}");
|
||||
|
||||
@@ -51,13 +51,25 @@ fn sequence(letter: char, steps: usize) -> Vec<Tool> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// [`shift_press`] with two frames instead of three: the runtime takes the key in the first and the app picks the
|
||||
/// tool it fired in the second (`shortcut_dispatch::pick_tool`); the third only drew the toolbar again.
|
||||
fn quick_shift_press(h: &mut Harness<'static, Box<PhotocraftApp>>, key: Key) {
|
||||
h.input_mut().events.extend([
|
||||
egui::Event::ModifiersChanged(Modifiers::SHIFT),
|
||||
egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::SHIFT },
|
||||
egui::Event::Key { key, physical_key: None, pressed: false, repeat: false, modifiers: Modifiers::SHIFT },
|
||||
egui::Event::ModifiersChanged(Modifiers::NONE),
|
||||
]);
|
||||
h.run_steps(2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_every_tool_shift_letter_lands_on_the_next_tool_in_toolbar_order() {
|
||||
let mut h = app();
|
||||
for (letter, group) in groups() {
|
||||
for (i, from) in group.iter().enumerate() {
|
||||
h.state_mut().ui.tool = *from;
|
||||
shift_press(&mut h, key_for(letter));
|
||||
quick_shift_press(&mut h, key_for(letter));
|
||||
let want = group[(i + 1) % group.len()];
|
||||
assert_eq!(h.state().ui.tool, want, "Shift+{letter} from {from:?}");
|
||||
}
|
||||
|
||||
@@ -2028,7 +2028,11 @@ fn every_paragraph_box_handle_resizes_the_box_with_snapping_on() {
|
||||
let scaled = Affine { m: [1.5, 0.0, 0.0, 0.75, 300.0, 300.0] };
|
||||
let rotated = Affine { m: [1.2 * 0.94, 1.2 * 0.342, -1.2 * 0.342, 1.2 * 0.94, 300.0, 300.0] };
|
||||
for ppp in [1.0, 2.0] {
|
||||
for zoom in [0.25f32, 0.5, 1.0, 2.0] {
|
||||
// The ends of the range only: the frame's handles and their grab area are screen-space parts of the
|
||||
// framework's `TransformBox::text_frame` (`controls.rs`, `frame_box`) and the snap reach is a screen distance,
|
||||
// so the zoom only scales the view, with no step in between. 25 % and 200 % at 1x and 2x span 12.5 % to
|
||||
// 200 % in points, which holds 50 % and 100 %.
|
||||
for zoom in [0.25f32, 2.0] {
|
||||
for (name, tf) in [("plain", None), ("scaled", Some(scaled)), ("rotated", Some(rotated))] {
|
||||
let mut app = new_app();
|
||||
assert!(app.ui.extras.snap, "snapping is on by default");
|
||||
|
||||
Reference in new issue
Block a user