mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 22:14:30 +00:00
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
This commit is contained in:
@@ -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<PreviewTextures> {
|
||||
|
||||
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<PreviewTextures>, f32)>::new()));
|
||||
let display = Rc::new(RefCell::new(None::<PreviewDisplay>));
|
||||
@@ -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<PreviewTextures>, 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);
|
||||
|
||||
@@ -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<K> Default for Pools<K> {
|
||||
/// 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<K: TextureKey> {
|
||||
store: TextureStore<K>,
|
||||
@@ -234,6 +237,7 @@ impl<K: TextureKey> TextureLoader<K> {
|
||||
asked.frame = frame;
|
||||
Some(())
|
||||
})?;
|
||||
replay::note_unsettled(ctx);
|
||||
Some(TextureState::Loading { stand_in: state.shown() })
|
||||
}
|
||||
|
||||
@@ -263,6 +267,7 @@ impl<K: TextureKey> TextureLoader<K> {
|
||||
// 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 }
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user