mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge pull request #15671 from aiongg/slow-tests-2
Faster engine, GPU and hold-key tests: smaller fixtures, fewer apps
This commit is contained in:
6 files changed
+91
-67
No files matched your search
@@ -842,9 +842,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn a_preview_within_the_full_resolution_budget_is_the_plain_solve_bit_for_bit() {
|
||||
let mut s = textured(300, 300);
|
||||
s.execute("select.rect", json!({"x": 20, "y": 30, "width": 60, "height": 50})).unwrap();
|
||||
for p in [json!({"offset": [120, 90]}), json!({"offset": [120, 90], "rotate": 30, "mode": "extend"})] {
|
||||
// The solves are short on a small canvas and selection; the budget edge is checked on a
|
||||
// canvas that holds a 256 × 256 selection and its move.
|
||||
let mut s = textured(110, 90);
|
||||
s.execute("select.rect", json!({"x": 10, "y": 10, "width": 24, "height": 20})).unwrap();
|
||||
for p in [json!({"offset": [60, 50]}), json!({"offset": [60, 50], "rotate": 30, "mode": "extend"})] {
|
||||
let job = preview(&s, &p).unwrap();
|
||||
assert!(!job.is_coarse());
|
||||
let (got, damage) = job.run(&JobCtx::new()).unwrap();
|
||||
@@ -859,6 +861,7 @@ mod tests {
|
||||
assert!(got.layers[0].surface().unwrap().read_region(b) == want.layers[0].surface().unwrap().read_region(b), "{p}");
|
||||
}
|
||||
// 256 × 256 is the largest selection solved at full resolution.
|
||||
let mut s = textured(300, 300);
|
||||
s.execute("select.rect", json!({"x": 0, "y": 0, "width": 256, "height": 256})).unwrap();
|
||||
assert!(!preview(&s, &json!({"offset": [20, 20]})).unwrap().is_coarse());
|
||||
s.execute("select.rect", json!({"x": 0, "y": 0, "width": 257, "height": 256})).unwrap();
|
||||
@@ -876,7 +879,14 @@ mod tests {
|
||||
s.edit("faint selection", |doc, _| {
|
||||
let mut sel = Surface::new(photocraft_color::PixelFormat::GRAY8);
|
||||
let r = Rect::new(20, 20, 536, 536);
|
||||
let data: Vec<f32> = (r.y0..r.y1).flat_map(|y| (r.x0..r.x1).map(move |x| if x % 4 == 0 && y % 4 == 0 { 1.0 / 255.0 } else { 0.0 })).collect();
|
||||
// Two clusters at opposite corners: the bounds are what scale the preview, and the few
|
||||
// selected pixels keep the solve short.
|
||||
let near = |v: i32| v < r.x0 + 40 || v >= r.x1 - 40;
|
||||
let data: Vec<f32> = (r.y0..r.y1)
|
||||
.flat_map(|y| {
|
||||
(r.x0..r.x1).map(move |x| if x % 4 == 0 && y % 4 == 0 && near(x) && near(y) && (x < 300) == (y < 300) { 1.0 / 255.0 } else { 0.0 })
|
||||
})
|
||||
.collect();
|
||||
sel.write_region(r, &data);
|
||||
doc.selection = Some(sel);
|
||||
Ok(())
|
||||
|
||||
@@ -58,9 +58,11 @@ fn green_doc() -> Session {
|
||||
s
|
||||
}
|
||||
|
||||
/// The same checker on a horizontal grey ramp, constant across each 10 px column.
|
||||
/// The same checker on a horizontal grey ramp, constant across each 10 px column. Cropped to what
|
||||
/// the tests read (the landings end at x 620, y 440): a fill samples the whole canvas, so its
|
||||
/// cost grows with it.
|
||||
fn ramp_doc() -> Session {
|
||||
let mut s = session(800, 600);
|
||||
let mut s = session(640, 460);
|
||||
paint(&mut s, |x, y| {
|
||||
if let Some(v) = checker(x, y) {
|
||||
[v, v, v]
|
||||
|
||||
@@ -1636,12 +1636,16 @@ fn content_aware_move_preview_shows_the_result_without_touching_the_session() {
|
||||
assert!(content_aware_move_preview(&s, &json!({"offset": [70, 0], "mode": "copy"})).is_err());
|
||||
}
|
||||
|
||||
/// A 30×30 object in the middle of a 400×300 selection (over the 256×256 a preview solves at full
|
||||
/// resolution) on a 700×400 canvas, dragged by (250, 60).
|
||||
/// A 30×30 object in a 60×60 selection, with two 8×8 pieces at the corners of a 400×300 bounding
|
||||
/// box (over the 256×256 a preview solves at full resolution) on a 700×400 canvas, dragged by
|
||||
/// (250, 60). The selection's bounds decide the preview's scale and placement; its few selected
|
||||
/// pixels are what the solves work on, which keeps them short.
|
||||
fn large_move(depth: u64) -> Session {
|
||||
let mut s = session(700, 400, depth, "rgb");
|
||||
paint_layer(&mut s, |x, y| if (195..225).contains(&x) && (145..175).contains(&y) { [0.05, 0.1, 0.9, 1.0] } else { texture(x, y) });
|
||||
s.execute("select.rect", json!({"x": 10, "y": 10, "width": 400, "height": 300})).unwrap();
|
||||
s.execute("select.rect", json!({"x": 180, "y": 130, "width": 60, "height": 60})).unwrap();
|
||||
s.execute("select.rect", json!({"x": 10, "y": 10, "width": 8, "height": 8, "mode": "add"})).unwrap();
|
||||
s.execute("select.rect", json!({"x": 402, "y": 302, "width": 8, "height": 8, "mode": "add"})).unwrap();
|
||||
s
|
||||
}
|
||||
|
||||
|
||||
@@ -31,15 +31,14 @@ fn raster(d: &Document, name: &str, bounds: Rect, color: [f32; 4]) -> Layer {
|
||||
layer
|
||||
}
|
||||
|
||||
/// Keeps the measured straight geometry and fits turned controls under the 1 MiB transform limit
|
||||
/// that the preference test can set process-wide.
|
||||
fn scene_divisor(turned: bool) -> i32 {
|
||||
if turned { 2 } else { 1 }
|
||||
}
|
||||
/// The scene is the measured 800 × 500 one at half size: the fills' cost grows with the canvas, and
|
||||
/// turned controls must fit under the 1 MiB transform limit that the preference test can set
|
||||
/// process-wide.
|
||||
const DIVISOR: i32 = 2;
|
||||
|
||||
/// The measured scene, with a deliberately different crop extension colour.
|
||||
fn scene(turned: bool) -> (Session, Layers) {
|
||||
let divisor = scene_divisor(turned);
|
||||
fn scene() -> (Session, Layers) {
|
||||
let divisor = DIVISOR;
|
||||
let rect = |x0, y0, x1, y1| Rect::new(x0 / divisor, y0 / divisor, x1 / divisor, y1 / divisor);
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", json!({"width":800/divisor,"height":500/divisor,"depth":8,"background":"white"})).unwrap();
|
||||
@@ -72,14 +71,13 @@ fn select(s: &mut Session, id: LayerId) {
|
||||
|
||||
/// Extends the frame to the right by one eighth of the original width.
|
||||
fn frame(turned: bool) -> Value {
|
||||
let divisor = scene_divisor(turned);
|
||||
let divisor = DIVISOR;
|
||||
json!({"x":0,"y":0,"width":900/divisor,"height":500/divisor,"angle":if turned { 10 } else { 0 },"deleteCroppedPixels":true})
|
||||
}
|
||||
|
||||
/// Samples the same relative point inside the new strip in both fixture sizes.
|
||||
fn extension_sample(turned: bool) -> (i32, i32) {
|
||||
let divisor = scene_divisor(turned);
|
||||
(850 / divisor, 400 / divisor)
|
||||
fn extension_sample() -> (i32, i32) {
|
||||
(850 / DIVISOR, 400 / DIVISOR)
|
||||
}
|
||||
|
||||
fn crop(s: &mut Session, mut p: Value, aware: bool) {
|
||||
@@ -133,11 +131,11 @@ fn undo_redo(s: &mut Session, before: &Document) {
|
||||
assert_eq!(s.active().unwrap().history.undo_label(), Some("Content-aware Crop"));
|
||||
}
|
||||
|
||||
/// Matches the three measured rows at their original size, bounds and sample points.
|
||||
/// Matches the three measured rows: bounds and sample points, at half the measured size.
|
||||
#[test]
|
||||
fn measured_straight_rows_fill_background_and_only_the_active_raster() {
|
||||
for row in 0..3 {
|
||||
let (mut s, ids) = scene(false);
|
||||
let (mut s, ids) = scene();
|
||||
let active = if row == 1 { ids.edge } else { ids.quads };
|
||||
if row == 2 {
|
||||
s.edit("Layer 0", |d, _| {
|
||||
@@ -155,22 +153,22 @@ fn measured_straight_rows_fill_background_and_only_the_active_raster() {
|
||||
let past = s.active().unwrap().history.past_len();
|
||||
crop(&mut s, p, true);
|
||||
let d = doc(&s);
|
||||
assert_eq!((d.size.width, d.size.height), (900, 500));
|
||||
assert_eq!((d.size.width, d.size.height), (900 / DIVISOR as u32, 500 / DIVISOR as u32));
|
||||
let mut untouched = vec![ids.small, ids.hidden, ids.text];
|
||||
untouched.push(if row == 1 { ids.quads } else { ids.edge });
|
||||
if row == 2 {
|
||||
assert!(d.background().is_none());
|
||||
untouched.push(ids.background);
|
||||
} else {
|
||||
assert_eq!(d.layer(ids.background).unwrap().surface().unwrap().content_bounds(), Rect::new(0, 0, 900, 500));
|
||||
pixel(d, ids.background, 850, 400, WHITE);
|
||||
assert_eq!(d.layer(ids.background).unwrap().surface().unwrap().content_bounds(), Rect::new(0, 0, 900 / DIVISOR, 500 / DIVISOR));
|
||||
pixel(d, ids.background, 850 / DIVISOR, 400 / DIVISOR, WHITE);
|
||||
}
|
||||
let bounds = if row == 1 { Rect::new(600, 0, 900, 500) } else { Rect::new(0, 0, 900, 500) };
|
||||
let bounds = if row == 1 { Rect::new(600 / DIVISOR, 0, 900 / DIVISOR, 500 / DIVISOR) } else { Rect::new(0, 0, 900 / DIVISOR, 500 / DIVISOR) };
|
||||
assert_eq!(d.layer(active).unwrap().surface().unwrap().content_bounds(), bounds);
|
||||
pixel(d, active, 850, if row == 1 { 400 } else { 125 }, if row == 1 { BLUE } else { GREEN });
|
||||
pixel(d, active, 850 / DIVISOR, if row == 1 { 400 / DIVISOR } else { 125 / DIVISOR }, if row == 1 { BLUE } else { GREEN });
|
||||
// The fill adds pixels only where the crop uncovered the canvas: the active layer's own
|
||||
// pixels inside the old canvas are the plain crop's.
|
||||
covered_as_plain(d, &plain, active, Rect::new(0, 0, 800, 500));
|
||||
covered_as_plain(d, &plain, active, Rect::new(0, 0, 800 / DIVISOR, 500 / DIVISOR));
|
||||
unchanged(d, &plain, &untouched);
|
||||
named_one_step(&s, past, "Content-aware Crop");
|
||||
undo_redo(&mut s, &before);
|
||||
@@ -180,9 +178,9 @@ fn measured_straight_rows_fill_background_and_only_the_active_raster() {
|
||||
/// Checks own-layer donors and exact non-target parity after rotation.
|
||||
#[test]
|
||||
fn turned_rows_sample_each_target_and_leave_other_layers_at_plain_crop() {
|
||||
let (x, y) = extension_sample(true);
|
||||
let (x, y) = extension_sample();
|
||||
for row in 0..3 {
|
||||
let (mut s, ids) = scene(true);
|
||||
let (mut s, ids) = scene();
|
||||
// Uniform donors isolate target selection from the existing turned-fill sampling policy.
|
||||
s.edit("Uniform Quads", |d, _| {
|
||||
let fmt = d.pixel_format();
|
||||
@@ -222,8 +220,8 @@ fn turned_rows_sample_each_target_and_leave_other_layers_at_plain_crop() {
|
||||
#[test]
|
||||
fn background_active_is_not_a_second_target() {
|
||||
for turned in [false, true] {
|
||||
let (x, y) = extension_sample(turned);
|
||||
let (mut s, ids) = scene(turned);
|
||||
let (x, y) = extension_sample();
|
||||
let (mut s, ids) = scene();
|
||||
select(&mut s, ids.background);
|
||||
let p = frame(turned);
|
||||
let plain = plain_control(&mut s, &p);
|
||||
@@ -244,9 +242,9 @@ fn background_active_is_not_a_second_target() {
|
||||
#[test]
|
||||
fn unmeasured_active_targets_and_delete_off_keep_the_legacy_target() {
|
||||
for turned in [false, true] {
|
||||
let (x, y) = extension_sample(turned);
|
||||
let (x, y) = extension_sample();
|
||||
for (text, locked_group, delete) in [(true, false, true), (false, true, true), (false, false, false)] {
|
||||
let (mut s, ids) = scene(turned);
|
||||
let (mut s, ids) = scene();
|
||||
let active = if text { ids.text } else { ids.quads };
|
||||
if locked_group {
|
||||
s.edit("Group active", |d, _| {
|
||||
@@ -273,13 +271,13 @@ fn unmeasured_active_targets_and_delete_off_keep_the_legacy_target() {
|
||||
/// Checks the plain history name for interior crops and crops with synthesis disabled.
|
||||
#[test]
|
||||
fn no_fill_or_content_aware_off_keeps_the_crop_history_name() {
|
||||
for (p, aware, turned) in [
|
||||
(json!({"x":20,"y":20,"width":40,"height":30}), true, false),
|
||||
(json!({"x":20,"y":20,"width":40,"height":30,"angle":10}), true, true),
|
||||
(frame(false), false, false),
|
||||
(frame(true), false, true),
|
||||
for (p, aware) in [
|
||||
(json!({"x":20,"y":20,"width":40,"height":30}), true),
|
||||
(json!({"x":20,"y":20,"width":40,"height":30,"angle":10}), true),
|
||||
(frame(false), false),
|
||||
(frame(true), false),
|
||||
] {
|
||||
let (mut s, ids) = scene(turned);
|
||||
let (mut s, ids) = scene();
|
||||
select(&mut s, ids.quads);
|
||||
let past = s.active().unwrap().history.past_len();
|
||||
crop(&mut s, p, aware);
|
||||
@@ -332,8 +330,8 @@ fn turned_hidden_overhang_coverage_belongs_to_each_layer() {
|
||||
#[test]
|
||||
fn donorless_added_target_keeps_the_background_fill() {
|
||||
for turned in [false, true] {
|
||||
let (x, y) = extension_sample(turned);
|
||||
let (mut s, ids) = scene(turned);
|
||||
let (x, y) = extension_sample();
|
||||
let (mut s, ids) = scene();
|
||||
let empty = s
|
||||
.edit("Empty target", |d, active| {
|
||||
let layer = Layer::raster("Empty", d.pixel_format());
|
||||
|
||||
@@ -486,12 +486,13 @@ fn shadows_and_highlights_with_per_pixel_stages() {
|
||||
cr! { shadows: 30.0, highlights: -30.0, whites: 40.0, blacks: -30.0, encoding_gamma: 1.8},
|
||||
],
|
||||
);
|
||||
// At the dialog's proxy size, at one depth: the depth only changes how the input is
|
||||
// At the dialog's proxy width, at one depth: the depth only changes how the input is
|
||||
// quantized (8 and 16 bits both develop with `float = false`), and every depth already ran
|
||||
// above at 171×113. The size is what matters here (subsampled pyramid levels).
|
||||
// above at 171×113. The long side is what matters here (subsampled pyramid levels); the short
|
||||
// one only needs to keep several levels, so the frame is a strip.
|
||||
let Some(mut g) = gpu() else { return };
|
||||
let d = compare_at(&mut g, &all, Depth::Sixteen, (858, 572));
|
||||
eprintln!("shadows/highlights + per pixel 858x572: max |GPU - CPU| = {d:.2e}");
|
||||
let d = compare_at(&mut g, &all, Depth::Sixteen, (858, 120));
|
||||
eprintln!("shadows/highlights + per pixel 858x120: max |GPU - CPU| = {d:.2e}");
|
||||
}
|
||||
|
||||
/// Asserts that each of `sets` moves some pixel of the test image by over 2 %, so a comparison
|
||||
@@ -564,10 +565,12 @@ fn clarity_texture_and_dehaze_with_shadows_highlights_and_per_pixel_stages() {
|
||||
];
|
||||
check("clarity/texture/dehaze + shadows/highlights + per pixel", &sets);
|
||||
let Some(mut g) = gpu() else { return };
|
||||
// At the dialog's proxy size (Dehaze and Clarity on a copy subsampled twice), and wider (three
|
||||
// At the dialog's proxy width (Dehaze and Clarity on a copy subsampled twice), and wider (three
|
||||
// times). One depth per size: the depth only changes how the input is quantized (8 and 16
|
||||
// bits both develop with `float = false`), and every depth already ran above at 171×113.
|
||||
for (size, depth) in [((858, 572), Depth::Eight), ((1600, 900), Depth::Float)] {
|
||||
// bits both develop with `float = false`), and every depth already ran above at 171×113. The
|
||||
// long side sets the subsampling; the short one only needs to keep several pyramid levels, so
|
||||
// the frames are strips.
|
||||
for (size, depth) in [((858, 120), Depth::Eight), ((1600, 120), Depth::Float)] {
|
||||
let d = compare_at(&mut g, &all, depth, size);
|
||||
eprintln!("everything {size:?} {depth:?}: max |GPU - CPU| = {d:.2e}");
|
||||
}
|
||||
|
||||
@@ -350,9 +350,13 @@ fn cmd_gives_the_move_tool_only_where_the_tool_does_not_take_cmd() {
|
||||
// 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`).
|
||||
// One app per group, with the tool switched between cases and a fresh layer for each: starting
|
||||
// the whole app dominates the cost of a case.
|
||||
let moves = [Tool::Brush, Tool::Gradient, Tool::CloneStamp, Tool::Eyedropper, Tool::Move, Tool::RectMarquee, Tool::Lasso];
|
||||
let mut h = harness(moves[0]);
|
||||
for tool in moves {
|
||||
let mut h = harness(tool);
|
||||
h.state_mut().ui.tool = tool;
|
||||
h.run_steps(1);
|
||||
let id = with_layer(&mut h);
|
||||
let steps = h.state().session.active().unwrap().history.past_len();
|
||||
drag_with(&mut h, Modifiers::COMMAND, 130.0, 130.0, 170.0, 150.0);
|
||||
@@ -362,28 +366,31 @@ fn cmd_gives_the_move_tool_only_where_the_tool_does_not_take_cmd() {
|
||||
assert_eq!(st.history.past_len(), steps + 1, "{tool:?}: one step, nothing painted");
|
||||
assert_eq!(h.state().ui.tool, tool, "{tool:?}: the tool is back");
|
||||
}
|
||||
// The Crop and Rotate View tools go last, in an app of their own: they leave a pending crop and
|
||||
// a turned view behind.
|
||||
let keeps = [
|
||||
Tool::Hand,
|
||||
Tool::RotateView,
|
||||
Tool::Zoom,
|
||||
Tool::Pen,
|
||||
Tool::Rectangle,
|
||||
Tool::Type,
|
||||
Tool::VerticalType,
|
||||
Tool::Crop,
|
||||
Tool::PathSelection,
|
||||
Tool::DirectSelection,
|
||||
vec![Tool::Hand, Tool::Zoom, Tool::Pen, Tool::Rectangle, Tool::Type, Tool::VerticalType, Tool::PathSelection, Tool::DirectSelection],
|
||||
vec![Tool::Crop, Tool::RotateView],
|
||||
];
|
||||
for tool in keeps {
|
||||
let mut h = harness(tool);
|
||||
let id = with_layer(&mut h);
|
||||
drag_with(&mut h, Modifiers::COMMAND, 130.0, 130.0, 170.0, 150.0);
|
||||
assert_eq!(bounds(&h, id), Rect::new(100, 100, 160, 160), "{tool:?}: the layer stays");
|
||||
assert_ne!(h.state().session.active().unwrap().history.undo_label(), Some("Move"), "{tool:?}");
|
||||
assert_eq!(h.state().ui.tool, tool);
|
||||
for group in keeps {
|
||||
let mut h = harness(group[0]);
|
||||
for tool in group {
|
||||
h.state_mut().ui.tool = tool;
|
||||
h.run_steps(1);
|
||||
keeps_the_layer(&mut h, tool);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A ⌘-drag with `tool`, one that keeps ⌘ for itself, leaves a fresh layer where it is.
|
||||
fn keeps_the_layer(h: &mut Harness<'static, Box<PhotocraftApp>>, tool: Tool) {
|
||||
let id = with_layer(h);
|
||||
drag_with(h, Modifiers::COMMAND, 130.0, 130.0, 170.0, 150.0);
|
||||
assert_eq!(bounds(h, id), Rect::new(100, 100, 160, 160), "{tool:?}: the layer stays");
|
||||
assert_ne!(h.state().session.active().unwrap().history.undo_label(), Some("Move"), "{tool:?}");
|
||||
assert_eq!(h.state().ui.tool, tool);
|
||||
}
|
||||
|
||||
/// ⌘⌥-drag duplicates the layer first and moves the copy, as the Move tool's ⌥-drag does. Off
|
||||
/// the Mac the same keys are Ctrl+Alt, which the Brush keeps for its on-canvas resize
|
||||
/// (`brush_resize`, Alt+right-drag there too), so Ctrl+Alt duplicates with the tools that have no
|
||||
|
||||
Reference in new issue
Block a user