M8: a zoom in keeps the image on screen until the sharp one is ready

When renders from scratch take longer than about a frame, every new zoom
got a coarse preview first (#312), with a quarter of the pixels each way.
After a zoom out that is right: the old image, re-projected, covers a small
part of the view. After a zoom in it covers all of it, and enlarged up to
4x it is at least as sharp as the preview. During a pinch or a held zoom
each step also dropped its refined image as soon as the next step's request
came, so the canvas stayed coarse until the zoom stopped.

Now a zoom in to at most PREVIEW_FACTOR times the image last shown, inside
the area that image covers, gets no preview, up front or from the watchdog:
the image on screen stands in until the refined one comes. Zoom outs, other
pages and files, larger zoom ins and zooms to an area the image doesn't
cover still get previews. The browser's banded renders take the same rule,
measured from the last image finished rather than one still being drawn.

The previews' doc comments in render_worker.rs and zoom_preview_tests.rs
still say "a new zoom"; they now hold for zoom outs and large zoom ins.

Measured in the app on a page of 11 000 layers and 237 images (M4 Max),
39 zoom steps from 10% to 200%, read through `ui.inspect`: before, 5 of
them showed a preview; with this change none did, each showed the refined
image, and full renders at those zooms took 5-14 ms.
This commit is contained in:
Denis Gomes
2026-11-19 15:12:53 -05:00
parent 4e35fb9cea
commit ee405acecc
4 changed files with 63 additions and 10 deletions
+36 -5
View File
@@ -233,6 +233,7 @@ pub struct Renders {
preview: Retained,
/// The last full render's document, page and scale.
last: Option<(u64, NodeId, f64)>,
last_shown: Option<(u64, NodeId, View)>,
/// How long the last render from scratch took.
full_ms: f64,
/// Previews come first only when renders from scratch take at least this long.
@@ -298,7 +299,33 @@ impl Default for Renders {
impl Renders {
/// Previews when renders from scratch take at least `ms` (tests: 0, always).
pub fn with_threshold(ms: f64) -> Self {
Self { full: Retained::default(), preview: Retained::default(), last: None, full_ms: 0.0, preview_after_ms: ms, steps: None }
Self {
full: Retained::default(),
preview: Retained::default(),
last: None,
last_shown: None,
full_ms: 0.0,
preview_after_ms: ms,
steps: None,
}
}
fn keep(&mut self, job: &Job) {
self.last = Some((job.uid, job.page, job.view.scale));
self.last_shown = Some((job.uid, job.page, job.view.clone()));
}
fn kept_image_is_as_sharp_as_a_preview(&self, job: &Job) -> bool {
let Some((uid, page, kept)) = &self.last_shown else { return false };
let (outer, inner) = (kept.page_rect(), job.view.page_rect());
*uid == job.uid
&& *page == job.page
&& job.view.scale >= kept.scale
&& job.view.scale <= kept.scale * PREVIEW_FACTOR
&& outer.x0 <= inner.x0
&& outer.y0 <= inner.y0
&& outer.x1 >= inner.x1
&& outer.y1 >= inner.y1
}
/// Whether `job` is a render from scratch: the kept image is of another zoom, page or file, or
@@ -310,7 +337,11 @@ impl Renders {
/// Whether `job` gets a preview first: it renders from scratch and those have been slow on a
/// page already drawn (the first render has no measure).
fn wants_preview(&self, job: &Job) -> bool {
job.zoom_preview && self.last.is_some() && self.full_ms_so_far() >= self.preview_after_ms && self.starts_over(job)
job.zoom_preview
&& self.last.is_some()
&& self.full_ms_so_far() >= self.preview_after_ms
&& self.starts_over(job)
&& !self.kept_image_is_as_sharp_as_a_preview(job)
}
/// How long the last render from scratch took, or what the one being drawn in steps has taken
@@ -321,7 +352,7 @@ impl Renders {
/// Whether `job` should get a preview should its render run long: from scratch, with none first.
pub fn wants_late_preview(&self, job: &Job) -> bool {
job.zoom_preview && self.starts_over(job) && !self.wants_preview(job)
job.zoom_preview && self.starts_over(job) && !self.wants_preview(job) && !self.kept_image_is_as_sharp_as_a_preview(job)
}
/// The coarse preview of the whole of `job`'s view, when one should come first.
@@ -336,7 +367,7 @@ impl Renders {
pub fn refine(&mut self, job: &Job) -> Option<Done> {
let done = guarded(&mut self.full, |r| run(job, &job.view, r, false));
if let Some(d) = &done {
self.last = Some((job.uid, job.page, job.view.scale));
self.keep(job);
if d.work == Work::Full {
self.full_ms = d.ms;
}
@@ -432,7 +463,7 @@ impl Renders {
/// Record a render done at once in [`Self::refine_for`].
fn finished(&mut self, job: &Job, d: Option<Done>) -> Option<Done> {
if let Some(d) = &d {
self.last = Some((job.uid, job.page, job.view.scale));
self.keep(job);
if d.work == Work::Full {
self.full_ms = d.ms;
}
@@ -173,6 +173,26 @@ fn a_zoom_out_previews_the_whole_view_then_refines_to_a_fresh_render() {
assert!(same_pixels(&refined, &fresh), "the settled image is a render from scratch");
}
#[test]
fn a_zoom_in_shows_the_kept_image_until_a_preview_would_be_sharper() {
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();
for scale in [1.08, 2.0, PREVIEW_FACTOR] {
assert!(r.preview(&at(scale)).is_none(), "{scale}x: the kept image, enlarged, is as sharp as a preview");
assert!(!r.wants_late_preview(&at(scale)), "{scale}x: no preview beside the render either");
}
assert!(r.preview(&at(PREVIEW_FACTOR * 1.5)).is_some(), "enlarged past a preview's sharpness");
assert!(r.preview(&at(0.5)).is_some(), "a zoom out");
let mut aside = at(2.0);
aside.view.origin.0 += 10_000.0;
assert!(r.preview(&aside).is_some(), "a zoom in where the kept image isn't");
r.refine(&at(2.0)).unwrap();
assert!(r.preview(&at(2.0 * PREVIEW_FACTOR)).is_none(), "measured from the image refined last");
}
/// 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<bool>, Done, Done) {
@@ -343,7 +363,7 @@ fn renders_from_scratch_with_nothing_to_go_by_get_a_late_preview() {
let first = at(&doc, page, uid, 1.0);
assert!(r.wants_late_preview(&first) && r.preview(&first).is_none(), "the first render");
r.refine(&first).unwrap();
assert!(r.wants_late_preview(&at(&doc, page, uid, 4.0)), "a zoom after quick renders");
assert!(r.wants_late_preview(&at(&doc, page, uid, 0.25)), "a zoom after quick renders");
assert!(r.wants_late_preview(&at(&doc, page, uid + 1, 1.0)), "another file");
let mut panned = first.clone();
panned.view.origin.0 += 5.0;
@@ -357,7 +377,7 @@ fn renders_from_scratch_with_nothing_to_go_by_get_a_late_preview() {
// Renders that have been slow: the preview comes first instead.
let mut slow = Renders::with_threshold(0.0);
slow.refine(&first).unwrap();
let zoom = at(&doc, page, uid, 4.0);
let zoom = at(&doc, page, uid, 0.25);
assert!(!slow.wants_late_preview(&zoom) && slow.preview(&zoom).is_some());
}
+3 -2
View File
@@ -1,6 +1,6 @@
# Hardware and platform parity
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-18 · **Change:** minor (the browser build uses team libraries and plugin directories on a server; unused; zoomed-out images draw from small copies that stay decoded, so a page of photos zooms out without decoding them again; under Wayland a minimised window answers control and MCP requests in about half a second instead of timing out after 60 s (#1906); images copied in other apps paste in the browser (#492); text reads only the fallback fonts it draws with; `doc.list` gives AI agents and plugins the open files' names, not their paths (#1117); a batch keeps one undo snapshot, not one per step (#1099); one depth cap bounds a whole render, pattern sources included, and render threads get 8 MiB stacks (#1082); in the browser an internal error that stops the page keeps its unsaved files, which open again on reload (#1123); the portable Windows zip keeps its settings, recovery copies and plugins in `config\` beside the executable, starting with an installed copy's preferences; the window starts on other graphics when its first ones fail before the first frame: Direct3D 12 compiles with FXC and no device compiles wgpu's indirect-validation shaders, then Vulkan, OpenGL and lower requirements on the power-saving GPU (#965, #1438); large images on the canvas draw from a smaller copy, so two 16k images no longer lag (#1483); macOS: the Quit menu and ⌘Q ask about unsaved changes (#857); egui/eframe 0.37 dependency migration; hidden-window screenshot deadlines; zoom previews; hidden windows answer control requests; macOS file opening, the Windows start-up message, Linux packaging; copy and paste in the browser; Windows QA pass; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; pen pressure for the Pencil and brushes on Windows and from browser styluses; macOS: quitting ends the process once everything is kept, avoiding the Touch Bar teardown crash (#781); Linux and BSD clipboard: images under Wayland, reads time out; minimised windows under Wayland; window controls on Wayland without server decorations; canvas textures on device pixels) · **Target:** Figma Design (desktop app 126.10.7)
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-18 · **Change:** minor (a zoom in shows the image on screen enlarged instead of a coarse preview, so a pinch stays sharp; the browser build uses team libraries and plugin directories on a server; unused; zoomed-out images draw from small copies that stay decoded, so a page of photos zooms out without decoding them again; under Wayland a minimised window answers control and MCP requests in about half a second instead of timing out after 60 s (#1906); images copied in other apps paste in the browser (#492); text reads only the fallback fonts it draws with; `doc.list` gives AI agents and plugins the open files' names, not their paths (#1117); a batch keeps one undo snapshot, not one per step (#1099); one depth cap bounds a whole render, pattern sources included, and render threads get 8 MiB stacks (#1082); in the browser an internal error that stops the page keeps its unsaved files, which open again on reload (#1123); the portable Windows zip keeps its settings, recovery copies and plugins in `config\` beside the executable, starting with an installed copy's preferences; the window starts on other graphics when its first ones fail before the first frame: Direct3D 12 compiles with FXC and no device compiles wgpu's indirect-validation shaders, then Vulkan, OpenGL and lower requirements on the power-saving GPU (#965, #1438); large images on the canvas draw from a smaller copy, so two 16k images no longer lag (#1483); macOS: the Quit menu and ⌘Q ask about unsaved changes (#857); egui/eframe 0.37 dependency migration; hidden-window screenshot deadlines; zoom previews; hidden windows answer control requests; macOS file opening, the Windows start-up message, Linux packaging; copy and paste in the browser; Windows QA pass; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; pen pressure for the Pencil and brushes on Windows and from browser styluses; macOS: quitting ends the process once everything is kept, avoiding the Touch Bar teardown crash (#781); Linux and BSD clipboard: images under Wayland, reads time out; minimised windows under Wayland; window controls on Wayland without server decorations; canvas textures on device pixels) · **Target:** Figma Design (desktop app 126.10.7)
How FigCraft uses hardware and which platforms it runs on, against Figma. Figma's desktop app is
Electron with a GPU helper process; its canvas renders on the GPU (WebGL, with WebGPU rolling out
@@ -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 new zoom shows the whole view coarsely first, then refines it (#312); 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 (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 |
| 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,6 +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-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 |
+2 -1
View File
File diff suppressed because one or more lines are too long