mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge remote-tracking branch 'upstream/main' into slow-ui-tests
# Conflicts: # crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs
This commit is contained in:
commit
662f2e24d5
20 files changed
+449
-264
No files matched your search
@@ -19,27 +19,30 @@ fn edited_psd_roundtrip_is_checked_and_bad_expectations_fail() {
|
||||
.unwrap();
|
||||
assert!(made.status.success(), "{}", String::from_utf8_lossy(&made.stderr));
|
||||
let hash = xtask::sha256::hex(&fs::read(&base).unwrap());
|
||||
let mut recipe = json!({"version":1,"corpus_revision":"synthetic","cases":[{
|
||||
"id":"style", "base":"base.psd", "base_sha256":hash, "target":{"kind":"Type","name":"Oracle"},
|
||||
"commands":[{"command":"type.antiAlias.crisp","params":{}}],
|
||||
"checks":[{"op":"changed_to","path":"/text/antialias","value":"Crisp"},{"op":"unchanged","path":"/text/text"}]
|
||||
}]});
|
||||
// One run with a right and a wrong expectation of the same edit: the runner hashes the CLI,
|
||||
// asks git and makes its output directory once, and still has to report the first case as
|
||||
// passing and the second as failing (and fail itself).
|
||||
let case = |id: &str, value: &str| {
|
||||
json!({
|
||||
"id":id, "base":"base.psd", "base_sha256":hash, "target":{"kind":"Type","name":"Oracle"},
|
||||
"commands":[{"command":"type.antiAlias.crisp","params":{}}],
|
||||
"checks":[{"op":"changed_to","path":"/text/antialias","value":value},{"op":"unchanged","path":"/text/text"}]
|
||||
})
|
||||
};
|
||||
let recipe = json!({"version":1,"corpus_revision":"synthetic","cases":[case("style", "Crisp"), case("wrong", "Sharp")]});
|
||||
let recipe_path = root.join("recipes.json");
|
||||
let src = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
|
||||
fs::write(&recipe_path, serde_json::to_vec(&recipe).unwrap()).unwrap();
|
||||
let cli_path = Path::new(&cli).to_str().unwrap();
|
||||
let corpus = root.to_str().unwrap();
|
||||
let recipe_name = recipe_path.to_str().unwrap();
|
||||
let output = root.join("success");
|
||||
let output = root.join("report");
|
||||
let args = [recipe_name, corpus, cli_path, output.to_str().unwrap()];
|
||||
xtask::psd_write_oracle::run(&src, &args).unwrap();
|
||||
assert!(xtask::psd_write_oracle::run(&src, &args).is_err(), "a failing case fails the run");
|
||||
let report: Value = serde_json::from_slice(&fs::read(output.join("report.json")).unwrap()).unwrap();
|
||||
assert_eq!(report["cases"][0]["id"], "style");
|
||||
assert_eq!(report["cases"][0]["status"], "pass");
|
||||
assert_eq!(report["cases"][0]["photoshop"]["opens"], "not_run");
|
||||
recipe["cases"][0]["checks"][0]["value"] = json!("Sharp");
|
||||
fs::write(&recipe_path, serde_json::to_vec(&recipe).unwrap()).unwrap();
|
||||
let bad_output = root.join("failure");
|
||||
assert!(xtask::psd_write_oracle::run(&src, &[recipe_name, corpus, cli_path, bad_output.to_str().unwrap()]).is_err());
|
||||
let bad: Value = serde_json::from_slice(&fs::read(bad_output.join("report.json")).unwrap()).unwrap();
|
||||
assert_eq!(bad["cases"][0]["status"], "fail");
|
||||
assert_eq!(report["cases"][1]["id"], "wrong");
|
||||
assert_eq!(report["cases"][1]["status"], "fail");
|
||||
}
|
||||
@@ -891,7 +891,9 @@ mod tests {
|
||||
let b = got.bounds();
|
||||
let before = s.active().unwrap().doc.layers[0].surface().unwrap().read_region(b);
|
||||
assert!(got.layers[0].surface().unwrap().read_region(b) != before, "the preview moves something");
|
||||
s.execute("paint.contentAwareMove", p).unwrap();
|
||||
// That the command takes this selection too is shown by `preview` above: it runs the
|
||||
// command's own `plan`, which rejects an empty selection, at full resolution. The
|
||||
// command's full-resolution solve is left out: nothing here checked its result.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -115,8 +115,10 @@ fn the_core_fit_shifts_brightness_and_leaves_a_hue_alone() {
|
||||
#[test]
|
||||
fn color_ten_on_green_leaves_the_middle_and_blends_the_edge() {
|
||||
// Selection 120,120 40×40 dragged (140,140) → (600,420). Row y 420 is the middle of the landing.
|
||||
// Color 0 is only read at the landing, which Extend makes as Move does (`run_move` step 1),
|
||||
// without Move's second fill of the old place.
|
||||
let mut kept = green_doc();
|
||||
select_and_move(&mut kept, [120, 120, 40, 40], [460, 280], 0, "move");
|
||||
select_and_move(&mut kept, [120, 120, 40, 40], [460, 280], 0, "extend");
|
||||
let mut fitted = green_doc();
|
||||
select_and_move(&mut fitted, [120, 120, 40, 40], [460, 280], 10, "move");
|
||||
|
||||
@@ -144,9 +146,12 @@ fn color_ten_on_green_leaves_the_middle_and_blends_the_edge() {
|
||||
|
||||
#[test]
|
||||
fn a_brightness_change_shifts_the_middle_only_past_color_five() {
|
||||
// Every check reads the landing, which Move and Extend make with the same code (`run_move`
|
||||
// step 1); Extend skips Move's fill of the old place, which nothing here reads. The drop
|
||||
// straight down below stays a Move.
|
||||
let row = |color: u64| {
|
||||
let mut s = ramp_doc();
|
||||
select_and_move(&mut s, [120, 120, 40, 40], [460, 280], color, "move");
|
||||
select_and_move(&mut s, [120, 120, 40, 40], [460, 280], color, "extend");
|
||||
(levels(&s, 590, 420), levels(&s, 600, 420))
|
||||
};
|
||||
let (light, dark) = row(0);
|
||||
@@ -171,21 +176,23 @@ fn a_brightness_change_shifts_the_middle_only_past_color_five() {
|
||||
|
||||
#[test]
|
||||
fn a_flat_patch_matches_the_new_surroundings_at_color_ten() {
|
||||
let middle = |color: u64, mode: &str| {
|
||||
let moved_with = |color: u64, mode: &str| {
|
||||
let mut s = flat_doc();
|
||||
select_and_move(&mut s, [150, 250, 100, 100], [400, 0], color, mode);
|
||||
levels(&s, 600, 300)
|
||||
s
|
||||
};
|
||||
for mode in ["move", "extend"] {
|
||||
assert_eq!(middle(0, mode), [204, 204, 204], "{mode} color 0 keeps 204");
|
||||
assert_eq!(middle(3, mode), [204, 204, 204], "{mode} color 3 leaves the middle");
|
||||
assert_eq!(middle(10, mode), [51, 51, 51], "{mode} color 10 becomes 51");
|
||||
// Move and Extend land the content with the same code (`run_move` step 1); Move only adds
|
||||
// the fill of the old place, away from the landing. So Colors 0 and 3 run once (Extend, one
|
||||
// fill instead of two), and Color 10 runs in both modes, whose landings are compared pixel
|
||||
// by pixel below.
|
||||
assert_eq!(levels(&moved_with(0, "extend"), 600, 300), [204, 204, 204], "color 0 keeps 204");
|
||||
assert_eq!(levels(&moved_with(3, "extend"), 600, 300), [204, 204, 204], "color 3 leaves the middle");
|
||||
let moved = moved_with(10, "move");
|
||||
let extended = moved_with(10, "extend");
|
||||
for (mode, s) in [("move", &moved), ("extend", &extended)] {
|
||||
assert_eq!(levels(s, 600, 300), [51, 51, 51], "{mode} color 10 becomes 51");
|
||||
}
|
||||
// The landing itself agrees; the old place is the part Move refills and Extend keeps.
|
||||
let mut moved = flat_doc();
|
||||
select_and_move(&mut moved, [150, 250, 100, 100], [400, 0], 10, "move");
|
||||
let mut extended = flat_doc();
|
||||
select_and_move(&mut extended, [150, 250, 100, 100], [400, 0], 10, "extend");
|
||||
for y in [256, 300, 340] {
|
||||
for x in [556, 600, 640] {
|
||||
assert_eq!(levels(&moved, x, y), levels(&extended, x, y), "move and extend agree at {x},{y}");
|
||||
|
||||
@@ -339,4 +339,53 @@ mod tests {
|
||||
assert!(c.covered(6, 0, m, None), "x = 4");
|
||||
assert!(!c.covered(7, 0, m, None), "x = 5");
|
||||
}
|
||||
|
||||
/// The active layer is a second fill target only as a visible, unlocked pixel layer with
|
||||
/// visible, unlocked ancestors: each unmeasured state keeps the Background alone. Every state
|
||||
/// here is a pure function of the layer tree; `crop_content_aware_layers.rs` runs a few of them
|
||||
/// through `image.crop`.
|
||||
#[test]
|
||||
fn only_a_visible_unlocked_active_raster_adds_a_target() {
|
||||
use photocraft_doc::{Layer, LayerContent, TextLayer};
|
||||
let mut s = crate::Session::new();
|
||||
s.execute("file.new", serde_json::json!({"width": 8, "height": 8, "background": "white"})).unwrap();
|
||||
let base = (*s.active().unwrap().doc).clone();
|
||||
let fmt = base.pixel_format();
|
||||
let background = base.background().unwrap().id;
|
||||
// The active layer `layer`, at the root or inside a group that `ancestor` edits.
|
||||
let with = |layer: Layer, ancestor: Option<fn(&mut Layer)>| {
|
||||
let mut d = base.clone();
|
||||
let id = layer.id;
|
||||
match ancestor {
|
||||
None => d.layers.push(layer),
|
||||
Some(edit) => {
|
||||
let mut group = Layer::group("Ancestor", vec![layer]);
|
||||
edit(&mut group);
|
||||
d.layers.push(group);
|
||||
}
|
||||
}
|
||||
(additional_target(&d, Some(id)), id)
|
||||
};
|
||||
let (got, id) = with(Layer::raster("Active", fmt), None);
|
||||
assert_eq!(got, Some(id), "a visible, unlocked raster");
|
||||
let plain_group: fn(&mut Layer) = |_| {};
|
||||
let (got, id) = with(Layer::raster("Active", fmt), Some(plain_group));
|
||||
assert_eq!(got, Some(id), "inside a visible, unlocked group");
|
||||
let text = Layer::new("T", LayerContent::Text(TextLayer { text: "T".into(), ..Default::default() }));
|
||||
assert_eq!(with(text, None).0, None, "a type layer");
|
||||
let mut hidden = Layer::raster("Active", fmt);
|
||||
hidden.visible = false;
|
||||
assert_eq!(with(hidden, None).0, None, "a hidden layer");
|
||||
for lock in ["all", "pixels", "transparency", "position", "artboard"] {
|
||||
let mut locked = Layer::raster("Active", fmt);
|
||||
assert!(locked.locks.set(lock, true));
|
||||
assert_eq!(with(locked, None).0, None, "lock {lock}");
|
||||
}
|
||||
let hidden_group: fn(&mut Layer) = |g| g.visible = false;
|
||||
assert_eq!(with(Layer::raster("Active", fmt), Some(hidden_group)).0, None, "a hidden ancestor");
|
||||
let locked_group: fn(&mut Layer) = |g| assert!(g.locks.set("pixels", true));
|
||||
assert_eq!(with(Layer::raster("Active", fmt), Some(locked_group)).0, None, "a locked ancestor");
|
||||
assert_eq!(additional_target(&base, Some(background)), None, "the Background itself");
|
||||
assert_eq!(additional_target(&base, None), None, "no active layer");
|
||||
}
|
||||
}
|
||||
@@ -236,34 +236,24 @@ fn background_active_is_not_a_second_target() {
|
||||
}
|
||||
|
||||
/// Verifies Background-only fill for ineligible active layers and Delete Cropped Pixels off.
|
||||
/// Which active layers are a second target is a pure function of the layer tree, checked for every
|
||||
/// unmeasured state (type, hidden, each lock, hidden or locked ancestor) by `crop_fill`'s
|
||||
/// `only_a_visible_unlocked_active_raster_adds_a_target`. Through the command, straight and
|
||||
/// turned, run one state the layer itself rules out (type), one an ancestor rules out (a locked
|
||||
/// group) and Delete Cropped Pixels off, its own branch of `fill_uncovered`.
|
||||
#[test]
|
||||
fn unmeasured_active_targets_and_delete_off_keep_the_legacy_target() {
|
||||
for turned in [false, true] {
|
||||
let (x, y) = extension_sample(turned);
|
||||
for case in 0..10 {
|
||||
for (text, locked_group, delete) in [(true, false, true), (false, true, true), (false, false, false)] {
|
||||
let (mut s, ids) = scene(turned);
|
||||
let active = match case {
|
||||
0 => ids.text,
|
||||
1 => ids.hidden,
|
||||
_ => ids.quads,
|
||||
};
|
||||
if (2..7).contains(&case) {
|
||||
s.edit("Lock active", |d, _| {
|
||||
assert!(d.layer_mut(active).unwrap().locks.set(["all", "pixels", "transparency", "position", "artboard"][case - 2], true));
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
if case >= 8 {
|
||||
let active = if text { ids.text } else { ids.quads };
|
||||
if locked_group {
|
||||
s.edit("Group active", |d, _| {
|
||||
let i = d.layers.iter().position(|layer| layer.id == active).unwrap();
|
||||
let child = d.layers.remove(i);
|
||||
let mut group = Layer::group("Ancestor", vec![child]);
|
||||
if case == 8 {
|
||||
group.visible = false;
|
||||
} else {
|
||||
assert!(group.locks.set("pixels", true));
|
||||
}
|
||||
assert!(group.locks.set("pixels", true));
|
||||
d.layers.insert(i, group);
|
||||
Ok(())
|
||||
})
|
||||
@@ -271,9 +261,7 @@ fn unmeasured_active_targets_and_delete_off_keep_the_legacy_target() {
|
||||
}
|
||||
select(&mut s, active);
|
||||
let mut p = frame(turned);
|
||||
if case == 7 {
|
||||
p["deleteCroppedPixels"] = json!(false);
|
||||
}
|
||||
p["deleteCroppedPixels"] = json!(delete);
|
||||
let plain = plain_control(&mut s, &p);
|
||||
crop(&mut s, p, true);
|
||||
pixel(doc(&s), ids.background, x, y, WHITE);
|
||||
|
||||
@@ -474,27 +474,31 @@ fn root_checkpoints_keep_clipping_groups_and_adjustments_whole() {
|
||||
fn disjoint_partial_damages_admit_whole_chunks_not_damage_rects() {
|
||||
let Some(mut g) = gpu() else { return };
|
||||
let mut doc = base_doc(600, 300);
|
||||
doc.layers.push(noise_layer("middle", PixelFormat::RGBA8, doc.bounds(), 2, 0.2));
|
||||
doc.layers.push(noise_layer("top", PixelFormat::RGBA8, doc.bounds(), 3, 0.2));
|
||||
// Each layer in a pass of its own (`alone`): batched into one run, the stack has no
|
||||
// checkpoint below the top layer, so no render would capture and the byte count could not
|
||||
// grow whatever the admission did.
|
||||
doc.layers.push(alone(noise_layer("middle", PixelFormat::RGBA8, doc.bounds(), 2, 0.2)));
|
||||
doc.layers.push(alone(noise_layer("top", PixelFormat::RGBA8, doc.bounds(), 3, 0.2)));
|
||||
check(&mut g, &doc, "warm");
|
||||
// Each series paints 8 rectangles. The second series' rectangles are all new (7 px across
|
||||
// and 65 px down from the first's) but in the same chunk (the 600 x 300 document is one
|
||||
// chunk at `CHUNK`), so a cache entry per damage rectangle would add 8 entries. (The four
|
||||
// series of 24 this replaces painted the same 24 rectangles every time.)
|
||||
let strokes = |g: &mut Gpu, doc: &Document, pass: i32| {
|
||||
for i in 0..24u32 {
|
||||
let x = 40 + ((i + pass as u32 * 13) % 8) * 60;
|
||||
let y = 30 + (i / 8) * 60;
|
||||
diff_rect(g, doc, Rect::new(x as i32, y as i32, x as i32 + 40, y as i32 + 30), "stroke").unwrap();
|
||||
for i in 0..8 {
|
||||
let (x, y) = (40 + i * 60 + pass * 7, 30 + pass * 65);
|
||||
diff_rect(g, doc, Rect::new(x, y, x + 40, y + 30), "stroke").unwrap();
|
||||
}
|
||||
};
|
||||
for pass in 0..2 {
|
||||
doc.layers[2].opacity = 0.3 + pass as f32 * 0.1;
|
||||
strokes(&mut g, &doc, pass);
|
||||
}
|
||||
// The same grid chunks hold every stroke: no entry-per-rectangle growth between passes.
|
||||
doc.layers[2].opacity = 0.3;
|
||||
strokes(&mut g, &doc, 0);
|
||||
// The same grid chunks hold every stroke: no entry-per-rectangle growth between series.
|
||||
let bytes = g.comp.composite_cache_bytes();
|
||||
assert!(bytes > 0);
|
||||
for pass in 2..4 {
|
||||
doc.layers[2].opacity = 0.3 + pass as f32 * 0.1;
|
||||
strokes(&mut g, &doc, pass);
|
||||
}
|
||||
// 0.6, the last opacity the four series this replaces left, so what follows renders the
|
||||
// same document as before.
|
||||
doc.layers[2].opacity = 0.6;
|
||||
strokes(&mut g, &doc, 1);
|
||||
assert_eq!(g.comp.composite_cache_bytes(), bytes, "partial damages must not add entries");
|
||||
// A full-canvas render still populates the whole chunks, and the top edit afterwards hits.
|
||||
check(&mut g, &doc, "full refresh after strokes");
|
||||
@@ -1425,7 +1429,12 @@ fn small_layers_composite_over_their_bounds() {
|
||||
check(&mut g, &big, "small layers across chunks");
|
||||
}
|
||||
|
||||
fn many_layers_submit_inside_one_chunk_mode(paged: bool) {
|
||||
/// One compositor is enough: at 16 x 12 the document is one page and one chunk under the whole
|
||||
/// texture limit and under [`PAGED_LIMIT`] alike, and both draw it through the same `run_cell`.
|
||||
/// The paged run this replaces reported the same `Stats`, field for field (1202 passes, 2401
|
||||
/// tiles uploaded, 1 flush, 1 chunk, 1 cell).
|
||||
#[test]
|
||||
fn many_layers_submit_inside_one_chunk_whole() {
|
||||
// P12: a refresh recorded every pass of a page cell into one command buffer, and with a few
|
||||
// hundred layers Metal ran out of command buffers (device lost, "pc_compose_uniforms is
|
||||
// invalid"). 1200 layers need well over 1000 passes in the document's only chunk: each is
|
||||
@@ -1443,24 +1452,13 @@ fn many_layers_submit_inside_one_chunk_mode(paged: bool) {
|
||||
d.layers.push(l);
|
||||
}
|
||||
let cpu = photocraft_compose::render(&d, d.bounds());
|
||||
let comp = if paged { &mut g.paged } else { &mut g.comp };
|
||||
let (out, stats) = photocraft_gpu::render_to_vec_stats(comp, &g.device, &g.queue, &d, d.bounds()).unwrap();
|
||||
assert!(worst_diff(&cpu.px, &out).0 <= TOL, "1200 layers, paged={paged}");
|
||||
let (out, stats) = photocraft_gpu::render_to_vec_stats(&mut g.comp, &g.device, &g.queue, &d, d.bounds()).unwrap();
|
||||
assert!(worst_diff(&cpu.px, &out).0 <= TOL, "1200 layers");
|
||||
assert_eq!(stats.layers_batched, 0, "{stats:?}");
|
||||
assert_eq!(stats.chunks, 1);
|
||||
assert!(stats.flushes > 0, "{stats:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn many_layers_submit_inside_one_chunk_whole() {
|
||||
many_layers_submit_inside_one_chunk_mode(false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn many_layers_submit_inside_one_chunk_paged() {
|
||||
many_layers_submit_inside_one_chunk_mode(true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runs_of_plain_layers_blend_in_one_pass() {
|
||||
// Consecutive plain layers are drawn several to a pass (`fs_layerbatch`). Every layer mode at
|
||||
@@ -1901,8 +1899,19 @@ fn fx_check(g: &mut Gpu, doc: &Document, what: &str) -> photocraft_gpu::Stats {
|
||||
fn layer_effects_every_kind() {
|
||||
let Some(mut g) = gpu() else { return };
|
||||
let mut failures = Vec::new();
|
||||
// On the GPU a 16-bit document differs only in the layer upload
|
||||
// (`convert::rgb_gray16_to_f16`) and in what that input does to Dissolve's threshold and to
|
||||
// pattern pixels: 16 bits run every Dissolve and pattern case, and the full stack (every kind
|
||||
// at once) for the rest. Every case runs at 8 bits.
|
||||
let depth_sensitive = |fx: &[Effect]| {
|
||||
let text = format!("{fx:?}");
|
||||
text.contains("Dissolve") || text.contains("Pattern")
|
||||
};
|
||||
for depth in [SampleType::U8, SampleType::U16] {
|
||||
for (name, fx) in effect_cases() {
|
||||
if depth == SampleType::U16 && name != "full stack" && !depth_sensitive(&fx) {
|
||||
continue;
|
||||
}
|
||||
let mut d = fx_doc(96, 80, depth);
|
||||
d.patterns.push(checker_pattern());
|
||||
let mut l = blob("fx", d.pixel_format(), 46.0, 40.0, 22.0, [0.9, 0.4, 0.2]);
|
||||
@@ -1985,6 +1994,12 @@ fn exterior_effects_merge_from_the_shape_at_any_fill() {
|
||||
];
|
||||
for depth in [SampleType::U8, SampleType::U16] {
|
||||
for (name, fx) in &stacks {
|
||||
// The merge (`effect_exterior`, `fs_fxmerge`) has no depth branch on the GPU or the
|
||||
// CPU: depth only changes how the layer is uploaded (`convert::rgb_gray16_to_f16`). The
|
||||
// stack with both effects covers that at 16 bits; every stack runs at 8 bits.
|
||||
if depth == SampleType::U16 && *name != "shadow and glow" {
|
||||
continue;
|
||||
}
|
||||
for (opacity, fill, blend) in [
|
||||
(1.0, 1.0, BlendMode::Normal),
|
||||
(0.8, 0.6, BlendMode::Normal),
|
||||
@@ -3084,30 +3099,50 @@ fn unbuildable_pipelines_are_an_error_not_a_panic() {
|
||||
|
||||
/// A document several pages wide under [`PAGED_LIMIT`]: pixel layers crossing page borders (one
|
||||
/// masked, one off-canvas), a big effect layer whose region exceeds the limit (maps built per
|
||||
/// page cell), a type layer with a shadow, an adjustment, a clipped group and a gradient fill.
|
||||
/// page cell), a type layer with a shadow across a border, an adjustment, a clipped group and a
|
||||
/// gradient fill. 1100 x 900 (5 x 4 pages) for the residency and budget tests, whose views and
|
||||
/// ratios are measured on it.
|
||||
fn big_doc() -> Document {
|
||||
let (w, h) = (1100, 900);
|
||||
big_doc_sized(false)
|
||||
}
|
||||
|
||||
/// [`big_doc`] at 660 x 580, 3 x 3 pages, with every layer moved and sized to cross the same
|
||||
/// borders: the middle cell has page borders on all four sides and the four inner page corners,
|
||||
/// so it holds every border and corner case of the larger document at about 40 % of its pixels.
|
||||
fn small_big_doc() -> Document {
|
||||
big_doc_sized(true)
|
||||
}
|
||||
|
||||
fn big_doc_sized(small: bool) -> Document {
|
||||
// Each geometry as (1100 x 900 value, 660 x 580 value).
|
||||
let pick = |large: [i32; 4], reduced: [i32; 4]| {
|
||||
let [x0, y0, x1, y1] = if small { reduced } else { large };
|
||||
Rect::new(x0, y0, x1, y1)
|
||||
};
|
||||
let (w, h) = if small { (660, 580) } else { (1100, 900) };
|
||||
let mut d = fx_doc(w, h, SampleType::U8);
|
||||
// Right over the background: adjustment results round to 8 bits, which would turn sub-LSB
|
||||
// float differences of blends beneath into whole steps.
|
||||
let mut adj = Layer::new("invert", LayerContent::Adjustment(Adjustment::Invert));
|
||||
adj.opacity = 0.6;
|
||||
adj.mask = Some(mask(Rect::new(240, 0, 800, 520), 83, 0.0));
|
||||
adj.mask = Some(mask(pick([240, 0, 800, 520], [240, 0, 560, 520]), 83, 0.0));
|
||||
d.layers.push(adj);
|
||||
let mut top = noise_layer("top", PixelFormat::RGBA8, Rect::new(-30, 200, 700, 820), 81, 0.0);
|
||||
let mut top = noise_layer("top", PixelFormat::RGBA8, pick([-30, 200, 700, 820], [-30, 200, 620, 600]), 81, 0.0);
|
||||
top.blend = BlendMode::Multiply;
|
||||
top.mask = Some(mask(Rect::new(100, 240, 600, 700), 82, 1.0));
|
||||
top.mask = Some(mask(pick([100, 240, 600, 700], [100, 240, 500, 540]), 82, 1.0));
|
||||
d.layers.push(top);
|
||||
let stack = effect_cases().into_iter().find(|(n, _)| *n == "full stack").unwrap().1;
|
||||
let mut big = blob("big", d.pixel_format(), 520.0, 450.0, 330.0, [0.9, 0.4, 0.2]);
|
||||
let (bx, by, br) = if small { (330.0, 290.0, 200.0) } else { (520.0, 450.0, 330.0) };
|
||||
let mut big = blob("big", d.pixel_format(), bx, by, br, [0.9, 0.4, 0.2]);
|
||||
big.effects.items = stack;
|
||||
big.effects.items.push(Effect::OuterGlow(glow(FxPaint::Color(Color::rgb(0.2, 1.0, 0.6)), GlowTechnique::Softer, 40.0, 0.2, GlowSource::Edge)));
|
||||
d.layers.push(big);
|
||||
let mut text = as_text(blob("type", d.pixel_format(), 900.0, 150.0, 90.0, [0.1, 0.2, 0.9]));
|
||||
let (tx, ty, tr) = if small { (560.0, 120.0, 60.0) } else { (900.0, 150.0, 90.0) };
|
||||
let mut text = as_text(blob("type", d.pixel_format(), tx, ty, tr, [0.1, 0.2, 0.9]));
|
||||
text.effects.items = vec![Effect::DropShadow(shadow(BlendMode::Multiply, 0.8, 135.0, 12.0, 20.0, 0.0))];
|
||||
d.layers.push(text);
|
||||
let a = noise_layer("ga", PixelFormat::RGBA8, Rect::new(200, 500, 1000, 880), 84, 0.6);
|
||||
let mut c = noise_layer("gc", PixelFormat::RGBA8, Rect::new(0, 600, 1100, 700), 85, 0.0);
|
||||
let a = noise_layer("ga", PixelFormat::RGBA8, pick([200, 500, 1000, 880], [150, 400, 620, 570]), 84, 0.6);
|
||||
let mut c = noise_layer("gc", PixelFormat::RGBA8, pick([0, 600, 1100, 700], [0, 450, 660, 520]), 85, 0.0);
|
||||
c.clipped = true;
|
||||
c.blend = BlendMode::Screen;
|
||||
let mut grp = Layer::group("g", vec![a, c]);
|
||||
@@ -3125,20 +3160,20 @@ fn big_doc() -> Document {
|
||||
fn documents_larger_than_the_texture_limit() {
|
||||
let _gamma = TEXT_GAMMA.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let Some(mut g) = gpu() else { return };
|
||||
let mut d = big_doc();
|
||||
let mut d = small_big_doc();
|
||||
assert!(g.paged.supports(&d).is_ok());
|
||||
// Every pass sees page borders, and effect maps and blurs crossing them.
|
||||
check(&mut g, &d, "big document");
|
||||
let s = photocraft_gpu::render_to_vec_stats(&mut g.paged, &g.device, &g.queue, &d, d.bounds()).unwrap().1;
|
||||
assert!(s.cells >= 20 && s.chunks == s.cells, "{s:?}");
|
||||
// A viewport off the page grid covers only its cells.
|
||||
let view = Rect::new(300, 330, 790, 610);
|
||||
assert!(s.cells >= 9 && s.chunks == s.cells, "{s:?}");
|
||||
// A viewport off the page grid covers only its cells (3 x 2).
|
||||
let view = Rect::new(200, 230, 530, 430);
|
||||
diff_rect(&mut g, &d, view, "viewport").unwrap_or_else(|e| panic!("{e}"));
|
||||
let s = photocraft_gpu::render_to_vec_stats(&mut g.paged, &g.device, &g.queue, &d, view).unwrap().1;
|
||||
assert_eq!(s.cells, 6, "{s:?}");
|
||||
// A dab across a page corner on the effect layer, and an edit elsewhere.
|
||||
d.layers[3].surface_mut().unwrap().fill_rect(Rect::new(500, 490, 530, 530), &[0.1, 0.1, 0.9, 1.0]);
|
||||
d.layers[2].surface_mut().unwrap().fill_rect(Rect::new(250, 250, 270, 270), &[0.0, 0.0, 0.0, 0.0]);
|
||||
d.layers[3].surface_mut().unwrap().fill_rect(Rect::new(240, 240, 270, 270), &[0.1, 0.1, 0.9, 1.0]);
|
||||
d.layers[2].surface_mut().unwrap().fill_rect(Rect::new(500, 250, 520, 270), &[0.0, 0.0, 0.0, 0.0]);
|
||||
check(&mut g, &d, "after dabs");
|
||||
let s = photocraft_gpu::render_to_vec_stats(&mut g.paged, &g.device, &g.queue, &d, d.bounds()).unwrap().1;
|
||||
assert_eq!((s.tiles_uploaded, s.fx_shapes), (0, 0), "nothing changed since the last render: {s:?}");
|
||||
@@ -3148,13 +3183,15 @@ fn documents_larger_than_the_texture_limit() {
|
||||
fn pages_are_evicted_under_the_budget() {
|
||||
let _gamma = TEXT_GAMMA.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let Some(mut g) = gpu() else { return };
|
||||
let mut d = big_doc();
|
||||
let mut d = small_big_doc();
|
||||
check(&mut g, &d, "warm");
|
||||
let all = g.paged.resident_bytes();
|
||||
// A budget of one page: everything but the cell being drawn is evicted as the render goes.
|
||||
let page = u64::from(g.paged.page_size()).pow(2) * 4;
|
||||
g.paged.set_resident_budget(page);
|
||||
for round in 0..3 {
|
||||
// Round 0 evicts from a warm, fully resident state; round 1 brings back pages evicted with
|
||||
// the edits made meanwhile (a third round repeated round 1).
|
||||
for round in 0..2 {
|
||||
let cpu = timed("eviction CPU reference", || photocraft_compose::flatten(&d));
|
||||
let (out, s) =
|
||||
timed("eviction GPU render/readback", || photocraft_gpu::render_to_vec_stats(&mut g.paged, &g.device, &g.queue, &d, d.bounds())).unwrap();
|
||||
|
||||
@@ -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);
|
||||
@@ -134,24 +135,24 @@ fn sliders(h: &Harness<'_, Box<PhotocraftApp>>) -> Vec<Rect> {
|
||||
/// Issue #12: every adjustment kind, on a new document at 8/16/32 bits and in RGB, Grayscale,
|
||||
/// CMYK and Lab, opens its Properties editor and takes an edit through real input without
|
||||
/// panicking; slider kinds commit exactly one history step per gesture and end the preview with it.
|
||||
/// One app per document: Undo takes back each kind's layer and edit before the next kind's layer
|
||||
/// is added, so every kind meets the new document with its two tones.
|
||||
#[test]
|
||||
fn every_adjustment_layer_edits_through_properties() {
|
||||
for (mode, depth) in [("rgb", 8), ("rgb", 16), ("rgb", 32), ("gray", 8), ("cmyk", 8), ("lab", 16)] {
|
||||
// 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);
|
||||
// The document's history before its adjustment layer.
|
||||
let base = history_len(&h) - 1;
|
||||
for (i, kind) in ALL_KINDS.into_iter().enumerate() {
|
||||
if i > 0 {
|
||||
while history_len(&h) > base {
|
||||
let steps = history_len(&h);
|
||||
h.state_mut().run("edit.undo", json!({})).unwrap_or_else(|e| panic!("{kind} {mode}: undo: {e}"));
|
||||
assert!(history_len(&h) < steps, "{kind} {mode}: undo to the new document");
|
||||
}
|
||||
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();
|
||||
h.run_steps(8);
|
||||
// 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");
|
||||
|
||||
@@ -229,40 +229,46 @@ fn clipped_target_preview_composites_on_the_gpu_like_the_command() {
|
||||
let Some((device, queue, mut comp)) = gpu() else { return };
|
||||
let (tol_gpu, tol_cmd) = (2.0 / 255.0, 2.5 / 255.0);
|
||||
let mut worst = 0.0f32;
|
||||
for mode in [ColorMode::Rgb, ColorMode::Grayscale] {
|
||||
for depth in [SampleType::U8, SampleType::U16, SampleType::F32] {
|
||||
for selection in [false, true] {
|
||||
let (doc, target) = clipped_document(mode, depth, selection);
|
||||
for kind in photocraft_ui_egui::adjust_editors::KINDS {
|
||||
let params = sample(kind);
|
||||
let preview = match preview_document(&doc, target, kind, ¶ms) {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
// Only grayscale kinds that make colour keep the CPU proxy preview.
|
||||
assert_eq!(mode, ColorMode::Grayscale, "{kind}: {e}");
|
||||
assert!(GRAY_COLOUR.contains(&kind), "{kind} {mode:?}: unexpected preview error: {e}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
assert!(preview.layer(PREVIEW_LAYER).is_some());
|
||||
assert!(preview.layer(target).unwrap().is_group(), "the clipped target is isolated");
|
||||
let what = format!("{kind} {mode:?} {depth:?} selection {selection}");
|
||||
let b = preview.bounds();
|
||||
let skip = if matches!(kind, "threshold" | "posterize") && depth != SampleType::U8 { (b.width() * b.height()) as usize / 100 } else { 0 };
|
||||
let on_gpu = render_to_vec(&mut comp, &device, &queue, &preview, b).unwrap_or_else(|e| panic!("{what}: {e:?}"));
|
||||
let on_cpu = photocraft_compose::render(&preview, b).into_px();
|
||||
let d = max_diff(&on_gpu, &on_cpu, skip);
|
||||
assert!(d <= tol_gpu, "{what}: GPU vs CPU {:.2}/255", d * 255.0);
|
||||
let mut s = photocraft_engine::Session::new();
|
||||
s.add_document(doc.clone(), None);
|
||||
s.select_layer(target).unwrap();
|
||||
s.execute(&format!("image.adjustments.{kind}"), params.clone()).unwrap();
|
||||
let cmd = photocraft_compose::render(&s.active().unwrap().doc, b).into_px();
|
||||
let d = max_diff(&on_gpu, &cmd, skip);
|
||||
worst = worst.max(d);
|
||||
assert!(d <= tol_cmd, "{what}: GPU preview vs command {:.2}/255", d * 255.0);
|
||||
// Each kind runs once per mode at one (depth, selection) pair, rather than kind x depth x selection: this test's
|
||||
// own case is the isolating group, which `base_document` builds before it knows the kind (`with_settings` only
|
||||
// swaps the preview layer's adjustment), and the GPU planner applies a clipped adjustment through the same
|
||||
// `atop_any` / `adjust` passes whatever the group around it (`crates/gpu/src/plan/planner.rs`). The kind x depth x
|
||||
// selection x mode matrix of those passes is `preview_layer_composites_on_the_gpu_like_the_command`. Cycling the
|
||||
// pairs over the kinds still runs every depth with and without a selection in both modes (in Grayscale among the
|
||||
// kinds that keep gray, too).
|
||||
const PAIRS: [(SampleType, bool); 6] =
|
||||
[(SampleType::U8, false), (SampleType::U16, true), (SampleType::F32, false), (SampleType::U8, true), (SampleType::U16, false), (SampleType::F32, true)];
|
||||
for (mode, offset) in [(ColorMode::Rgb, 0), (ColorMode::Grayscale, 3)] {
|
||||
for (i, kind) in photocraft_ui_egui::adjust_editors::KINDS.into_iter().enumerate() {
|
||||
let (depth, selection) = PAIRS[(i + offset) % PAIRS.len()];
|
||||
let (doc, target) = clipped_document(mode, depth, selection);
|
||||
let params = sample(kind);
|
||||
let preview = match preview_document(&doc, target, kind, ¶ms) {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
// Only grayscale kinds that make colour keep the CPU proxy preview.
|
||||
assert_eq!(mode, ColorMode::Grayscale, "{kind}: {e}");
|
||||
assert!(GRAY_COLOUR.contains(&kind), "{kind} {mode:?}: unexpected preview error: {e}");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
};
|
||||
assert!(preview.layer(PREVIEW_LAYER).is_some());
|
||||
assert!(preview.layer(target).unwrap().is_group(), "the clipped target is isolated");
|
||||
let what = format!("{kind} {mode:?} {depth:?} selection {selection}");
|
||||
let b = preview.bounds();
|
||||
let skip = if matches!(kind, "threshold" | "posterize") && depth != SampleType::U8 { (b.width() * b.height()) as usize / 100 } else { 0 };
|
||||
let on_gpu = render_to_vec(&mut comp, &device, &queue, &preview, b).unwrap_or_else(|e| panic!("{what}: {e:?}"));
|
||||
let on_cpu = photocraft_compose::render(&preview, b).into_px();
|
||||
let d = max_diff(&on_gpu, &on_cpu, skip);
|
||||
assert!(d <= tol_gpu, "{what}: GPU vs CPU {:.2}/255", d * 255.0);
|
||||
let mut s = photocraft_engine::Session::new();
|
||||
s.add_document(doc.clone(), None);
|
||||
s.select_layer(target).unwrap();
|
||||
s.execute(&format!("image.adjustments.{kind}"), params.clone()).unwrap();
|
||||
let cmd = photocraft_compose::render(&s.active().unwrap().doc, b).into_px();
|
||||
let d = max_diff(&on_gpu, &cmd, skip);
|
||||
worst = worst.max(d);
|
||||
assert!(d <= tol_cmd, "{what}: GPU preview vs command {:.2}/255", d * 255.0);
|
||||
}
|
||||
}
|
||||
eprintln!("worst clipped-target GPU preview vs command: {:.3}/255", worst * 255.0);
|
||||
|
||||
@@ -108,12 +108,13 @@ fn size_changing_rotation_preview_is_visible_and_preserves_the_panned_center() {
|
||||
let _gpu = photocraft_testkit::gpu_lock();
|
||||
let Some(mut h) = harness() else { return };
|
||||
h.run_steps(4);
|
||||
for (width, height, zoom, center, degrees, factor) in [
|
||||
(400, 240, 1.0, [160.0, 90.0], 45.0, 1),
|
||||
(400, 240, 1.0, [160.0, 90.0], -45.0, 1),
|
||||
(400, 240, 1.0, [160.0, 90.0], 90.0, 1),
|
||||
(3000, 1800, 0.12, [1350.0, 825.0], 45.0, 2),
|
||||
] {
|
||||
// The canvas places a size-changing preview by its size alone (`canvas/gpu_picture.rs`: `growth` and
|
||||
// `preview_bounds` from `preview_size`): 45° grows both sides, 90° grows one and shrinks the other, and the large
|
||||
// document runs the reduced proxy. -45° gives 45°'s size, so it repeated the same placement; the direction of
|
||||
// the rotation itself is the engine's (its `image.rotation.arbitrary` tests with `"direction": "ccw"`).
|
||||
for (width, height, zoom, center, degrees, factor) in
|
||||
[(400, 240, 1.0, [160.0, 90.0], 45.0, 1), (400, 240, 1.0, [160.0, 90.0], 90.0, 1), (3000, 1800, 0.12, [1350.0, 825.0], 45.0, 2)]
|
||||
{
|
||||
setup(&mut h, width, height, zoom, center);
|
||||
assert_eq!(photocraft_ui_egui::proxy::factor(&h.state().session.active().unwrap().doc), factor);
|
||||
let id = open(&mut h);
|
||||
|
||||
@@ -289,15 +289,31 @@ fn pixel_grid_does_not_flip_colour_across_mid_tones() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The depths [`pixel_grid_is_solid_and_visible_at_scale`] runs at. Both canvases draw the grid with the same
|
||||
/// `PixelGrid` over a CPU composite (`PhotoComposite`: compose's f32 render, `canvas/raster_source.rs` `read`; see
|
||||
/// `grid_prep` and "The grid is drawn over the picture" in `canvas/document_display.rs`), and the fills 0 and 1 are
|
||||
/// exact at every depth, so the grid reads the same pixels at 8, 16 and 32 bits. Depth reaches only the picture under
|
||||
/// it, which the `inside` assertion reads: on the GPU canvas its texture (`Rgba8Unorm` for 8-bit, `Rgba16Float` for
|
||||
/// 16/32-bit, see `canvas_16f.rs`). So every canvas and scale runs 8-bit, and the GPU canvas adds 16-bit at 1x and
|
||||
/// 32-bit at 2x.
|
||||
fn grid_depths(gpu: bool, ppp: f32) -> Vec<photocraft_color::SampleType> {
|
||||
use photocraft_color::SampleType;
|
||||
match (gpu, ppp > 1.0) {
|
||||
(true, false) => vec![SampleType::U8, SampleType::U16],
|
||||
(true, true) => vec![SampleType::U8, SampleType::F32],
|
||||
(false, _) => vec![SampleType::U8],
|
||||
}
|
||||
}
|
||||
|
||||
fn pixel_grid_is_solid_and_visible_at_scale(gpu: bool, ppp: f32) {
|
||||
let _gpu = photocraft_testkit::gpu_lock();
|
||||
use photocraft_color::{ColorMode, PixelFormat, SampleType};
|
||||
use photocraft_color::{ColorMode, PixelFormat};
|
||||
use photocraft_doc::{Document, Layer, LayerContent, Size};
|
||||
use photocraft_geom::Rect;
|
||||
use photocraft_raster::Surface;
|
||||
|
||||
let Some(mut h) = harness_with_scale(gpu, ppp) else { return };
|
||||
for depth in [SampleType::U8, SampleType::U16, SampleType::F32] {
|
||||
for depth in grid_depths(gpu, ppp) {
|
||||
for v in [0.0, 1.0] {
|
||||
let mut doc = Document::new("grid contrast", Size::new(32, 16), ColorMode::Rgb, depth);
|
||||
let mut surface = Surface::new(PixelFormat::new(ColorMode::Rgb, depth, true));
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
//!
|
||||
//! They drive the real app offscreen on wgpu with real egui pointer events (press, then a series
|
||||
//! of moves past the click distance), render the frame mid-drag and look at the pixels along the
|
||||
//! preview's edges on white and on black documents. They also check the preview follows every
|
||||
//! preview's edges on a mid-grey document, for both colours of the ants. They also check the preview follows every
|
||||
//! move (each move's frame shows the new outline) and that the animated ants keep frames coming
|
||||
//! while the pointer is held still. Skips when no GPU adapter exists (like `live_stroke_canvas.rs`).
|
||||
|
||||
@@ -169,11 +169,17 @@ fn coverage_along(img: &Image, ppp: f32, pts: &[Pos2], test: impl Fn(u8) -> bool
|
||||
hits as f32 / samples.max(1) as f32
|
||||
}
|
||||
|
||||
/// Ink that contrasts with `background`: dark on white, light on black. The 1 px ants are half
|
||||
/// antialiasing where the curve crosses pixel columns, so a quarter of the luma range suffices.
|
||||
fn ink(background: &str) -> impl Fn(u8) -> bool {
|
||||
let white = background == "white";
|
||||
move |l| if white { l < 192 } else { l > 63 }
|
||||
/// The document the marquee tests drag over: the grey halfway between the ants' two colours (luma 102 and 255 in the
|
||||
/// default theme), so both contrast with it.
|
||||
const GREY: &str = "#b3b3b3";
|
||||
|
||||
/// An ink's name and whether a luma shows it.
|
||||
type Ink = (&'static str, fn(u8) -> bool);
|
||||
|
||||
/// The two inks of the ants over [`GREY`] (luma 179): darker and lighter. The 1 px ants are half antialiasing where
|
||||
/// the curve crosses pixel columns (luma 140 and 217 there), so the thresholds sit just past the grey either way.
|
||||
fn inks() -> [Ink; 2] {
|
||||
[("dark", |l| l < 150), ("light", |l| l > 208)]
|
||||
}
|
||||
|
||||
/// The four edges of the document rectangle `[x0, y0]`–`[x1, y1]` on screen.
|
||||
@@ -186,22 +192,34 @@ fn edges(h: &Harness, a: [f32; 2], b: [f32; 2]) -> [(Pos2, Pos2); 4] {
|
||||
#[test]
|
||||
fn marquee_previews_show_while_dragging_on_white_and_black_at_1x_and_2x() {
|
||||
let _gpu = photocraft_testkit::gpu_lock();
|
||||
for ppp in [1.0, 2.0] {
|
||||
let Some(mut h) = harness(ppp) else { return };
|
||||
// One mid-grey document instead of a white and a black one: the ants are a band of the marquee colour with dashes
|
||||
// of the halo colour, fixed colours that never depend on the pixels under them (the framework's `marching_ants`,
|
||||
// which the marquee tool paints through `ToolContext::marching_ants`). White on white (#253) hid the light ants
|
||||
// and black would hide the dark ones; over grey the test sees both inks at once, so an outline missing either
|
||||
// colour fails here as it failed on one of the two documents. (The name is the one CI's slow-test order lists.)
|
||||
// One harness for both scales: the app derives its scale from the window's native one every frame
|
||||
// (`prefs_ui/appearance.rs` `interface_zoom`), so the 2x pass sets that, as a move to a HiDPI display does.
|
||||
let Some(mut h) = harness(1.0) else { return };
|
||||
h.run_steps(4);
|
||||
for ppp in [1.0f32, 2.0] {
|
||||
if let Some(root) = h.input_mut().viewports.get_mut(&egui::ViewportId::ROOT) {
|
||||
root.native_pixels_per_point = Some(ppp);
|
||||
}
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.ctx.pixels_per_point(), ppp, "the harness runs at {ppp}x");
|
||||
for tool in ["rectMarquee", "ellipseMarquee"] {
|
||||
for bg in ["white", "black"] {
|
||||
setup(&mut h, bg, tool);
|
||||
let (a, b) = ([100.0, 80.0], [300.0, 220.0]);
|
||||
let before = render(&mut h);
|
||||
drag_to(&mut h, a, b);
|
||||
let img = render(&mut h);
|
||||
setup(&mut h, GREY, tool);
|
||||
let (a, b) = ([100.0, 80.0], [300.0, 220.0]);
|
||||
let before = render(&mut h);
|
||||
drag_to(&mut h, a, b);
|
||||
let img = render(&mut h);
|
||||
for (ink, test) in inks() {
|
||||
if tool == "rectMarquee" {
|
||||
for (i, (p, q)) in edges(&h, a, b).into_iter().enumerate() {
|
||||
let was = coverage(&before, ppp, p, q, ink(bg));
|
||||
let now = coverage(&img, ppp, p, q, ink(bg));
|
||||
// Ants: half the dashes contrast with the pixels under them.
|
||||
assert!(was < 0.05 && now > 0.3, "{tool} on {bg} @{ppp}x, edge {i}: {was:.2} → {now:.2} contrasting");
|
||||
let was = coverage(&before, ppp, p, q, test);
|
||||
let now = coverage(&img, ppp, p, q, test);
|
||||
// Ants: half the dashes are each ink.
|
||||
assert!(was < 0.05 && now > 0.3, "{tool} @{ppp}x, edge {i}: {was:.2} → {now:.2} {ink}");
|
||||
}
|
||||
} else {
|
||||
// The ellipse touches its box at the edge midpoints. Walk the curve around
|
||||
@@ -220,21 +238,24 @@ fn marquee_previews_show_while_dragging_on_white_and_black_at_1x_and_2x() {
|
||||
screen(&h, (cx as f64 + rx as f64 * t.cos()) as f32, (cy as f64 + ry as f64 * t.sin()) as f32)
|
||||
})
|
||||
.collect();
|
||||
let now = coverage_along(&img, ppp, &pts, ink(bg));
|
||||
assert!(now > 0.3, "{tool} on {bg} @{ppp}x at ({mx}, {my}): {now:.2} contrasting");
|
||||
let was = coverage_along(&before, ppp, &pts, test);
|
||||
let now = coverage_along(&img, ppp, &pts, test);
|
||||
assert!(was < 0.05 && now > 0.3, "{tool} @{ppp}x at ({mx}, {my}): {was:.2} → {now:.2} {ink}");
|
||||
}
|
||||
}
|
||||
// Each move's frame shows the outline where the pointer is now (no stale frame).
|
||||
pointer_move(&mut h, 340.0, 250.0);
|
||||
let img = render(&mut h);
|
||||
if tool == "rectMarquee" {
|
||||
let [top, right, ..] = edges(&h, a, [340.0, 250.0]);
|
||||
assert!(coverage(&img, ppp, top.0, top.1, ink(bg)) > 0.3, "{tool} {bg} @{ppp}x: top edge follows the pointer");
|
||||
assert!(coverage(&img, ppp, right.0, right.1, ink(bg)) > 0.3, "{tool} {bg} @{ppp}x: right edge follows the pointer");
|
||||
}
|
||||
button(&mut h, 340.0, 250.0, false);
|
||||
h.run_steps(2);
|
||||
}
|
||||
// Each move's frame shows the outline where the pointer is now (no stale frame).
|
||||
pointer_move(&mut h, 340.0, 250.0);
|
||||
let img = render(&mut h);
|
||||
if tool == "rectMarquee" {
|
||||
let [top, right, ..] = edges(&h, a, [340.0, 250.0]);
|
||||
for (ink, test) in inks() {
|
||||
assert!(coverage(&img, ppp, top.0, top.1, test) > 0.3, "{tool} @{ppp}x: top edge follows the pointer ({ink})");
|
||||
assert!(coverage(&img, ppp, right.0, right.1, test) > 0.3, "{tool} @{ppp}x: right edge follows the pointer ({ink})");
|
||||
}
|
||||
}
|
||||
button(&mut h, 340.0, 250.0, false);
|
||||
h.run_steps(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,15 @@ type Pixels = Vec<[u8; 4]>;
|
||||
fn raw_pointer_brush_and_mixer_pixels_appear_in_the_input_frame() {
|
||||
use photocraft_ui_egui::state::Tool;
|
||||
let _gpu = photocraft_testkit::gpu_lock();
|
||||
// One harness for every case: each case closes what the last one left open and sets its own tool, view flip,
|
||||
// brush and colours, so a fresh harness per case only repeated the wgpu setup.
|
||||
let Some(mut h) = harness() else { return };
|
||||
for flip in [false, true] {
|
||||
for tool in [Tool::Brush, Tool::MixerBrush] {
|
||||
let Some(mut h) = harness() else { return };
|
||||
let app = h.state_mut();
|
||||
while app.session.active().is_some() {
|
||||
app.run("file.close", json!({"discard": true})).unwrap();
|
||||
}
|
||||
app.run("file.new", json!({"width":300,"height":200,"background":"white"})).unwrap();
|
||||
app.run("edit.fill", json!({"color":"#2040df"})).unwrap();
|
||||
app.run("tools.setColors", json!({"foreground":"#ef2000"})).unwrap();
|
||||
@@ -202,11 +207,14 @@ fn the_canvas_shows_the_committed_stroke_part(part: usize) {
|
||||
let _gpu = photocraft_testkit::gpu_lock();
|
||||
let Some(mut h) = harness() else { return };
|
||||
h.run_steps(4);
|
||||
// Every zoom once, with every smoothing amount among them, rather than zoom x smoothing: the canvas branches on
|
||||
// the zoom (reduced, 1:1 and magnified pictures) and only on whether smoothing is on (a held pointer repeats its
|
||||
// point while smoothing catches up, `canvas/strokes.rs`); that the live stroke equals the commit at
|
||||
// every zoom and smoothing amount is the engine's `live_stroke_equals_the_commit_at_every_zoom_with_smoothing`
|
||||
// (`brush_cmds/tests.rs`). The zoom 4, smoothing 0.1 case is the base the cases after it change one thing of.
|
||||
let mut cases = Vec::new();
|
||||
for zoom in [0.5, 1.0, 4.0, 12.0] {
|
||||
for smoothing in [0.0, 0.1, 0.5] {
|
||||
cases.push(Case { zoom, smoothing, hardness: 0.0, depth: 8, pressure: false, flip: false });
|
||||
}
|
||||
for (zoom, smoothing) in [(0.5, 0.5), (1.0, 0.0), (4.0, 0.1), (12.0, 0.0)] {
|
||||
cases.push(Case { zoom, smoothing, hardness: 0.0, depth: 8, pressure: false, flip: false });
|
||||
}
|
||||
cases.push(Case { zoom: 4.0, smoothing: 0.1, hardness: 1.0, depth: 8, pressure: false, flip: false });
|
||||
cases.push(Case { zoom: 4.0, smoothing: 0.1, hardness: 0.0, depth: 16, pressure: false, flip: false });
|
||||
@@ -214,7 +222,8 @@ fn the_canvas_shows_the_committed_stroke_part(part: usize) {
|
||||
cases.push(Case { zoom: 4.0, smoothing: 0.1, hardness: 0.0, depth: 8, pressure: false, flip: true });
|
||||
cases.push(Case { zoom: 12.0, smoothing: 0.5, hardness: 0.0, depth: 16, pressure: true, flip: true });
|
||||
let mut gpu_seen = false;
|
||||
for c in cases.into_iter().skip(part).step_by(4) {
|
||||
// One step per `_part_N` test, so every case runs in exactly one of them.
|
||||
for c in cases.into_iter().skip(part).step_by(3) {
|
||||
let (before, drawing, done, gpu) = frames(&mut h, c);
|
||||
gpu_seen |= gpu;
|
||||
// The stroke is on screen while drawing (not a blank canvas compared with a blank one)…
|
||||
@@ -248,60 +257,67 @@ fn the_canvas_shows_the_committed_stroke_part_2() {
|
||||
fn live_tool_camera_navigation_is_visible_in_the_input_frame() {
|
||||
use photocraft_ui_egui::state::Tool;
|
||||
let _gpu = photocraft_testkit::gpu_lock();
|
||||
// Brush only: no stroke is drawn, and the canvas has no branch on the live tool before a press. Since the canvas
|
||||
// moved onto the framework it always runs the tools, then shows the picture with the camera of this pass
|
||||
// (`canvas/document_display.rs` `show`: "The tools run after the controls … and before the picture"); the Mixer
|
||||
// Brush's own paths (`canvas/paint_tool.rs`, `canvas/strokes.rs`) start at a press, which
|
||||
// `raw_pointer_brush_and_mixer_pixels_appear_in_the_input_frame` covers. The flip (CPU or GPU picture) and the
|
||||
// input (pinch zoom or wheel pan) do reach different code, so they stay, on one harness.
|
||||
let tool = Tool::Brush;
|
||||
let Some(mut h) = harness() else { return };
|
||||
for flip in [false, true] {
|
||||
for tool in [Tool::Brush, Tool::MixerBrush] {
|
||||
for zoom in [false, true] {
|
||||
let Some(mut h) = harness() else { return };
|
||||
let app = h.state_mut();
|
||||
app.run("file.new", json!({"width":300,"height":200,"background":"white"})).unwrap();
|
||||
app.run("paint.stroke", json!({"points":[[40,40],[240,160]],"size":30,"hardness":1.0,"color":"#2050df"})).unwrap();
|
||||
app.run("prefs.set", json!({"values":{"tools.overscroll":true,"general.animatedZoom":false,"general.zoomWithScrollWheel":false}})).unwrap();
|
||||
app.ui.tool = tool;
|
||||
app.ui.view.flip_horizontal = flip;
|
||||
app.sync_views();
|
||||
h.run_steps(4);
|
||||
control(&mut h, "ui.set", json!({"zoom":1.0,"center":[150,100]}));
|
||||
let at = h.state().last_canvas_rect.center() + egui::vec2(30.0, 10.0);
|
||||
h.hover_at(at);
|
||||
h.run_steps(2);
|
||||
let before = h.state().ui.views[0].clone();
|
||||
h.input_mut().events.push(if zoom {
|
||||
egui::Event::Zoom(1.25)
|
||||
} else {
|
||||
egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Point,
|
||||
delta: egui::vec2(30.0, 20.0),
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
phase: egui::TouchPhase::Move,
|
||||
source: egui::MouseWheelSource::Unknown,
|
||||
}
|
||||
});
|
||||
h.step();
|
||||
let moved = h.state().ui.views[0].clone();
|
||||
assert!(if zoom { moved.zoom != before.zoom } else { moved.center != before.center }, "navigation was applied");
|
||||
let immediate = h.render().unwrap();
|
||||
let rect = h.state().last_canvas_rect.shrink(8.0);
|
||||
h.step();
|
||||
let settled = h.render().unwrap();
|
||||
if tool == Tool::MixerBrush
|
||||
&& flip
|
||||
&& zoom
|
||||
&& let Ok(path) = std::env::var("PHOTOCRAFT_NAV_SNAPSHOT")
|
||||
{
|
||||
settled.save(path).unwrap();
|
||||
}
|
||||
assert_eq!(h.state().ui.views[0].zoom, moved.zoom);
|
||||
assert_eq!(h.state().ui.views[0].center, moved.center);
|
||||
let mut diff = 0;
|
||||
for y in rect.top() as u32..rect.bottom() as u32 {
|
||||
for x in rect.left() as u32..rect.right() as u32 {
|
||||
for (a, b) in immediate.get_pixel(x, y).0.into_iter().zip(settled.get_pixel(x, y).0) {
|
||||
diff = diff.max(a.abs_diff(b));
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(diff <= 1, "{tool:?} flip={flip} zoom={zoom}: canvas changes {diff}/255 one frame after navigation");
|
||||
for zoom in [false, true] {
|
||||
let app = h.state_mut();
|
||||
while app.session.active().is_some() {
|
||||
app.run("file.close", json!({"discard": true})).unwrap();
|
||||
}
|
||||
app.run("file.new", json!({"width":300,"height":200,"background":"white"})).unwrap();
|
||||
app.run("paint.stroke", json!({"points":[[40,40],[240,160]],"size":30,"hardness":1.0,"color":"#2050df"})).unwrap();
|
||||
app.run("prefs.set", json!({"values":{"tools.overscroll":true,"general.animatedZoom":false,"general.zoomWithScrollWheel":false}})).unwrap();
|
||||
app.ui.tool = tool;
|
||||
app.ui.view.flip_horizontal = flip;
|
||||
app.sync_views();
|
||||
h.run_steps(4);
|
||||
control(&mut h, "ui.set", json!({"zoom":1.0,"center":[150,100]}));
|
||||
let at = h.state().last_canvas_rect.center() + egui::vec2(30.0, 10.0);
|
||||
h.hover_at(at);
|
||||
h.run_steps(2);
|
||||
let before = h.state().ui.views[0].clone();
|
||||
h.input_mut().events.push(if zoom {
|
||||
egui::Event::Zoom(1.25)
|
||||
} else {
|
||||
egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Point,
|
||||
delta: egui::vec2(30.0, 20.0),
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
phase: egui::TouchPhase::Move,
|
||||
source: egui::MouseWheelSource::Unknown,
|
||||
}
|
||||
});
|
||||
h.step();
|
||||
let moved = h.state().ui.views[0].clone();
|
||||
assert!(if zoom { moved.zoom != before.zoom } else { moved.center != before.center }, "navigation was applied");
|
||||
let immediate = h.render().unwrap();
|
||||
let rect = h.state().last_canvas_rect.shrink(8.0);
|
||||
h.step();
|
||||
let settled = h.render().unwrap();
|
||||
if flip
|
||||
&& zoom
|
||||
&& let Ok(path) = std::env::var("PHOTOCRAFT_NAV_SNAPSHOT")
|
||||
{
|
||||
settled.save(path).unwrap();
|
||||
}
|
||||
assert_eq!(h.state().ui.views[0].zoom, moved.zoom);
|
||||
assert_eq!(h.state().ui.views[0].center, moved.center);
|
||||
let mut diff = 0;
|
||||
for y in rect.top() as u32..rect.bottom() as u32 {
|
||||
for x in rect.left() as u32..rect.right() as u32 {
|
||||
for (a, b) in immediate.get_pixel(x, y).0.into_iter().zip(settled.get_pixel(x, y).0) {
|
||||
diff = diff.max(a.abs_diff(b));
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(diff <= 1, "{tool:?} flip={flip} zoom={zoom}: canvas changes {diff}/255 one frame after navigation");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user