From fadef65cc88229dab60f07360663e16d007585b8 Mon Sep 17 00:00:00 2001 From: funkvay-star <71777367+funkvay-star@users.noreply.github.com> Date: Tue, 3 Nov 2026 21:12:15 +0400 Subject: [PATCH] Levels clipping: draw nothing while a background job runs (#3328) paint now returns before thresholds, scan and image while the session has jobs, and the display comes back once they are done. --- crates/ui-egui/src/levels_clipping.rs | 5 +++ crates/ui-egui/src/levels_clipping_tests.rs | 38 +++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/crates/ui-egui/src/levels_clipping.rs b/crates/ui-egui/src/levels_clipping.rs index 01e175a0945..66a334e4a65 100644 --- a/crates/ui-egui/src/levels_clipping.rs +++ b/crates/ui-egui/src/levels_clipping.rs @@ -360,6 +360,11 @@ pub fn paint(app: &mut PhotocraftApp, ctx: &egui::Context, painter: &egui::Paint app.levels_clipping = None; return; } + // A background job holds the workers and may replace the document: no thresholds, scan or + // image until it ends. + if app.session.has_jobs() { + return; + } let Some(req) = request(app, idx) else { return }; let Some(thr) = thresholds(&req.adj, req.doc.pixel_format().sample) else { return }; let max_side = (ctx.input(|i| i.max_texture_side) as u32).clamp(256, 8192); diff --git a/crates/ui-egui/src/levels_clipping_tests.rs b/crates/ui-egui/src/levels_clipping_tests.rs index 116e72dd0cc..f9fc4c4011e 100644 --- a/crates/ui-egui/src/levels_clipping_tests.rs +++ b/crates/ui-egui/src/levels_clipping_tests.rs @@ -386,6 +386,44 @@ fn ineligible_documents_show_no_display() { assert!(request(&app, 0).is_none(), "fill layer"); } +/// While a background job runs the display draws nothing and neither scans nor builds its +/// texture. It comes back once the job is done. +#[test] +fn a_running_job_holds_the_display() { + use std::sync::Arc; + use std::sync::atomic::{AtomicBool, Ordering}; + let ctx = egui::Context::default(); + let mut app = ramp_app(ColorMode::Rgb, SampleType::U8); + open_levels(&mut app, json!({"inBlack": 100}), Some("shadows")); + let gate = Arc::new(AtomicBool::new(false)); + let open = gate.clone(); + let started = app + .session + .start_job( + "test.slow", + json!({}), + "Slow", + false, + move |job| { + while !open.load(Ordering::Relaxed) { + job.check()?; + std::thread::sleep(std::time::Duration::from_millis(1)); + } + Ok(()) + }, + |_, ()| Ok(json!({})), + ) + .unwrap(); + let photocraft_engine::jobs::Started::Job(job) = started else { panic!("ran inline") }; + assert!(app.session.has_jobs()); + assert!(paint_view(&mut app, &ctx, &view(10.0)).is_none()); + assert!(app.levels_clipping.is_none(), "no scan and no texture while the job runs"); + gate.store(true, Ordering::Relaxed); + app.session.wait_job(job).unwrap(); + assert!(!app.session.has_jobs()); + assert!(paint_view(&mut app, &ctx, &view(10.0)).is_some(), "back once the job is done"); +} + /// A Smart Filter's Levels dialog edits the filter, not the layer's pixels: no display, and its /// cache goes as if no Levels dialog were open, even over a pixel layer. #[test]