diff --git a/crates/ui-egui/src/canvas/render_worker.rs b/crates/ui-egui/src/canvas/render_worker.rs index 6b547645b..8bf3ebe48 100644 --- a/crates/ui-egui/src/canvas/render_worker.rs +++ b/crates/ui-egui/src/canvas/render_worker.rs @@ -310,9 +310,13 @@ impl Renders { } } - fn keep(&mut self, job: &Job) { + fn keep(&mut self, job: &Job, d: &Done) { self.last = Some((job.uid, job.page, job.view.scale)); - self.last_shown = Some((job.uid, job.page, job.view.clone())); + self.handed_over(d); + } + + fn handed_over(&mut self, d: &Done) { + self.last_shown = Some((d.uid, d.page, d.view.clone())); } fn kept_image_is_as_sharp_as_a_preview(&self, job: &Job) -> bool { @@ -360,14 +364,18 @@ impl Renders { if !self.wants_preview(job) { return None; } - preview_with(job, &mut self.preview) + let done = preview_with(job, &mut self.preview); + if let Some(d) = &done { + self.handed_over(d); + } + done } /// The image of `job`'s view, built on the kept one where it can be. pub fn refine(&mut self, job: &Job) -> Option { let done = guarded(&mut self.full, |r| run(job, &job.view, r, false)); if let Some(d) = &done { - self.keep(job); + self.keep(job, d); if d.work == Work::Full { self.full_ms = d.ms; } @@ -450,7 +458,10 @@ impl Renders { // A pan or an edit at this zoom builds on this render: no preview for it. self.last = Some((job.uid, job.page, job.view.scale)); self.steps = Some(Stepping { job: job.clone(), fonts: figcraft_text::layout_generation(), steps, spent: 0.0 }); - drawn.map(Refined::Shown) + drawn.map(|d| { + self.handed_over(&d); + Refined::Shown(d) + }) } Ok(Err(d)) => Some(Refined::Done(self.finished(job, *d))), Err(_) => { @@ -463,7 +474,7 @@ impl Renders { /// Record a render done at once in [`Self::refine_for`]. fn finished(&mut self, job: &Job, d: Option) -> Option { if let Some(d) = &d { - self.keep(job); + self.keep(job, d); if d.work == Work::Full { self.full_ms = d.ms; } diff --git a/crates/ui-egui/src/canvas/zoom_preview_tests.rs b/crates/ui-egui/src/canvas/zoom_preview_tests.rs index 8a5d997c5..274ff1b52 100644 --- a/crates/ui-egui/src/canvas/zoom_preview_tests.rs +++ b/crates/ui-egui/src/canvas/zoom_preview_tests.rs @@ -193,6 +193,27 @@ fn a_zoom_in_shows_the_kept_image_until_a_preview_would_be_sharper() { assert!(r.preview(&at(2.0 * PREVIEW_FACTOR)).is_none(), "measured from the image refined last"); } +#[test] +fn a_zoom_in_after_an_unrefined_zoom_out_is_measured_from_the_preview_on_screen() { + let (s, _) = document(); + let ds = s.ds().unwrap(); + let at = |scale: f64| job(&ds.doc, ds.page, ds.uid, view_at((300.0, 200.0), scale, 400, 300)); + let mut r = Renders::with_threshold(0.0); + r.refine(&at(1.0)).unwrap(); + assert!(r.preview(&at(0.25)).is_some_and(|d| d.coarse), "a zoom out shows its preview"); + assert!(r.preview(&at(2.0)).is_some(), "the preview on screen is coarser than this zoom's preview"); + assert!(r.preview(&at(2.0)).is_none(), "the same zoom again: the preview on screen is as sharp as another"); + + let mut w = waiting(Duration::from_secs(3600)); + w.submit(at(1.0)); + assert!(refined(&mut w).is_some_and(|d| !d.coarse && d.view.scale == 1.0)); + let now = Instant::now(); + w.submit(at(0.25)); + assert!(w.poll_at(now).is_some_and(|d| d.coarse), "the browser shows the zoom out's preview"); + w.submit(at(2.0)); + assert!(w.poll_at(now).is_some_and(|d| d.coarse && d.view.scale == 2.0 / PREVIEW_FACTOR), "and previews the zoom in that follows it"); +} + /// Zoom, pan and edit with `r`; whether each step was previewed, and the pan's and the edit's /// images. fn zoom_pan_edit(r: &mut Renders) -> (Vec, Done, Done) { @@ -261,7 +282,7 @@ fn previews_cover_the_view_for_any_zoom_and_density() { let (s, _) = document(); let ds = s.ds().unwrap(); let mut r = Renders::with_threshold(0.0); - r.refine(&job(&ds.doc, ds.page, ds.uid, view_at((0.0, 0.0), 0.37, 64, 64))).unwrap(); + let kept = job(&ds.doc, ds.page, ds.uid, view_at((0.0, 0.0), 0.37, 64, 64)); let mut n = 0; // Zooms from 2% to 6400% at 1x, 1.5x and 2x displays, odd sizes, centres off the pixel grid. for zoom in [0.02, 0.1, 0.333, 1.0, 2.5, 8.0, 64.0] { @@ -270,6 +291,7 @@ fn previews_cover_the_view_for_any_zoom_and_density() { let v = view_at((123.456, -78.9), zoom * ppp, w, h); let c = coarse_view(&v); assert!(covers(&c, &v), "coarse view of {v:?}"); + r.refine(&kept).unwrap(); let p = r.preview(&job(&ds.doc, ds.page, ds.uid, v.clone())).expect("a preview"); assert!(covers(&p.view, &v), "preview of {v:?} shows {:?}", p.view); n += 1; diff --git a/docs/hardware-parity.md b/docs/hardware-parity.md index 902fda46f..b8096f3ff 100644 --- a/docs/hardware-parity.md +++ b/docs/hardware-parity.md @@ -12,7 +12,7 @@ since 2025). FigCraft renders the canvas on the CPU and presents it through wgpu | Feature | Figma | FigCraft (macOS / Windows / Linux / web) | Hours | |---|---|---|---| -| Canvas rendering | GPU | CPU (tiny-skia), banded across cores, retained (re-renders only what an edit or pan touches), levels of detail below 50% zoom, images drawn from the smallest copy that holds the size they show, down to 256 px (#1483); when renders from scratch are slow, a zoom out (or a zoom in past 4×) shows the whole view coarsely first, then refines it (#312), and a zoom in up to 4× shows the image already on screen, enlarged, until the refined one; shown through wgpu (WebGPU or WebGL2 in the browser) | 30–60 for a GPU path | +| Canvas rendering | GPU | CPU (tiny-skia), banded across cores, retained (re-renders only what an edit or pan touches), levels of detail below 50% zoom, images drawn from the smallest copy that holds the size they show, down to 256 px (#1483); when renders from scratch are slow, a zoom out, a zoom in past 4× or one to where the image on screen doesn't reach shows the whole view coarsely first, then refines it (#312), and a zoom in up to 4× inside the image on screen (a preview too) shows that image, enlarged, until the refined one; shown through wgpu (WebGPU or WebGL2 in the browser) | 30–60 for a GPU path | | Effects (blurs, glass, noise) | GPU | CPU | in the above | | HiDPI / Retina | yes | yes (all); a canvas image rendered at the screen's density is placed on whole device pixels, so fractional pans, zooms and display scales don't blur it (#359; geometry tests, the snapping not judged by eye) | — | | Wide-gamut display (Display P3) | yes, on capable displays | colours stored and exported in P3; the screen shows sRGB: eframe/egui-wgpu 0.37 configure an 8-bit sRGB surface with no colour space option, although wgpu 30 can present Display P3 or extended sRGB on Metal, DX12, Vulkan and WebGPU (see gaps #18). The colour picker warns about colours outside sRGB and View ▸ Soft-proof sRGB stripes them on the canvas | 2–5 | @@ -50,7 +50,7 @@ Nothing has been timed against Figma on the same document (needs `.fig` import). | Date | Change | Summary | |---|---|---| -| 2026-11-10 | minor | Zoom in without coarse previews (#312 follow-up): a zoom in to at most 4× the image on screen, inside the area it covers, shows that image enlarged until the refined one comes; it is at least as sharp as a preview with a quarter of the pixels each way. During a pinch or a held zoom each step used to get a preview and drop its refined image for the next step's, so the canvas stayed coarse until the zoom stopped. Zoom outs, other pages and larger zoom ins still get previews. | +| 2026-11-10 | minor | Zoom in without coarse previews (#312 follow-up): a zoom in to at most 4× the image on screen, inside the area it covers, shows that image enlarged until the refined one comes, measured from what the screen shows, a preview included; it is at least as sharp as a preview with a quarter of the pixels each way. During a pinch or a held zoom each step used to get a preview and drop its refined image for the next step's, so the canvas stayed coarse until the zoom stopped. Zoom outs, other pages and larger zoom ins still get previews. | | 2026-11-18 | minor | M9, gap 6: the browser build uses team libraries and plugin directories on a server, through its WebSocket requests: adding a library by its link, its styles and components, publishing to it, Show usage and the reports a file sends; browsing a directory and installing from it, for the page only. Scripts through `window.figcraft` still can't, as commands there don't wait for the server. Numbers unchanged. Tests: `exchange_tests`. | | 2026-11-10 | minor | Zoomed-out images: the canvas's copies of an image shown smaller than its pixels now also come at 256, 512, 1024 and 2048 px, the smallest that holds what the screen shows, and images of 4096 px or less get them too (they were drawn from the image itself at any size). On a page of 237 photos, about 4.6 GB decoded against the 512 MB cache, every zoomed-out render decoded them again: 3.4 s a frame at 1% before, 0.9 s the first time and 4 ms after; peak memory 3.9 → 2.3 GB. Exports, and images shown at their own size or larger, still draw from the image itself. | | 2026-11-10 | patch | M10, #1343 (also #1422, #2233): Windows: the window no longer draws below a hidden caption. FigCraft draws its own title bar on Windows and opens undecorated windows, but winit 0.30 still gives them `WS_CAPTION` and `WS_BORDER`; on some systems the desktop compositor reserves that caption, so the content was drawn about 30 px low (a black band above it) while clicks kept the client coordinates and landed above what was drawn. A per-frame step (`apps/figcraft/src/window_frame.rs`, safe `winsafe` calls, Windows only) clears `WS_CAPTION` and `WS_BORDER` from every FigCraft window, the main one and the others, keeping the sizing border and window buttons so edge resizing and snap work, and writes only when a style changed (winit puts them back on maximize and restore). The same fix as DesignCraft #2139 and PhotoCraft #2401; the maximize-to-work-area trim from DesignCraft is left for a later change. Not run on a Windows machine that shows the offset: the style math and the per-frame hook are tested, the window itself needs a live check. Tests: `window_frame_tests`. Numbers unchanged | diff --git a/docs/roadmap.md b/docs/roadmap.md index 54231183b..779ae4414 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -76,7 +76,7 @@ blockers. | Date | Change | Summary | |---|---|---| -| 2026-11-10 | minor | Zoom in without coarse previews (#312 follow-up): a zoom in to at most 4× the image on screen, inside the area it covers, shows that image enlarged until the refined one comes; it is at least as sharp as a preview with a quarter of the pixels each way. During a pinch or a held zoom each step used to get a preview and drop its refined image for the next step's, so the canvas stayed coarse until the zoom stopped. Zoom outs, other pages and larger zoom ins still get previews. | +| 2026-11-10 | minor | Zoom in without coarse previews (#312 follow-up): a zoom in to at most 4× the image on screen, inside the area it covers, shows that image enlarged until the refined one comes, measured from what the screen shows, a preview included; it is at least as sharp as a preview with a quarter of the pixels each way. During a pinch or a held zoom each step used to get a preview and drop its refined image for the next step's, so the canvas stayed coarse until the zoom stopped. Zoom outs, other pages and larger zoom ins still get previews. | | 2026-11-19 | minor | M12, #2237 (step 1 of 4): code blocks in the document and engine. `board.codeBlock` places a dark panel of monospace text as tall as its lines, `board.setLanguage` picks one of 16 languages, and `board.nextSticky` makes the next block beside it; the toolbar entry, language menu, highlighting, line numbers and `.jam` import are missing. Numbers unchanged. | | 2026-11-18 | minor | M3, gap 10: library analytics count insertions and detachments of styles and variables. Applying one, or copying or duplicating content that uses it, inserts it; the Detach button detaches it; an instance counts as its component alone. Show usage and `library.usage` give them per style and variable over the chosen period. Modes aren't counted. Numbers unchanged. Tests: `library_asset_counts_tests`, `library_assets_tests`. | | 2026-11-18 | minor | M9, gap 6: the browser build uses team libraries and plugin directories on a server, through its WebSocket requests: adding a library by its link, its styles and components, publishing to it, Show usage and the reports a file sends; browsing a directory and installing from it, for the page only. Scripts through `window.figcraft` still can't, as commands there don't wait for the server. Numbers unchanged. Tests: `exchange_tests`. |