From cb0b9afa4a8a2c1faad545eae3a6e61515e8bd9b Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 16 Nov 2026 13:13:18 +0000 Subject: [PATCH] merge-fwf: F7 settled regions: a Loading answer of the texture loader notes the asking code as still moving, so a settled region showing a stand-in reruns when the job lands; trial: the mip trial in a settling region --- crates/imaging/tests/it/transform_preview.rs | 53 ++++++++++++++----- .../src/primitives/textures/loader.rs | 7 ++- crates/ui-contract/src/runtime/lazy.rs | 3 +- 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/crates/imaging/tests/it/transform_preview.rs b/crates/imaging/tests/it/transform_preview.rs index 2cbb04bfe..77b6a8dd7 100644 --- a/crates/imaging/tests/it/transform_preview.rs +++ b/crates/imaging/tests/it/transform_preview.rs @@ -14,7 +14,7 @@ use craft_imaging::ui::transform_preview::{ }; use craft_imaging::ui::warp::WarpMesh; use craft_ui::canvas::{Canvas, PixelRect}; -use craft_ui::contract::{Show as _, ShowContainer as _}; +use craft_ui::contract::{Lazy, Show as _, ShowContainer as _}; use craft_ui::testing::{Fixture, trial}; use egui::{Color32, ColorImage, Shape}; @@ -382,6 +382,16 @@ fn white(name: &str) -> Rc { impl Mips { fn new() -> Self { + Self::with(false) + } + + /// The previews painted inside a settling region (`Lazy::settles`), which replays its last run while nothing the + /// framework tracks changed for it. + fn settling() -> Self { + Self::with(true) + } + + fn with(settles: bool) -> Self { let jobs = Arc::new(ManualJobs::new()); let painted = Rc::new(RefCell::new(Vec::<(Rc, f32)>::new())); let display = Rc::new(RefCell::new(None::)); @@ -389,13 +399,20 @@ impl Mips { let uploads = Rc::new(Cell::new(0)); let (paint, converted, seen, counted) = (Rc::clone(&painted), Rc::clone(&display), Rc::clone(&shown), Rc::clone(&uploads)); let mut fixture = Fixture::new(move |ui| { - let display = converted.borrow(); - let picks = paint - .borrow() - .iter() - .map(|(textures, scale)| textures.pick(ui.ctx(), PreviewTextures::choose(1.0, *scale, false), display.as_ref())) - .collect(); - *seen.borrow_mut() = picks; + let run = |ui: &mut egui::Ui| { + let display = converted.borrow(); + let picks = paint + .borrow() + .iter() + .map(|(textures, scale)| textures.pick(ui.ctx(), PreviewTextures::choose(1.0, *scale, false), display.as_ref())) + .collect(); + *seen.borrow_mut() = picks; + }; + if settles { + Lazy::new("previews", 0.0).settles(true).show(ui, run); + } else { + run(ui); + } counted.set(PreviewTextures::statistics(ui.ctx()).uploads); }); fixture.host(Arc::new(Host::builder(AppInfo { id: "trial", name: "Trial", version: "0" }).jobs(jobs.clone()).build())); @@ -404,9 +421,15 @@ impl Mips { } /// One frame painting `previews`. + /// A change of the previews or their scales arrives with input, as a drag's does. fn paint(&mut self, previews: &[(&Rc, f32)]) { - *self.painted.borrow_mut() = previews.iter().map(|(textures, scale)| (Rc::clone(textures), *scale)).collect(); - self.fixture.frame(Vec::new()); + let next: Vec<_> = previews.iter().map(|(textures, scale)| (Rc::clone(textures), *scale)).collect(); + let changed = { + let painted = self.painted.borrow(); + painted.len() != next.len() || painted.iter().zip(&next).any(|(a, b)| !Rc::ptr_eq(&a.0, &b.0) || a.1 != b.1) + }; + *self.painted.borrow_mut() = next; + self.fixture.frame(if changed { vec![egui::Event::WindowFocused(true)] } else { Vec::new() }); } /// The texture and uv extent the `at`th preview showed. @@ -424,10 +447,16 @@ fn near_uv(uv: [f32; 2], want: [f32; 2]) -> bool { } /// P91 (#13382): the frame that first needs a mip level builds none on the UI thread; level 0 stands in, the frames -/// while its job waits do no work for it, and the landing frame uploads it once. +/// while its job waits do no work for it, and the landing frame uploads it once. In a settling region the frame +/// after the job lands runs the region again with no other input and shows the level. #[trial] fn a_mip_level_first_needed_mid_drag_is_built_off_the_ui_thread() { - let mut mips = Mips::new(); + for settles in [false, true] { + mips_first_needed_mid_drag(if settles { Mips::settling() } else { Mips::new() }); + } +} + +fn mips_first_needed_mid_drag(mut mips: Mips) { let t = white("drag"); mips.paint(&[(&t, 1.0)]); let (level0, _) = mips.shown(0); diff --git a/crates/ui-contract/src/primitives/textures/loader.rs b/crates/ui-contract/src/primitives/textures/loader.rs index da2b9b40a..3b98ff466 100644 --- a/crates/ui-contract/src/primitives/textures/loader.rs +++ b/crates/ui-contract/src/primitives/textures/loader.rs @@ -4,6 +4,7 @@ use super::store::{Revision, TextureKey, TextureState, TextureStore, TextureStor use super::words::TextureWords; use crate::runtime::egui::{memory, pass, repaint}; use crate::runtime::env::Env; +use crate::runtime::replay; use craft_host::queue::{Cancel, JobQueue, QueueOptions}; use craft_host::{Jobs, Wake, default_jobs}; use egui::{Color32, ColorImage, Context}; @@ -160,7 +161,9 @@ impl Default for Pools { /// are dropped at the next frame that draws. Asked keys move to the priority they were last asked with. /// - **Failures.** A job returns a `LoadFailure`; the state carries it. A job that panics is stored as /// `LoadFailure::Panicked`. -/// - **Waking.** The queue asks for a pass when a job finishes; no timed repaint. +/// - **Waking.** The queue asks for a pass when a job finishes; no timed repaint. A `Loading` answer notes the +/// asking code as still moving (`runtime::replay`), so a settled region that shows a stand-in runs in that pass, +/// asks again and shows the finished picture, and its asking keeps the job. /// - **Without lanes** (`lanes == 0`) the first call in a frame runs one job inline. pub struct TextureLoader { store: TextureStore, @@ -234,6 +237,7 @@ impl TextureLoader { asked.frame = frame; Some(()) })?; + replay::note_unsettled(ctx); Some(TextureState::Loading { stand_in: state.shown() }) } @@ -263,6 +267,7 @@ impl TextureLoader { // The job runs in the next frame's `run_frame_work`; the web repaints only on input. repaint::request(ctx); } + replay::note_unsettled(ctx); TextureState::Loading { stand_in } } diff --git a/crates/ui-contract/src/runtime/lazy.rs b/crates/ui-contract/src/runtime/lazy.rs index 0274fd6de..4ad20aa82 100644 --- a/crates/ui-contract/src/runtime/lazy.rs +++ b/crates/ui-contract/src/runtime/lazy.rs @@ -248,7 +248,8 @@ pub(crate) fn replay(ctx: &Context, id: Id) { /// also needs the child at the `place` it ran at, which a measuring run cannot tell. /// /// It replays when its last run was in an earlier frame and since then: -/// - nothing in it moves: no animation off its end value, no repaint asked from inside it, no wake time reached; +/// - nothing in it moves: no animation off its end value, no repaint asked from inside it, no texture it shows still +/// loading, no wake time reached; /// - the pointer is not over it, no press started on it and none of its widgets is dragged or holds egui focus, and /// none of that held in its last run; /// - none of its stops holds focus or is the target of a focus request, now or in its last run;