Merge look-fix-request-drain app work (paint while a screenshot is pending)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. Taylor
2026-11-29 00:42:30 +00:00
co-authored by Claude Opus 5.5
2 changed files with 59 additions and 2 deletions
+3 -2
View File
@@ -41,8 +41,9 @@ impl SlideApp {
channel.captures.note_pass();
let finished = channel.captures.issue(&host, craft::ui::runtime::motion::now(), document);
control::finish_captures(self, &mut channel, finished);
// A capture settles over passes and waits out its delay; an idle window would draw no more of them.
if channel.captures.any_unissued() {
// A capture settles over passes and waits out its delay, and the renderer reads an issued one back as it submits
// a later frame; an idle window would draw no more of them.
if channel.captures.any_unissued() || channel.captures.any_pending() {
ui.ctx().request_repaint();
}
self.control = Some(channel);
+56
View File
@@ -1094,6 +1094,62 @@ mod tests {
Ok(())
}
/// Sends its request as the first pass of the next frame begins, and runs that frame twice: the request arrives
/// after the frame took its requests, and the transport's wake went to the first pass.
struct ArriveInRerunFrame(Option<(mpsc::Sender<ControlRequest>, ControlRequest)>);
impl egui::Plugin for ArriveInRerunFrame {
fn debug_name(&self) -> &'static str {
"control request arriving in a rerun frame"
}
fn on_begin_pass(&mut self, ui: &mut egui::Ui) {
if let Some((sender, request)) = self.0.take() {
let _ = sender.send(request);
ui.ctx().request_discard("a request arriving in a frame that runs twice");
}
}
}
/// A request that arrives after the frame took its requests, in a frame that runs twice, is answered by a window at
/// rest: eframe runs a frame only for a wake at most one pass old, so the frame that left the request waiting asks
/// for the next one itself.
#[test]
fn a_request_arriving_in_a_frame_that_runs_twice_is_answered() -> Result<(), Box<dyn Error>> {
let (sender, receiver) = mpsc::channel();
let mut session = deckcraft_engine::Session::with_new();
deckcraft_engine::sample::open_sample(&mut session)?;
let mut harness = harness_with(
session,
crate::Services::default(),
egui_kittest::Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0),
|platform| platform.control = Some(ControlChannel::new(receiver)),
);
harness.run_steps(30);
let wakes = Arc::new(std::sync::Mutex::new(Vec::new()));
let sink = wakes.clone();
harness.ctx.set_request_repaint_callback(move |info| {
if let Ok(mut wakes) = sink.lock() {
wakes.push(info.current_cumulative_pass_nr);
}
});
let (request, reply) = ControlRequest::new("ui.inspect", json!({}));
harness.ctx.add_plugin(ArriveInRerunFrame(Some((sender.clone(), request))));
// The frames eframe runs: the one the transport's wake started, then one for each wake it keeps.
for _ in 0..30 {
harness.step();
if let Ok(answer) = reply.try_recv() {
assert_eq!(answer["ok"], true, "{answer}");
return Ok(());
}
let now = harness.ctx.cumulative_pass_nr();
if !wakes.lock().map_err(|_| "wakes")?.drain(..).any(|nr| now <= nr + 1) {
break;
}
}
Err("the request was left waiting with no frame to take it".into())
}
/// A pass shows the command states of every request taken before it: a diagram inserted in the same frame as the
/// switch to its tab leaves Change Colors enabled there, and a labelled click opens its colour menu.
#[test]