mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
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.
This commit is contained in:
1 parent
8878ff335f
commit
fadef65cc8
2 files changed
+43
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in new issue
Block a user