From a7b65190a5d39efc5695fcfbb266587889368533 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 23 Nov 2026 19:22:09 +0000 Subject: [PATCH 1/2] test(ui): shrink the full-resolution preview fixtures (#15370) --- crates/ui-egui/src/app.rs | 2 + crates/ui-egui/src/canvas/filter_preview.rs | 8 +- crates/ui-egui/src/canvas/textures.rs | 2 +- crates/ui-egui/src/dialogs/adjust_preview.rs | 11 +-- .../it => src}/gpu_tests/full_res_preview.rs | 84 +++++++++++-------- crates/ui-egui/src/lib.rs | 7 ++ crates/ui-egui/src/proxy.rs | 26 +++++- crates/ui-egui/tests/it/main.rs | 1 - 8 files changed, 91 insertions(+), 50 deletions(-) rename crates/ui-egui/{tests/it => src}/gpu_tests/full_res_preview.rs (71%) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index bcf7d61c5c..7f3d7cc9a2 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -92,6 +92,8 @@ impl PhotocraftApp { #[cfg(not(target_arch = "wasm32"))] control: None, live_adjust: None, + #[cfg(test)] + preview_test_area_multiplier: 1, frame: 0, notices_live: notices::Live::default(), low_memory: crate::memory_warning::Watch::default(), diff --git a/crates/ui-egui/src/canvas/filter_preview.rs b/crates/ui-egui/src/canvas/filter_preview.rs index 9ac9589238..77b22fe756 100644 --- a/crates/ui-egui/src/canvas/filter_preview.rs +++ b/crates/ui-egui/src/canvas/filter_preview.rs @@ -30,8 +30,8 @@ mod tests; /// the very stall this avoids. pub(crate) fn filter_preview_factor(app: &PhotocraftApp, doc: &Document, cmd: &str, params: &serde_json::Value) -> u32 { // A smart filter edit re-renders the whole stack: every stage constrains the factor. - let k = crate::filter_dialog::smart_preview_factor(doc, cmd, params, crate::proxy::preview_factor(doc, crate::proxy::reduced_previews(app))); - if cfg!(target_arch = "wasm32") { k } else { crate::proxy::view_factor(k, app.current_zoom(), doc.size.area()) } + let k = crate::filter_dialog::smart_preview_factor(doc, cmd, params, crate::proxy::app_factor(app, doc)); + if cfg!(target_arch = "wasm32") { k } else { crate::proxy::view_factor(k, app.current_zoom(), crate::proxy::planning_area(app, doc)) } } /// The open adjustment dialog (a plain one or a Smart Filter edit) while its preview shows: its dialog id and what OK @@ -345,11 +345,11 @@ pub(super) fn ensure_proxy_preview(app: &mut PhotocraftApp, idx: usize, zoom: f3 (st.doc.id, st.revision, st.doc.clone()) }; // Low-resolution previews off: k is 1 and the canvas shows `display_doc` (full size). - let mut k = crate::proxy::preview_factor(&doc, crate::proxy::reduced_previews(app)); + let mut k = crate::proxy::app_factor(app, &doc); // Zoomed in, a proxy coarser than the screen showed the drag in k-pixel blocks (#5764): when // the wgpu compositor draws the full-size document, use a proxy only as coarse as the screen // (none at 50 % and closer). Otherwise the full size would be a CPU composite per change. - let fine = crate::proxy::view_factor(k, zoom, doc.size.area()); + let fine = crate::proxy::view_factor(k, zoom, crate::proxy::planning_area(app, &doc)); if fine < k && app.gpu.as_ref().is_some_and(|g| g.supports(&doc)) { k = fine; } diff --git a/crates/ui-egui/src/canvas/textures.rs b/crates/ui-egui/src/canvas/textures.rs index 22a92e76be..dad4f9370a 100644 --- a/crates/ui-egui/src/canvas/textures.rs +++ b/crates/ui-egui/src/canvas/textures.rs @@ -97,7 +97,7 @@ pub(crate) fn canvas_picture( if proxy == ProxyPreview::Document && crate::adjust_preview::shown_key(app) == Some(preview_key) && let Some(st) = app.session.documents().get(idx) - && crate::proxy::preview_factor(&st.doc, crate::proxy::reduced_previews(app)) > 1 + && crate::proxy::app_factor(app, &st.doc) > 1 { (doc, preview_key) = (st.doc.clone(), 0); } diff --git a/crates/ui-egui/src/dialogs/adjust_preview.rs b/crates/ui-egui/src/dialogs/adjust_preview.rs index 1011f82cad..dd3269909c 100644 --- a/crates/ui-egui/src/dialogs/adjust_preview.rs +++ b/crates/ui-egui/src/dialogs/adjust_preview.rs @@ -254,7 +254,7 @@ pub(crate) fn targets_channel(app: &PhotocraftApp, idx: usize, kind: &str, param fn cheap(app: &PhotocraftApp, doc: &Document) -> bool { match &app.gpu { Some(g) => g.supports(doc), - None => crate::proxy::preview_factor(doc, crate::proxy::reduced_previews(app)) <= 1, + None => crate::proxy::app_factor(app, doc) <= 1, } } @@ -426,15 +426,16 @@ pub fn gpu_proxy(app: &mut PhotocraftApp, idx: usize, zoom: f32) -> Option>; -// Just above the 5 MP proxy threshold; keep the same factor-two reduction. -const W: i32 = 2502; -const H: i32 = 2000; +// Leave room for a visible patch of columns beside the dialogs at 50 % zoom. +const W: i32 = 800; +const H: i32 = 500; +const PREVIEW_AREA_MULTIPLIER: u64 = 13; fn harness() -> Option { let built = std::panic::catch_unwind(|| { egui_kittest::Harness::builder().with_size(egui::vec2(1100.0, 760.0)).with_pixels_per_point(1.0).with_max_steps(64).wgpu().build_eframe(|cc| { PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); let mut app = PhotocraftApp::with_context(cc.egui_ctx.clone(), photocraft_engine::Session::new(), Default::default()); + app.preview_test_area_multiplier = PREVIEW_AREA_MULTIPLIER; if let Some(rs) = cc.wgpu_render_state.as_ref() { app.set_wgpu(rs.clone()); } @@ -46,19 +49,18 @@ fn control(h: &mut Harness, method: &str, params: Value) { h.run_steps(3); } -fn columns_document() -> Document { - let mut doc = Document::with_background("columns", Size::new(W as u32, H as u32), ColorMode::Rgb, SampleType::U8, Color::WHITE); - assert_eq!(photocraft_ui_egui::proxy::factor(&doc), 2, "the fixture must exercise a reduced preview"); +fn columns_document(width: i32, height: i32) -> Document { + let mut doc = Document::with_background("columns", Size::new(width as u32, height as u32), ColorMode::Rgb, SampleType::U8, Color::WHITE); let s = doc.layers[0].surface_mut().expect("background pixels"); - let row: Vec = (0..W) + let row: Vec = (0..width) .flat_map(|x| { let v = if x % 2 == 0 { 0.0 } else { 1.0 }; [v, v, v, 1.0] }) .collect(); - for y in (0..H).step_by(64) { - let end = (y + 64).min(H); - s.write_region(Rect::new(0, y, W, end), &row.repeat((end - y) as usize)); + for y in (0..height).step_by(64) { + let end = (y + 64).min(height); + s.write_region(Rect::new(0, y, width, end), &row.repeat((end - y) as usize)); } doc } @@ -66,7 +68,10 @@ fn columns_document() -> Document { fn setup(h: &mut Harness, zoom: f32) { { let app = h.state_mut(); - app.session.add_document(columns_document(), None); + let doc = columns_document(W, H); + assert_eq!(crate::proxy::factor(&doc), 1, "the fixture is below the production threshold"); + assert_eq!(crate::proxy::app_factor(app, &doc), 2, "the test must exercise a twofold reduction"); + app.session.add_document(doc, None); app.sync_views(); app.ui.extras.rulers = false; } @@ -89,17 +94,18 @@ fn low_res(h: &mut Harness, on: bool) { h.run_steps(4); } -/// Luma along a 300 px row near the canvas's top-left corner (clear of centred dialogs). +/// Luma along a row inside the visible document, to the left of centred dialogs. fn row(h: &mut Harness) -> Vec { h.run_steps(4); - // The canvas as its last pass showed it: the rectangle the rendered pixels are sampled in. - let canvas = photocraft_ui_egui::canvas::active_view(h.state()).expect("the canvas has been shown").rect; - // egui_kittest waits 10 s for the GPU. Windows CI renders on WARP, a software rasterizer, - // where the first full-resolution composite of this 5 MP document can take longer; the - // submitted work still finishes, so wait for it again instead of failing. + let view = crate::canvas::active_view(h.state()).expect("the canvas has been shown"); + let image = egui::Rect::from_two_pos(view.to_screen(Point::ORIGIN), view.to_screen(Point::new(f64::from(W), f64::from(H)))); + let visible = view.rect.intersect(image); + // Windows CI uses a software rasterizer. A render timeout need not drop the submitted work. let img = (0..3).find_map(|_| h.render().ok()).expect("render"); - let (x0, y) = (canvas.min.x as u32 + 20, canvas.min.y as u32 + 40); - (x0..x0 + 300) + let (x0, y) = (visible.min.x.ceil() as u32 + 12, visible.min.y.ceil() as u32 + 12); + let x1 = x0 + 48; + assert!(visible.contains(egui::pos2(x1 as f32, y as f32)), "sample row is inside the visible image"); + (x0..x1) .map(|x| { let p = img.get_pixel(x, y).0; (i32::from(p[0]) * 3 + i32::from(p[1]) * 6 + i32::from(p[2])) / 10 @@ -142,7 +148,7 @@ fn adjustment_layer_drag_previews_at_full_resolution_when_low_res_is_off() { control(&mut h, "ui.set", json!({"zoom": 0.5, "center": [W / 2, H / 2]})); h.state_mut().live_adjust = None; let committed = mean(&row(&mut h)); - assert!(committed > 60.0, "zoomed out the inverted columns average to grey ({committed})"); + assert!((60.0..220.0).contains(&committed), "zoomed out the inverted columns average to grey ({committed})"); h.state_mut().live_adjust = Some((layer, json!({}))); let reduced = mean(&row(&mut h)); assert!(reduced > 225.0, "default at 50 %: the reduced copy keeps only the (inverted) black columns ({reduced})"); @@ -164,10 +170,10 @@ fn filter_dialog_previews_at_full_resolution_when_low_res_is_off() { return; } let committed = mean(&row(&mut h)); - assert!(committed > 60.0, "zoomed out the columns average to grey ({committed})"); + assert!((60.0..220.0).contains(&committed), "zoomed out the columns average to grey ({committed})"); control(&mut h, "ui.set", json!({"zoom": 1.0, "center": [W / 2, H / 2]})); // Offset 0, 0 leaves the pixels as they are: any change is the preview's resolution. - let _dialog = photocraft_ui_egui::filter_dialog::open(h.state_mut(), "filter.other.offset").expect("Offset dialog"); + let _dialog = crate::filter_dialog::open(h.state_mut(), "filter.other.offset").expect("Offset dialog"); let at_100 = row(&mut h); assert!(columns(&at_100) > 0.9, "default at 100 %: the preview is never coarser than the screen ({})", columns(&at_100)); control(&mut h, "ui.set", json!({"zoom": 0.5, "center": [W / 2, H / 2]})); @@ -187,14 +193,15 @@ fn adjustment_dialog_zoomed_out_skips_the_reduced_copy_when_low_res_is_off() { return; } let committed = mean(&row(&mut h)); - assert!(committed > 60.0, "zoomed out the columns average to grey ({committed})"); - let _dialog = photocraft_ui_egui::adjust_dialog::open(h.state_mut(), "image.adjustments.levels").expect("Levels dialog"); + assert!((60.0..220.0).contains(&committed), "zoomed out the columns average to grey ({committed})"); + let _dialog = crate::adjust_dialog::open(h.state_mut(), "image.adjustments.levels").expect("Levels dialog"); h.run_steps(4); - assert!(photocraft_ui_egui::adjust_preview::gpu_proxy(h.state_mut(), 0, 0.5).is_some(), "default: zoomed out on the reduced copy"); + let proxy = crate::adjust_preview::gpu_proxy(h.state_mut(), 0, 0.5).expect("default: zoomed out on the reduced copy"); + assert_eq!(proxy.k, 2); let reduced = mean(&row(&mut h)); assert!(reduced < 30.0, "the reduced copy keeps only the black columns ({reduced})"); low_res(&mut h, false); - assert!(photocraft_ui_egui::adjust_preview::gpu_proxy(h.state_mut(), 0, 0.5).is_none(), "off: no reduced copy"); + assert!(crate::adjust_preview::gpu_proxy(h.state_mut(), 0, 0.5).is_none(), "off: no reduced copy"); let full = mean(&row(&mut h)); assert!((full - committed).abs() < 8.0, "off: the preview matches the committed view ({full} vs {committed})"); } @@ -211,8 +218,11 @@ fn compositor_chunks_keep_their_columns() { return; }; eprintln!("canvas encode adapter {:?}", rs.adapter.get_info()); - let gpu = photocraft_ui_egui::gpu_canvas::GpuCanvas::new(&rs); - let doc = columns_document(); + let gpu = crate::gpu_canvas::GpuCanvas::new(&rs); + // Keep three chunks across and two down, with a partial chunk on both axes. + let width = 2 * photocraft_gpu::CHUNK + 24; + let height = photocraft_gpu::CHUNK + 24; + let doc = columns_document(width as i32, height as i32); let refresh = gpu.refresh(doc.id.0, &doc, None, None); assert!(gpu.fault().is_none(), "GPU fault after canvas refresh: {:?}", gpu.fault()); if refresh.kind == "full" { @@ -222,11 +232,11 @@ fn compositor_chunks_keep_their_columns() { assert_eq!(refresh.kind, "gpu-full", "{:?}", refresh.fallback); let (format, size, texels) = gpu.read_texels(doc.id.0).expect("read back the encoded canvas"); assert_eq!(format, eframe::wgpu::TextureFormat::Rgba8Unorm); - assert_eq!(size, [W as u32, H as u32]); - assert_eq!(texels.len(), (W * H) as usize); + assert_eq!(size, [width, height]); + assert_eq!(texels.len(), (width * height) as usize); for (i, pixel) in texels.iter().enumerate() { - let x = i % W as usize; + let x = i % width as usize; let v = (x % 2) as f32; - assert_eq!(*pixel, [v, v, v, 1.0], "canvas pixel ({x}, {})", i / W as usize); + assert_eq!(*pixel, [v, v, v, 1.0], "canvas pixel ({x}, {})", i / width as usize); } } diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 7be1811eba..09e5fa6c9c 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -37,6 +37,10 @@ pub mod file_open; pub mod frame_stages; pub mod gpu_memo; pub mod gpu_status; +#[cfg(all(test, not(target_arch = "wasm32")))] +mod gpu_tests { + mod full_res_preview; +} mod history_keys; pub mod home_recent_ui; pub mod i18n; @@ -407,6 +411,9 @@ pub struct PhotocraftApp { control: Option, /// Live (uncommitted) adjustment edit shown on canvas while a slider is dragged. pub live_adjust: Option<(photocraft_doc::LayerId, Value)>, + /// Lets GPU tests use small fixtures while exercising large-document preview decisions. + #[cfg(test)] + preview_test_area_multiplier: u64, /// Frames rendered (for tests and the status bar). pub frame: u64, /// What the notice stack keeps between frames: the pointer rest that gives a fresh auto-hide diff --git a/crates/ui-egui/src/proxy.rs b/crates/ui-egui/src/proxy.rs index 52a8b9c203..6ae3da9762 100644 --- a/crates/ui-egui/src/proxy.rs +++ b/crates/ui-egui/src/proxy.rs @@ -5,12 +5,17 @@ use craft::imaging::ui::live_preview::ProxyPlan; use photocraft_doc::Document; +use crate::PhotocraftApp; + /// Target pixel count for previews (fast enough to composite every frame on CPU). pub const PREVIEW_PIXELS: u64 = 2_500_000; /// Downscale factor for a document, or 1 when it's already small. pub fn factor(doc: &Document) -> u32 { - let px = doc.size.area(); + factor_for_area(doc.size.area()) +} + +fn factor_for_area(px: u64) -> u32 { if px <= PREVIEW_PIXELS * 2 { return 1; } @@ -19,7 +24,7 @@ pub fn factor(doc: &Document) -> u32 { /// Whether live previews may run on a reduced copy (Preferences › Performance › Low Resolution /// Previews, on by default). Off, every live preview renders at full resolution. -pub fn reduced_previews(app: &crate::PhotocraftApp) -> bool { +pub fn reduced_previews(app: &PhotocraftApp) -> bool { app.session.prefs().performance.low_resolution_previews } @@ -28,6 +33,19 @@ pub fn preview_factor(doc: &Document, reduced: bool) -> u32 { if reduced { factor(doc) } else { 1 } } +/// Pixel count for choosing preview resolution. Tests can scale the decision's input +/// while the fixture's real dimensions still govern rendering and allocation. +pub(crate) fn planning_area(_app: &PhotocraftApp, doc: &Document) -> u64 { + let area = doc.size.area(); + #[cfg(test)] + let area = area.saturating_mul(_app.preview_test_area_multiplier); + area +} + +pub(crate) fn app_factor(app: &PhotocraftApp, doc: &Document) -> u32 { + if reduced_previews(app) { factor_for_area(planning_area(app, doc)) } else { 1 } +} + /// A live preview's factor `k` capped for a view at `zoom` (physical screen pixels per document /// pixel) of a document of `document_pixels`: never coarser than the screen /// ([`ProxyPlan::factor`]), so a view at 100 % shows full resolution instead of k-pixel blocks while @@ -48,6 +66,10 @@ mod tests { fn factor_scales_with_size() { let small = Document::new("s", Size::new(1000, 1000), ColorMode::Rgb, SampleType::U8); assert_eq!(factor(&small), 1); + let boundary = Document::new("threshold", Size::new(2500, 2000), ColorMode::Rgb, SampleType::U8); + let above = Document::new("above threshold", Size::new(2501, 2000), ColorMode::Rgb, SampleType::U8); + assert_eq!(factor(&boundary), 1); + assert_eq!(factor(&above), 2); let big = Document::new("b", Size::new(6016, 6016), ColorMode::Rgb, SampleType::U8); let k = factor(&big); assert!((3..=5).contains(&k), "{k}"); diff --git a/crates/ui-egui/tests/it/main.rs b/crates/ui-egui/tests/it/main.rs index 5315c28e74..20dac68cfa 100644 --- a/crates/ui-egui/tests/it/main.rs +++ b/crates/ui-egui/tests/it/main.rs @@ -56,7 +56,6 @@ mod gpu_tests { mod color_managed_canvas; mod display_shadows; mod drag_preview_canvas; - mod full_res_preview; mod live_stroke_canvas; mod pattern_preview_canvas; mod ui_scale_canvas; From 5c1a47a8f3cdffd1ae02516976a0b426a6493db6 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 23 Nov 2026 19:38:12 +0000 Subject: [PATCH 2/2] Propagate GPU preview fixture errors from test helpers --- .../ui-egui/src/gpu_tests/full_res_preview.rs | 85 ++++++++++--------- 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/crates/ui-egui/src/gpu_tests/full_res_preview.rs b/crates/ui-egui/src/gpu_tests/full_res_preview.rs index fcfd63fb48..4997f60fd1 100644 --- a/crates/ui-egui/src/gpu_tests/full_res_preview.rs +++ b/crates/ui-egui/src/gpu_tests/full_res_preview.rs @@ -49,9 +49,9 @@ fn control(h: &mut Harness, method: &str, params: Value) { h.run_steps(3); } -fn columns_document(width: i32, height: i32) -> Document { +fn columns_document(width: i32, height: i32) -> Result { let mut doc = Document::with_background("columns", Size::new(width as u32, height as u32), ColorMode::Rgb, SampleType::U8, Color::WHITE); - let s = doc.layers[0].surface_mut().expect("background pixels"); + let s = doc.layers.first_mut().and_then(|layer| layer.surface_mut()).ok_or("missing background pixels")?; let row: Vec = (0..width) .flat_map(|x| { let v = if x % 2 == 0 { 0.0 } else { 1.0 }; @@ -62,13 +62,13 @@ fn columns_document(width: i32, height: i32) -> Document { let end = (y + 64).min(height); s.write_region(Rect::new(0, y, width, end), &row.repeat((end - y) as usize)); } - doc + Ok(doc) } -fn setup(h: &mut Harness, zoom: f32) { +fn setup(h: &mut Harness, zoom: f32) -> Result<(), &'static str> { { let app = h.state_mut(); - let doc = columns_document(W, H); + let doc = columns_document(W, H)?; assert_eq!(crate::proxy::factor(&doc), 1, "the fixture is below the production threshold"); assert_eq!(crate::proxy::app_factor(app, &doc), 2, "the test must exercise a twofold reduction"); app.session.add_document(doc, None); @@ -77,6 +77,7 @@ fn setup(h: &mut Harness, zoom: f32) { } control(h, "ui.set", json!({"zoom": zoom, "center": [W / 2, H / 2]})); h.run_steps(4); + Ok(()) } /// Whether the canvas draws on the GPU (the previews under test are the GPU canvas's). @@ -89,28 +90,29 @@ fn on_gpu(h: &mut Harness) -> bool { gpu } -fn low_res(h: &mut Harness, on: bool) { - h.state_mut().run("prefs.set", json!({"path": "performance.lowResolutionPreviews", "value": on})).expect("prefs.set"); +fn low_res(h: &mut Harness, on: bool) -> Result<(), String> { + h.state_mut().run("prefs.set", json!({"path": "performance.lowResolutionPreviews", "value": on}))?; h.run_steps(4); + Ok(()) } /// Luma along a row inside the visible document, to the left of centred dialogs. -fn row(h: &mut Harness) -> Vec { +fn row(h: &mut Harness) -> Result, &'static str> { h.run_steps(4); - let view = crate::canvas::active_view(h.state()).expect("the canvas has been shown"); + let view = crate::canvas::active_view(h.state()).ok_or("the canvas has not been shown")?; let image = egui::Rect::from_two_pos(view.to_screen(Point::ORIGIN), view.to_screen(Point::new(f64::from(W), f64::from(H)))); let visible = view.rect.intersect(image); // Windows CI uses a software rasterizer. A render timeout need not drop the submitted work. - let img = (0..3).find_map(|_| h.render().ok()).expect("render"); + let img = (0..3).find_map(|_| h.render().ok()).ok_or("could not render the canvas")?; let (x0, y) = (visible.min.x.ceil() as u32 + 12, visible.min.y.ceil() as u32 + 12); let x1 = x0 + 48; assert!(visible.contains(egui::pos2(x1 as f32, y as f32)), "sample row is inside the visible image"); - (x0..x1) + Ok((x0..x1) .map(|x| { let p = img.get_pixel(x, y).0; (i32::from(p[0]) * 3 + i32::from(p[1]) * 6 + i32::from(p[2])) / 10 }) - .collect() + .collect()) } /// Fraction of neighbouring screen pixels that differ like black and white. @@ -127,14 +129,14 @@ fn mean(r: &[i32]) -> f32 { /// previews on; zoomed out to 50 % the default drag runs on the reduced copy (only the black columns, inverted), and with /// them off it matches the committed view (the columns' mipmapped grey). #[test] -fn adjustment_layer_drag_previews_at_full_resolution_when_low_res_is_off() { +fn adjustment_layer_drag_previews_at_full_resolution_when_low_res_is_off() -> Result<(), String> { let _gpu = photocraft_testkit::gpu_lock(); - let Some(mut h) = harness() else { return }; - setup(&mut h, 1.0); + let Some(mut h) = harness() else { return Ok(()) }; + setup(&mut h, 1.0)?; if !on_gpu(&mut h) { - return; + return Ok(()); } - assert!(columns(&row(&mut h)) > 0.9, "the canvas shows the 1 px columns at 100 %"); + assert!(columns(&row(&mut h)?) > 0.9, "the canvas shows the 1 px columns at 100 %"); let layer = { let app = h.state_mut(); app.run("layer.newAdjustmentLayer.invert", json!({})).expect("adjustment layer"); @@ -143,67 +145,70 @@ fn adjustment_layer_drag_previews_at_full_resolution_when_low_res_is_off() { app.live_adjust = Some((id, json!({}))); id }; - let at_100 = row(&mut h); + let at_100 = row(&mut h)?; assert!(columns(&at_100) > 0.9, "default at 100 %: the drag is never coarser than the screen ({})", columns(&at_100)); control(&mut h, "ui.set", json!({"zoom": 0.5, "center": [W / 2, H / 2]})); h.state_mut().live_adjust = None; - let committed = mean(&row(&mut h)); + let committed = mean(&row(&mut h)?); assert!((60.0..220.0).contains(&committed), "zoomed out the inverted columns average to grey ({committed})"); h.state_mut().live_adjust = Some((layer, json!({}))); - let reduced = mean(&row(&mut h)); + let reduced = mean(&row(&mut h)?); assert!(reduced > 225.0, "default at 50 %: the reduced copy keeps only the (inverted) black columns ({reduced})"); - low_res(&mut h, false); + low_res(&mut h, false)?; h.state_mut().live_adjust = Some((layer, json!({}))); - let full = mean(&row(&mut h)); + let full = mean(&row(&mut h)?); assert!((full - committed).abs() < 8.0, "low-res previews off: the drag matches the committed view ({full} vs {committed})"); + Ok(()) } /// A filter dialog's live preview is never coarser than the screen either (#6326): at 100 % every /// column shows with low-resolution previews on; zoomed out to 50 % the default preview runs on /// the reduced copy (only the black columns), and with them off it matches the committed view. #[test] -fn filter_dialog_previews_at_full_resolution_when_low_res_is_off() { +fn filter_dialog_previews_at_full_resolution_when_low_res_is_off() -> Result<(), String> { let _gpu = photocraft_testkit::gpu_lock(); - let Some(mut h) = harness() else { return }; - setup(&mut h, 0.5); + let Some(mut h) = harness() else { return Ok(()) }; + setup(&mut h, 0.5)?; if !on_gpu(&mut h) { - return; + return Ok(()); } - let committed = mean(&row(&mut h)); + let committed = mean(&row(&mut h)?); assert!((60.0..220.0).contains(&committed), "zoomed out the columns average to grey ({committed})"); control(&mut h, "ui.set", json!({"zoom": 1.0, "center": [W / 2, H / 2]})); // Offset 0, 0 leaves the pixels as they are: any change is the preview's resolution. let _dialog = crate::filter_dialog::open(h.state_mut(), "filter.other.offset").expect("Offset dialog"); - let at_100 = row(&mut h); + let at_100 = row(&mut h)?; assert!(columns(&at_100) > 0.9, "default at 100 %: the preview is never coarser than the screen ({})", columns(&at_100)); control(&mut h, "ui.set", json!({"zoom": 0.5, "center": [W / 2, H / 2]})); - let reduced = mean(&row(&mut h)); + let reduced = mean(&row(&mut h)?); assert!(reduced < 30.0, "default at 50 %: the reduced copy keeps only the black columns ({reduced})"); - low_res(&mut h, false); - let full = mean(&row(&mut h)); + low_res(&mut h, false)?; + let full = mean(&row(&mut h)?); assert!((full - committed).abs() < 8.0, "low-res previews off: the preview matches the committed view ({full} vs {committed})"); + Ok(()) } #[test] -fn adjustment_dialog_zoomed_out_skips_the_reduced_copy_when_low_res_is_off() { +fn adjustment_dialog_zoomed_out_skips_the_reduced_copy_when_low_res_is_off() -> Result<(), String> { let _gpu = photocraft_testkit::gpu_lock(); - let Some(mut h) = harness() else { return }; - setup(&mut h, 0.5); + let Some(mut h) = harness() else { return Ok(()) }; + setup(&mut h, 0.5)?; if !on_gpu(&mut h) { - return; + return Ok(()); } - let committed = mean(&row(&mut h)); + let committed = mean(&row(&mut h)?); assert!((60.0..220.0).contains(&committed), "zoomed out the columns average to grey ({committed})"); let _dialog = crate::adjust_dialog::open(h.state_mut(), "image.adjustments.levels").expect("Levels dialog"); h.run_steps(4); let proxy = crate::adjust_preview::gpu_proxy(h.state_mut(), 0, 0.5).expect("default: zoomed out on the reduced copy"); assert_eq!(proxy.k, 2); - let reduced = mean(&row(&mut h)); + let reduced = mean(&row(&mut h)?); assert!(reduced < 30.0, "the reduced copy keeps only the black columns ({reduced})"); - low_res(&mut h, false); + low_res(&mut h, false)?; assert!(crate::adjust_preview::gpu_proxy(h.state_mut(), 0, 0.5).is_none(), "off: no reduced copy"); - let full = mean(&row(&mut h)); + let full = mean(&row(&mut h)?); assert!((full - committed).abs() < 8.0, "off: the preview matches the committed view ({full} vs {committed})"); + Ok(()) } /// Check the encoded texture directly, before canvas painting or adjustment previews. @@ -222,7 +227,7 @@ fn compositor_chunks_keep_their_columns() { // Keep three chunks across and two down, with a partial chunk on both axes. let width = 2 * photocraft_gpu::CHUNK + 24; let height = photocraft_gpu::CHUNK + 24; - let doc = columns_document(width as i32, height as i32); + let doc = columns_document(width as i32, height as i32).expect("columns document"); let refresh = gpu.refresh(doc.id.0, &doc, None, None); assert!(gpu.fault().is_none(), "GPU fault after canvas refresh: {:?}", gpu.fault()); if refresh.kind == "full" {