From 3c9293022491c8687747053dcc2d1f892890a866 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Tue, 17 Nov 2026 17:14:57 +0700 Subject: [PATCH] M8: the strips a pan uncovers render in parallel bands, as full renders do --- crates/render/src/band_tests.rs | 51 +++++++++++++++++++++++ crates/render/src/lib.rs | 54 ++++++++++++++++++++++++ crates/render/src/pan_bench_tests.rs | 62 ++++++++++++++++++++++++++++ crates/render/src/retained.rs | 2 +- docs/gaps.md | 11 ++++- 5 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 crates/render/src/pan_bench_tests.rs diff --git a/crates/render/src/band_tests.rs b/crates/render/src/band_tests.rs index 6cdf2cd88..5af2f353f 100644 --- a/crates/render/src/band_tests.rs +++ b/crates/render/src/band_tests.rs @@ -163,3 +163,54 @@ fn huge_backdrop_blur_renders_in_one_piece() { assert!(render_bands(&d, p, &view(1.0), &Options::default(), 4).is_none()); assert!(render_view(&d, p, &view(1.0), &Options::default()).is_some()); } + +/// [`row_diffs`] down the columns: an artifact of column bands runs down a whole column. +fn col_diffs(a: &Pixmap, b: &Pixmap) -> Vec<(f64, usize)> { + let (w, h) = (a.width() as usize, a.height() as usize); + let column = |p: &Pixmap, x: usize| -> Vec { (0..h).flat_map(|y| p.data()[(y * w + x) * 4..(y * w + x) * 4 + 4].to_vec()).collect() }; + (0..w).map(|x| row_stats(&column(a, x), &column(b, x))).collect() +} + +#[test] +fn columns_match_one_piece_rendering() { + let (d, p) = scene(true, true); + for scale in [1.0, 2.0] { + let v = view(scale); + let one = render_view_single(&d, p, &v, &Options::default()).unwrap(); + for bands in [2, 3, 7] { + let banded = render_columns(&d, p, &v, &Options::default(), bands).unwrap(); + assert_eq!((banded.width(), banded.height()), (one.width(), one.height())); + for (x, (mean, off)) in col_diffs(&one, &banded).into_iter().enumerate() { + assert!( + row_ok(mean, off, v.height as usize), + "scale {scale}, {bands} columns: column {x} differs ({off} pixels, {mean:.2} on average)" + ); + } + } + } + let (mut d, p) = scene(true, true); + let g = d.find_by_name("Glass", None)[0]; + d.get_mut(g).unwrap().effects = vec![Effect { kind: EffectKind::BackgroundBlur(figcraft_doc::Blur::uniform(1e6)), visible: true }]; + assert!(render_columns(&d, p, &view(1.0), &Options::default(), 4).is_none(), "a blur past a whole column: in one piece"); +} + +/// The strips a pan uncovers render in bands along their longer side, and match one piece: no row +/// or column where a band's edge shows (a seam differs along all of it). A strip is too narrow for +/// [`row_ok`]'s mean: the edge antialiasing every band render has (a few pixels along a curve) +/// outweighs it there, so this counts the pixels that differ at all. +#[test] +fn a_tall_or_wide_part_of_a_view_matches_one_piece_rendering() { + let (d, p) = scene(true, true); + for (w, h) in [(60, 480), (880, 60), (200, 200)] { + let v = View { origin: (35.0, -10.0), scale: 2.0, width: w, height: h }; + let one = render_view_single(&d, p, &v, &Options::default()).unwrap(); + let part = render_part(&d, p, &v, &Options::default()).unwrap(); + assert_eq!((part.width(), part.height()), (w, h)); + for (y, (_, off)) in row_diffs(&one, &part).into_iter().enumerate() { + assert!(off * 20 <= w as usize, "{w} x {h}: row {y} differs in {off} pixels"); + } + for (x, (_, off)) in col_diffs(&one, &part).into_iter().enumerate() { + assert!(off * 20 <= h as usize, "{w} x {h}: column {x} differs in {off} pixels"); + } + } +} diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index 6700fbc72..8d0710cda 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -138,6 +138,58 @@ pub fn render_view(doc: &Document, page: NodeId, view: &View, opts: &Options) -> render_one(doc, page, view, opts) } +/// [`render_view`] for a part of a view a retained render redraws (the strips a pan uncovers, the +/// area of an edit): in parallel bands however few pixels it has, along its longer side (rows of a +/// tall strip, columns of a wide one), since what it costs is the layers it crosses (a shadow is +/// drawn whole for a sliver of it), not its pixels. +pub(crate) fn render_part(doc: &Document, page: NodeId, view: &View, opts: &Options) -> Option { + start_render(); + #[cfg(not(target_arch = "wasm32"))] + if let Some(pool) = band_pool() { + let threads = pool.current_num_threads().clamp(1, 16) as u32; + let rendered = if view.height >= view.width { + let bands = threads.min(view.height / 96); + (bands > 1).then(|| pool.install(|| render_bands(doc, page, view, opts, bands))).flatten() + } else { + let bands = threads.min(view.width / 96); + (bands > 1).then(|| pool.install(|| render_columns(doc, page, view, opts, bands))).flatten() + }; + if rendered.is_some() { + return rendered; + } + } + render_one(doc, page, view, opts) +} + +/// [`render_bands`] across: `bands` columns, overlapping by what background blurs read. +#[cfg(not(target_arch = "wasm32"))] +fn render_columns(doc: &Document, page: NodeId, view: &View, opts: &Options, bands: u32) -> Option { + use rayon::prelude::*; + let band_w = view.width.div_ceil(bands.max(1)); + let overlap = band_overlap(doc, view, band_w)?; + let s = view.scale.max(1e-9); + let parts: Vec<(u32, Option)> = (0..bands) + .into_par_iter() + .map(|i| { + let x0 = i * band_w; + let w = band_w.min(view.width.saturating_sub(x0)).max(1); + let left = x0.saturating_sub(overlap); + let right = (x0 + w + overlap).min(view.width).max(x0 + w); + let v = + View { origin: (view.origin.0 + f64::from(left) / s, view.origin.1), scale: view.scale, width: right - left, height: view.height }; + let own = tiny_skia::IntRect::from_xywh((x0 - left) as i32, 0, w, view.height.clamp(1, 16_384)); + (x0, render_one(doc, page, &v, opts).zip(own).and_then(|(p, r)| p.clone_rect(r))) + }) + .collect(); + let mut out = new_pixmap(view.width, view.height)?; + let copy = tiny_skia::PixmapPaint { blend_mode: tiny_skia::BlendMode::Source, ..Default::default() }; + for (x0, part) in parts { + let part = part?; + out.draw_pixmap(x0 as i32, 0, part.as_ref(), ©, tiny_skia::Transform::identity(), None); + } + Some(out) +} + /// The stack a thread that renders needs (#1082). A level of the layer tree takes about 6.5 KB of /// stack in a render (6.8 KB in a debug build), so the deepest render [`MAX_EXPORT_DEPTH`] allows, /// pattern sources included, needs about 1.7 MB: more than the 2 MiB threads get by default once @@ -590,6 +642,8 @@ mod mask_bounds_tests; #[cfg(test)] mod paint_behaviour_tests; #[cfg(test)] +mod pan_bench_tests; +#[cfg(test)] mod progressive_tests; #[cfg(test)] mod render_depth_tests; diff --git a/crates/render/src/pan_bench_tests.rs b/crates/render/src/pan_bench_tests.rs new file mode 100644 index 000000000..aca3d60ad --- /dev/null +++ b/crates/render/src/pan_bench_tests.rs @@ -0,0 +1,62 @@ +//! Pan render timings: a page of 60 × 60 cards, each with a drop shadow and an inner shadow, seen +//! at 100% through a 1600 × 1100 device-pixel view. Run in release: +//! `cargo test --release -p figcraft-render --lib pan_render_timings -- --ignored --nocapture`. +//! +//! "full" renders the whole view; "pan" rows go through `Retained` as the canvas does, each step +//! moving the view by `step` device pixels and redrawing only the strips it uncovers. + +use std::sync::Arc; +use std::time::Instant; + +use figcraft_color::{Color, Paint}; +use figcraft_doc::{Document, Effect, EffectKind, NodeId, NodeKind, Shadow}; + +use crate::{Options, Retained, View, render_view}; + +const STEPS: u32 = 12; + +/// The cards: (document, page). +fn cards() -> (Arc, NodeId) { + let mut d = Document::new("pan bench"); + let p = d.first_page().unwrap(); + for y in 0..60u32 { + for x in 0..60u32 { + let c = d.create(p, NodeKind::Rectangle, "Card", f64::from(x) * 140.0, f64::from(y) * 110.0, 120.0, 90.0).unwrap(); + let n = d.get_mut(c).unwrap(); + n.fills = vec![Paint::solid(Color::new(x as f32 / 60.0, y as f32 / 60.0, 0.7, 1.0))]; + n.corners.radii = [12.0; 4]; + n.effects = vec![ + Effect { kind: EffectKind::DropShadow(Shadow { radius: 18.0, offset: (0.0, 6.0), ..Shadow::default() }), visible: true }, + Effect { kind: EffectKind::InnerShadow(Shadow { radius: 8.0, ..Shadow::default() }), visible: true }, + ]; + } + } + (Arc::new(d), p) +} + +fn view(origin: (f64, f64)) -> View { + View { origin, scale: 1.0, width: 1600, height: 1100 } +} + +#[test] +#[ignore = "timing; run in release with --ignored --nocapture"] +fn pan_render_timings() { + let (d, p) = cards(); + let opts = Options { lod: true, ..Options::default() }; + let t0 = Instant::now(); + for _ in 0..4 { + render_view(&d, p, &view((1000.0, 1000.0)), &opts).unwrap(); + } + println!("full: {:.1} ms", t0.elapsed().as_secs_f64() * 1000.0 / 4.0); + for (name, step) in [("pan right", (60.0, 0.0)), ("pan down", (0.0, 60.0)), ("pan diagonally", (60.0, 24.0)), ("pan right fast", (240.0, 0.0))] { + let mut r = Retained::default(); + let mut at = (1000.0, 1000.0); + r.render(&d, p, &view(at), &opts).unwrap(); + let t0 = Instant::now(); + for _ in 0..STEPS { + at = (at.0 + step.0, at.1 + step.1); + r.render(&d, p, &view(at), &opts).unwrap(); + } + println!("{name} ({:?} px a step): {:.1} ms a step", step, t0.elapsed().as_secs_f64() * 1000.0 / f64::from(STEPS)); + } +} diff --git a/crates/render/src/retained.rs b/crates/render/src/retained.rs index f345e21d6..e8a711fc6 100644 --- a/crates/render/src/retained.rs +++ b/crates/render/src/retained.rs @@ -553,7 +553,7 @@ fn render_into(frame: FrameRender<'_>, d: &Px, margin: i64, pix: &mut Pixmap) -> let (rw, rh) = (u32::try_from(ex - ox).ok()?, u32::try_from(ey - oy).ok()?); // The same pixel grid as the frame: origin (px + offset) / scale. let sub = View { origin: ((px.0 + ox) as f64 / s, (px.1 + oy) as f64 / s), scale: s, width: rw, height: rh }; - let part = render_view(doc, page, &sub, opts)?; + let part = crate::render_part(doc, page, &sub, opts)?; let inner = IntRect::from_xywh( i32::try_from(d.x0 - ox).ok()?, i32::try_from(d.y0 - oy).ok()?, diff --git a/docs/gaps.md b/docs/gaps.md index 30d4e2304..584d7f3a0 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -1,6 +1,6 @@ # Where FigCraft falls short of Figma -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-17 · **Change:** minor (gap 7: the desktop refines a zoom's preview once the zoom has paused; gap 1: the `.fig` export writes vector region paints (#2302); gap 13: a boolean group's corner radius (#2222); gap 24: mind maps, first step: a first node with three children on curved branches, laid out again after every edit (`board.mindMap`, `board.mindMapAdd`, #2226); gap 10: library analytics list how many layers and files use each style and variable; the Controller menu names each button as PlayStation and Switch controllers do; gap 6: widgets draw lines and SVG pictures (plugin API 6); gap 7: text reads only the fallback fonts it draws with; a board connector's path can be reshaped by dragging its path handles (#1710); gap 10: library analytics count insertions and show insertions and detachments over time; gap 6: a widget opens its plugin's panel (plugin API 5), whose callbacks redraw it; the keyboard's Menu key opens the context menu, as Shift+F10 does; gap 14: a collection of this file extends, following its edits at once; colour picker review fixes for text undo, fitted sidebars, moving controls and gradient variables; gap 6: plugin widgets have hover styles; gap 7: the browser draws a zoom's full render a band at a time; `.fig` import keeps the file's saved line breaks while the text and its box are unedited (#1236); FigJam outer shape outlines and sticky body fallback beside author text (#1341, #1397); Arabic draft catalog; gap 7: the browser refines a zoom's preview once the zoom has paused; gap 17: branches in live sessions, branch history entries, the list-merge rows brought up to date; gap 6: plugin widgets take text input and a property menu (plugin API 4); gap 24: board templates and tables; gap 24: a shared timer and voting sessions; gap 24: the board dot grid, connector ends dragged to re-attach, curved connectors; egui/eframe 0.37 verified for gap 18; known gaps from the #1311 review in gaps 4, 14, 15 and 16; gap 16: measurements kept on the canvas, a read-only layers panel in Dev Mode; gap 24: boards and their tail; Dev Mode tail: import lines in layer trees, compare with versions, an inspect-only canvas; gap 5: reviewed Turkish, Czech and Indonesian drafts, the Japanese draft completed; reviewed Russian catalog and integer plurals; `.fig` export: instance sizes, variables with modes, shared styles, variable-width strokes; sharing with a join code; text box sizes measured against documents re-saved by other software; live sessions per document; .fig export checked by opening written files in other software; experimental .fig export; keyboard shortcut parity suite and bindings; Simplified Chinese draft catalog; Latin American Spanish overlay; prototyping tail: gamepad triggers, widgets in prototypes, mode lookups; plugin directory on figcraft-server; Japanese and Korean draft catalogs and CJK UI fonts; plugin widgets and the plugin panel tail; French, German and Brazilian Portuguese draft catalogs; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and edit tail; dev resources links; extended collections tail; branch version history and finer list merges; comments and version history behaviour suite and fixes; canvas navigation, guides and grids behaviour suite and fixes; `.fig` import: editable vector networks, more layer kinds, variable prototype actions; `.fig` import, best effort: gap 1 down to its tail; Windows QA pass: everyday workflows on Windows 11, eight fixes incl. unsaved work kept after a crash or a forced quit; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; localization layer with a draft Spanish catalog; hosting figcraft-server: wss in the desktop app, server releases, deployment guide; plugin panels and settings; canvas fixes: boolean hit testing on the result, group drags, frame outlines and slices; code connect; stretch and scatter brushes, pen pressure; text on a path and pattern fills; team libraries on the server and swap library; branches: create, update from main, review and merge; animated GIF fills and TIFF images; Open recent, outlines for the selection and mask outlines: menu breadth 100%; extended collections, variables import/export, gradient stop and variant bindings: gap 14 down to its tail; the 2026-10-17 landings: `.fig` import fidelity, budgets for large files, the import report, a `.fig` copy from Save as and paste from another design app (gap 1); menus, the Actions palette, editor fixes, Selection colors and smart-selection spacing (gap 4); catalog counts re-measured (gap 5); bounded canvas pan overscan) · **Target:** Figma Design (desktop app 126.10.7) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-17 · **Change:** minor (gap 7: the strips a pan uncovers render in parallel bands; gap 7: the desktop refines a zoom's preview once the zoom has paused; gap 1: the `.fig` export writes vector region paints (#2302); gap 13: a boolean group's corner radius (#2222); gap 24: mind maps, first step: a first node with three children on curved branches, laid out again after every edit (`board.mindMap`, `board.mindMapAdd`, #2226); gap 10: library analytics list how many layers and files use each style and variable; the Controller menu names each button as PlayStation and Switch controllers do; gap 6: widgets draw lines and SVG pictures (plugin API 6); gap 7: text reads only the fallback fonts it draws with; a board connector's path can be reshaped by dragging its path handles (#1710); gap 10: library analytics count insertions and show insertions and detachments over time; gap 6: a widget opens its plugin's panel (plugin API 5), whose callbacks redraw it; the keyboard's Menu key opens the context menu, as Shift+F10 does; gap 14: a collection of this file extends, following its edits at once; colour picker review fixes for text undo, fitted sidebars, moving controls and gradient variables; gap 6: plugin widgets have hover styles; gap 7: the browser draws a zoom's full render a band at a time; `.fig` import keeps the file's saved line breaks while the text and its box are unedited (#1236); FigJam outer shape outlines and sticky body fallback beside author text (#1341, #1397); Arabic draft catalog; gap 7: the browser refines a zoom's preview once the zoom has paused; gap 17: branches in live sessions, branch history entries, the list-merge rows brought up to date; gap 6: plugin widgets take text input and a property menu (plugin API 4); gap 24: board templates and tables; gap 24: a shared timer and voting sessions; gap 24: the board dot grid, connector ends dragged to re-attach, curved connectors; egui/eframe 0.37 verified for gap 18; known gaps from the #1311 review in gaps 4, 14, 15 and 16; gap 16: measurements kept on the canvas, a read-only layers panel in Dev Mode; gap 24: boards and their tail; Dev Mode tail: import lines in layer trees, compare with versions, an inspect-only canvas; gap 5: reviewed Turkish, Czech and Indonesian drafts, the Japanese draft completed; reviewed Russian catalog and integer plurals; `.fig` export: instance sizes, variables with modes, shared styles, variable-width strokes; sharing with a join code; text box sizes measured against documents re-saved by other software; live sessions per document; .fig export checked by opening written files in other software; experimental .fig export; keyboard shortcut parity suite and bindings; Simplified Chinese draft catalog; Latin American Spanish overlay; prototyping tail: gamepad triggers, widgets in prototypes, mode lookups; plugin directory on figcraft-server; Japanese and Korean draft catalogs and CJK UI fonts; plugin widgets and the plugin panel tail; French, German and Brazilian Portuguese draft catalogs; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and edit tail; dev resources links; extended collections tail; branch version history and finer list merges; comments and version history behaviour suite and fixes; canvas navigation, guides and grids behaviour suite and fixes; `.fig` import: editable vector networks, more layer kinds, variable prototype actions; `.fig` import, best effort: gap 1 down to its tail; Windows QA pass: everyday workflows on Windows 11, eight fixes incl. unsaved work kept after a crash or a forced quit; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; localization layer with a draft Spanish catalog; hosting figcraft-server: wss in the desktop app, server releases, deployment guide; plugin panels and settings; canvas fixes: boolean hit testing on the result, group drags, frame outlines and slices; code connect; stretch and scatter brushes, pen pressure; text on a path and pattern fills; team libraries on the server and swap library; branches: create, update from main, review and merge; animated GIF fills and TIFF images; Open recent, outlines for the selection and mask outlines: menu breadth 100%; extended collections, variables import/export, gradient stop and variant bindings: gap 14 down to its tail; the 2026-10-17 landings: `.fig` import fidelity, budgets for large files, the import report, a `.fig` copy from Save as and paste from another design app (gap 1); menus, the Actions palette, editor fixes, Selection colors and smart-selection spacing (gap 4); catalog counts re-measured (gap 5); bounded canvas pan overscan) · **Target:** Figma Design (desktop app 126.10.7) Every known shortfall against Figma, one entry each, ranked by how much it stops a Figma user from doing real work in FigCraft. Agents: pick work from the top unless the owner says otherwise. The @@ -312,6 +312,14 @@ No alpha blockers: the alpha gate in [`roadmap.md`](roadmap.md#alpha-gate) passe wait for it: on a 29,000 × 12,600 page of 9,000 layers with images and shadows (M1 Pro, 2x display) full renders took 110–520 ms, and the preview stood in for that long. Pans and edits are refined at once, as before. +- **Landed (2026-11-17):** the strips a pan uncovers, and the areas an edit redraws, render in + parallel bands as full renders do (`render_part`): rows of a tall strip, columns of a wide one, + however few pixels they have. A strip costs the layers it crosses, not its pixels (a card's + shadow is drawn whole for a sliver of it), and was drawn on one thread: on a page of 3,600 cards + with a drop and an inner shadow each, a 60 px pan took 33 ms right and 47 ms down where the + whole view took 80 ms; now 9 and 11 ms (`pan_bench_tests`, release, a 32-thread desktop; bands stop at 16). In the app + (release) a pan step on that page went from 150–170 ms to 17–27 ms. The browser renders on one + thread and is unchanged. - **Landed (2026-10-28):** the browser refines a zoom's preview only once no newer request has come for 120 ms (`SETTLE_MS`), or for as long as its last full render took when that is shorter: its full renders run on the UI thread, and one between every two wheel steps held the page up @@ -601,6 +609,7 @@ No alpha blockers: the alpha gate in [`roadmap.md`](roadmap.md#alpha-gate) passe | Date | Change | Summary | |---|---|---| +| 2026-11-17 | minor | Gap 7: the strips a pan uncovers render in parallel bands (rows of a tall strip, columns of a wide one), 3–5× quicker pans on effect-heavy pages. Numbers unchanged. Tests: `band_tests::columns_match_one_piece_rendering`, `band_tests::a_tall_or_wide_part_of_a_view_matches_one_piece_rendering`; timings: `pan_bench_tests` | | 2026-11-17 | minor | Gap 7: the desktop refines a zoom's preview only once the zoom has paused, as the browser does, so a full render that can't be stopped no longer holds up the next steps of a held zoom. Numbers unchanged. Test: `zoom_preview_tests::the_render_thread_refines_a_zoom_only_once_it_pauses` | | 2026-11-12 | minor | Gap 1: the `.fig` export writes vector region paints (#2302); the 2026-10-26 "Landed" bullet no longer says the export drops them | | 2026-11-10 | minor | Gap 13: a boolean group's corner radius rounds every sharp corner of its result (#2222); the boolean clause leaves the 2026-10-12 "Left" list |