Repository navigation
feat(rune-text,rune): animate monochrome SMIL SVG icons with partial damage - #1291
Merged
Merged
Conversation
…frame hold Parse SMIL <animate>, <animateTransform>, and <set> elements on une::Icon once into a bounded per-icon plan (32 tracks, 64 keyframes), advance frames on the runtime clock so animations never reset across view rebuilds, and update a single streaming Pixels handle in place to reuse its image atlas slot. Static icons pay only a cached pointer lookup, and reduced motion draws the = 0 resting frame through the ordinary static atlas with zero frames scheduled.
…nd fix partial damage Rewrite PR #1291 as monochrome (currentColor) SMIL animation only, addressing every finding from review-1291.md: - Drop the colour (usvg) UI-thread animation path: multi-colour icons stay static via color_icon (emitting a one-time debug_assertions warning if they contain SMIL tags). - Compile monochrome animated icons once into a bounded flat Op + Track AST (crates/rune-text/src/icon/anim/parse.rs) enforcing hard pre-allocation caps matching opencode-plugin-runtime::svg (32 KiB, depth 16, 128 elements, 64 shapes, 8 opacity layers, 16 tracks, 16 KiB / 1024 path cmds, 1024 points, 64 keyframes, 8 transform ops, clock <= 3600s, repeat <= 10000, coords <= 4096, scale <= 64, skew <= 85 deg, spline y in [-4, 5]), plus defensive mask bounds in area::render_aaa and aaa::fill. - Render live monochrome frames into double-buffered (px+2)x(px+2) glyph-atlas tiles (Atlas::put_bordered / Atlas::write_bordered, KIND_GLYPH), flipping UV only when quantized coverage bytes change. Preserves Windows partial damage (~23x23 icon rect, 0 whole-window redraws), GPU tinting (0 hover/scale atlas thrash), rotation, and non-resting scale. - Eliminate static-icon overhead: single FxHashMap IconKind lookup replacing is_color_icon, AtomicBool fast path on icon::swapped (no RwLock when no swap active), untouched static icon_coverage_at, and single bool has_animated_icons() guard in El::cache. - Fix wake/sleep and SMIL semantics: flat-hold WaitingUntil sleep via wake_for_motion, live.visible() gating, loops_shown() Windows occlusion polling, mount-relative time for finite animations, El::cache/PaintKeep re-enable on finish, finite/indefinite <set> termination, calcMode="paced", additive="sum" on <animate>, normalized 1/2-arg scale, fractional repeatCount freeze, inherited <g> paint, <rect> ry, inline pill icons, and live a11y reduced-motion redraw wake.
Hona
added a commit
to anomalyco/opencode-rune
that referenced
this pull request
Nov 20, 2026
…d colour icons (#273) - Sync all SVG cap constants in crates/opencode-plugin-runtime/src/svg/mod.rs 1:1 with Rune's backstop caps (rune-text::icon::anim::parse, anomalyco/rune#1291): MAX_SVG_BYTES=32 KiB, MAX_DEPTH=16, MAX_ELEMENTS=128, MAX_SHAPES=64, MAX_LAYERS=8, MAX_ANIMATIONS=16, MAX_PATH_BYTES=16 KiB, MAX_PATH_COMMANDS=1024, MAX_POINTS_NUMBERS=1024, MAX_KEYFRAMES=64, MAX_TRANSFORM_OPS=8, MIN/MAX_VIEW_DIM=1..4096, MIN_DUR_SECS=0.016, MAX_CLOCK_SECS=3600, MAX_REPEAT_COUNT=10000, MAX_COORD=4096, MAX_STROKE_WIDTH=256, MAX_SCALE=64, MAX_SKEW_DEG=85, MIN/MAX_SPLINE_Y=-4..5. - Enforce opacity layer count (<= 8), transform arg bounds, keySpline y bounds, and signed begin/by validation in svg/validate.rs so hostile plugin icons are rejected first with plugin, icon, and attribute diagnostics. - Emit a dev-build stderr warning in icons::{replace_plugin,intern_svg} when a plugin's multi-colour icon declares SMIL animation elements that Rune ignores and renders static.
…ation via loop_step - Clamp <path d> coords and composed transforms (ctm_is_safe, res <= 256, i128 edge + MAX_DEV_COORD in convex/raster.rs), and reject failed animated SVGs to empty coverage instead of falling back to static icon_coverage_at. - Add monotonic Atlas::next_page_gen so popped and recreated overflow pages never collide with stale bordered SlotEntry handles, plus slot_dirty in-place rewrite on missed drawables. - Include n.text pill icons (t.cold.pills) in El::cache liveness checks (cache_layer.rs). - Fix SMIL semantics: per-track additive='replace' on <animateTransform>, signed negative by/additive='sum' deltas, by-only scale (1,1)->(1+bx,1+by), inherited <g> paint base for additive/by/to-only, and double-sign clock rejection. - Pace AnimState::Moving via 30 Hz WaitingUntil with forward next-pixel-change probing (MAX_PIXEL_PROBES=12), wire IconSlot into CyclePaint/loop_step so icon-only ticks skip paint walks, and skip empty-patch presents via is_unchanged().
…ace atlas boundary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supports monochrome (
currentColor) SMIL SVG animation elements (<animate>,<animateTransform>,<set>) onrune::Icon, paced viaWaitingUntil+loop_step/arm_loop, preserving Windows partial window damage with zero whole-window redraws and zero empty presents, and holding att = 0under reduced motion with zero idle frames.Scope & Deliberate Difference
currentColor) icons animate (built-in and third-party plugins, matching upstreamanomalyco/opencode#64577+#60001).color_icon(the colourusvgUI-thread animation path is dropped). Multi-colour icons containing SMIL tags emit a one-timedebug_assertionsstderr warning naming the icon (andrune-desktoplogs plugin + icon name).Shared Defence-in-Depth Caps
Defined in one place (
crates/rune-text/src/icon/anim/parse.rs:13-34) and matched 1:1 by OpenCode Desktop's sanitizer (crates/opencode-plugin-runtime/src/svg/mod.rs:21-46):MAX_SVG_BYTES = 32 KiB,MAX_DEPTH = 16,MAX_ELEMENTS = 128,MAX_SHAPES = 64,MAX_LAYERS = 8,MAX_ANIMATIONS = 16MAX_PATH_BYTES = 16 KiB,MAX_PATH_COMMANDS = 1024,MAX_POINTS_NUMBERS = 1024,MAX_KEYFRAMES = 64,MAX_TRANSFORM_OPS = 8MIN_VIEW_DIM = 1.0,MAX_VIEW_DIM = 4096.0,MIN_DUR_SECS = 0.016,MAX_CLOCK_SECS = 3600.0,MAX_REPEAT_COUNT = 10_000.0MAX_COORD = 4096.0,MAX_STROKE_WIDTH = 256.0,MAX_SCALE = 64.0,MAX_SKEW_DEG = 85.0,MIN_SPLINE_Y = -4.0,MAX_SPLINE_Y = 5.0Shipping-Build Zero-Regression Check (No Animated Icon on Screen)
Paired shipping builds of
anomalyco/rune-desktop(--profile release, fat LTO,features: [], ORPHANED PGO profile identical on both builds:x86_64-pc-windows-msvc.profdatatrained at appe54adc6c9ad0/ Rune78efd4a7) built on the farm viameasure-exe.tsand timed onblade(Intel(R) Iris(R) Xe Graphics, DX12, hidden desktop insidetools/quiet-window.ps1 -Kind timing,OPENCODE_RUNE_OTEL=0;proof/ws6/rune-1291-shipping-ab/summary.json):dev):e9b29cd06dcd(Runedc8f7f72,157,894,144B, sha256283160962421…)ws6/measure-rune-1291, measuring only):30bab666a7ca(ONLY Rune pin bumped totrain/1120sa7a0ab78=dc8f7f72+#1304+#1291bdf974ca,158,003,200B, sha256574d3e47c79a…)dev(dc8f7f72) median [min..max] (spread)dc8f7f72+#1291) median [min..max] (spread)prose, commit frame, Pass 2cand-first)1,294.0µs append (757.9µs empty)2,979.0[2,779.7..3,032.2] (252.6µs); pooled2,933.7µs2,999.8[2,771.1..3,072.4] (301.3µs); pooled2,915.6µs+20.8µs (−18.1µs pooled)prose, commit frame, Pooled Pass 1+2)1,264.3[1,234.6..1,294.0] µs append (777.1µs empty)2,917.9[2,726.5..3,032.2] (305.7µs); pooled2,890.4µs3,018.3[2,756.3..3,528.7] (772.4µs; Pass 1 r1–r3 E-core/clock step whereworkUsrose identically +35%)+100.4µs (ranges overlap)prose, motion frame, Pooled Pass 1+2)777.1µs empty1,249.4[1,102.9..1,394.5] (291.6µs)1,268.6[1,099.4..1,640.0] (540.6µs); Pass 2 pooled1,229.0vs1,230.1µs+19.2µs (−1.1µs Pass 2)code2k, first block frame)903.1[888.4..1,005.8] µs pre-block (cand858.8)17,476.1[17,166.1..20,831.6] (3,665.5µs)16,983.1[16,793.7..23,353.6] (6,559.9µs)−493.0µscode2k, settled scroll)903.1µs pre-block (cand858.8)3,129.5[2,700.3..4,444.6] (1,744.3µs)3,132.8[3,071.0..4,616.9] (1,545.9µs)+3.3µscode2k, streaming 0.8–2.8 s)903.1µs pre-block (cand858.8)3,186.9[2,955.4..3,511.8] (556.4µs)3,106.8[2,914.1..3,188.4] (274.3µs)−80.1µsGoal reached, 10 s settle + 5 s strobe)1present (base3,857.0µs,cand4,262.9µs); headless--at 2.0:0animating frames1present/5 s[1,1,1,1,1](0 extra over floor);3,703.8[3,362.5..4,822.2] (1,459.7µs)1present/5 s[1,1,1,1,1](0 extra over floor);3,549.6[3,395.9..3,739.8] (343.9µs)0frames (−154.2µs)(Both builds use the same ORPHANED PGO profile trained at Rune
78efd4a7, which accounts for the ~600 µs offset vs matched-PGO reference2,236.6 µson prose; GPUI's earlier ORPHANED baseline atef07741awas2,800 [2,720.1–2,925.2]µs.)Shipping-Build Measurement (
--release --features frame-profile,RUNE_FRAME_LOG, 1280×800 @ 1.5× Iris Xe Dx12 165 Hz)Idle window displaying 18 transcript rows + Goal pill (1 s warmup + 5 s steady window for
animated/two_icons/static/reduced, 2.5 s steady forspinner/slide; hidden desktop;proof/ws6/rune-1291-bench/{summary-v4,summary-v2,summary,official-summary}.json):loop_step/ Fallbackbuild_cpup50bdf974caAnimated (goal/icons/active.svg, 5 s)25×25, 0.027% of window)paint 0.0 µs,prebuild 47.7 µs)bdf974caTwo Same-Size Animated Icons (5 s)paint 0.0 µs,prebuild 26.7 µs)bdf974caIcon +a11y_hiddenCycleSpinner (2.5 s)paint 88.7 µs,prebuild 121.9 µs)bdf974caIcon +SlideShimmer (2.5 s)paint 91.1 µs)bdf974caStatic (goal/icons/complete.svg, 5 s)bdf974caAnimated + Reduced Motion (t = 0hold, 5 s)61a091d8Animated (earlier unthrottled head, 5 s)23×23, 0.023% of window)paint 128.1 µs)e51247f626Static Idle (Goal reached, 0 CSS / 0 SMIL)e51247f626SMIL-only Idle (active.svgswapped in, 0 CSS / 4 SMIL)+110.0%delta)e51247f626Following goalFull (26 CSS + 4 SMIL)Stage breakdown (
61a091d8→bdf974ca, common idle case p50 µs):61a091d8(1,505.0 µs):submit_cpu 824.9(54.8%) +present_cpu 292.8(19.5%) +build_cpu 168.2(paint 128.1, 11.2%) +encode_cpu 133.7(8.9%) +acquire_cpu 21.1(1.4%) +upload 19.5(1.3%) +prebuild 3.2(0.2%).bdf974ca(728.5 µs):submit_cpu 443.5+present_cpu 157.5+encode_cpu 52.5+prebuild 47.7+acquire_cpu 17.5+upload 9.7+build_cpu 0.5(paint 0.0). Total idle CPU is 1.64% of 1 core (10.9× lower than61a091d8, 92.2× lower than Official Electron SMIL-only idle), with 0 fallback frames in the 5 s window (108/108loop_step). Visual cadence equivalence across the full 2.4 sactive.svgcycle is inproof/ws6/rune-1291-bench/goal-pulse-30hz-vs-exact.png.Finding-by-Finding Resolution (
notes/review-1291.mdInitial + Delta Reads at61a091d8&676852e5)usvgUI-thread stack overflow,<filter>/<use>DoS, transposedmatrix(), duplicate attrs, missingxmlns:xlink, colour reduced-motion bugcolor_iconand log once in debug builds if SMIL tags are present.crates/rune-text/src/icon/color.rs:136-153d/points, opacity layers (<g opacity="0.5">OOM)MAX_SVG_BYTES,MAX_DEPTH,MAX_ELEMENTS,MAX_SHAPES,MAX_LAYERS,MAX_PATH_BYTES,MAX_PATH_COMMANDS,MAX_POINTS_NUMBERS).crates/rune-text/src/icon/anim/parse.rs:13-34,201-334,359-412Vecallocation invalues/keyTimes/keySplines/parse_key_val,values=";;;;...",keyTimesoutside[0,1]/NaNparse_small_numbers<N>(zero heap alloc); semicolon count bounded againstMAX_KEYFRAMES + 1before allocating;keyTimesstrictly validated in[0, 1], monotonic,t[0] == 0,t[last] == 1for linear/spline;keySplinesy1/y2clamped to[-4, 5].crates/rune-text/src/icon/anim/parse.rs:582-620,721-838,956-98461a091d8):<path d>coords (1e30) & composedctm(64^8,64^128) reachedconvex/raster.rs(i64overflow debug panic) andarea.rsunclamped; rejected animated SVGs fell back to unbounded staticicon_coverage_at<path d>coords<= MAX_COORDat compile time (parse.rs); addedlocal_ctm_is_safeafter every transform op andctm_is_safeafter every group/shape composition (icon.rs,anim/mod.rs,area.rs+res <= 256.0); widenedconvex/raster.rsedge()toi128withMAX_DEV_COORD = 32_768.0guard; bounded staticicon_coverage_at(256 KiB,1024elements,64depth,128 KiBpath,MAX_LAYERS = 8) and returned empty coverage on hostile rejection.crates/rune-text/src/icon.rs:237-349,crates/rune-text/src/icon/area.rs:288-297,crates/rune-text/src/icon/convex/raster.rs:51-106,crates/rune-text/src/icon/anim/parse.rs:384-416,955-1002,crates/rune-text/src/icon/anim/mod.rs:373-387,477-516<animate>inside<defs>/<script>/ comments with>activating animation; single-quoted attrs ignoredXmlScannerskipping XML comments properly, supporting single and double quotes, rejecting DTD/CDATA, and skippingNON_RENDERINGsubtrees.crates/rune-text/src/icon/anim/parse.rs:37-40,236-241,1100-1205Plan::All("image")),ImageAtlasslot thrash, per-framePlanclone and XML re-parseCompiledAnimevaluated with reusable scratch buffers into double-buffered(px+2)×(px+2)glyph-atlas tiles (KIND_GLYPH), GPU-tinted byfill, flipping UV only when quantized pixels change.crates/rune-text/src/atlas.rs:518-599,crates/rune-text/src/icon/anim/mod.rs:230-495,crates/rune/src/runtime/paint/content.rs:190-209,896-97561a091d8):AtlasPage::newresetepoch: 1, colliding with staleSlotEntryhandles after overflowpages.pop()+ recreateAtlas::next_page_gencounter (alloc_page_gen) used by bothevict_pageand newly pushedAtlasPage::new.crates/rune-text/src/atlas.rs:142-150,226-229,315,342-366,470-47261a091d8): Unthrottled 124–180 fpsMovingburning ~18% idle core + 67 empty[0,0,1,1]presents in 5 sAnimState::MovingviaWaitingUntilat ≤ 30 Hz (ICON_ANIM_STEP = 1/30) with forward pixel-change probing (MAX_PIXEL_PROBES = 12) + hold-window cache hit; wired icon-only wakes intoloop_step/arm_loop; leftstate.looped = Noneon emptypatchedsois_unchanged()skips empty presents (0empty presents,108/108loop_step,1.64%core).crates/rune-text/src/icon/anim/mod.rs:32-39,230-303,crates/rune/src/runtime/paint/cycle.rs:147-218,280-329,crates/rune/src/runtime/paint/content.rs:956-972,crates/rune/src/runtime/frame/motion.rs:31-38,139,crates/rune/src/window/host/draw.rs:390-395,485-489SWAP.read()RwLock+ second SipHash lookupFxHashMapIconKindlookup replacesis_color_icon;SWAP_ACTIVEAtomicBoolfast path removesSWAP.read()when no swap is installed;cache_layer.rsshort-circuits onhas_animated_icons().crates/rune-text/src/icon/color.rs:45-100,crates/rune-text/src/icon.rs:34,61-67,crates/rune/src/runtime/paint/cache_layer.rs:188-19961a091d8):El::cachefroze inline animated pill/bare icons (n.textt.cold.pills)cache_layer.rsliveness check (gated byself.text.has_animated_icons()) to check `n.text.as_ref().is_some_and(<set>withoutdurspinning forever;live_visible/ Windows occlusion; finite mount time; live reduced-motion ON → OFF<set>with omitted/indefinitedursteps once atbeginthen returnsAnimState::Finished;paint_animated_iconchecksalpha > 1/255,live_visible, and wiresanimated_icons_shownintoloops_shown(); finite icons track(NodeId, icon_ptr)mount time;AccessibilityLink::receivewakes oninbox.settings.crates/rune-text/src/icon/anim/mod.rs:640-655,crates/rune/src/runtime/paint/content.rs:916-955,crates/rune/src/runtime/frame/motion.rs:16-19,crates/rune/src/a11y/mod.rs:173-18161a091d8): SMIL faults (resolve_transformadditive="replace", negativeby/sumclamp,by-onlyscale, inherited<g>paint,--5sdouble-sign clocks)parse.rsandanim/mod.rs.crates/rune-text/src/icon/anim/parse.rs:425-445,630-820,885-935,crates/rune-text/src/icon/anim/mod.rs:500-700676852e5):Atlas::slot_dirtyhorizontal-shelf aliasing froze a second same-size animated icon and dropped frames when text rasterized onto the same shelfAtlas::slot_dirtywith monotonicAtlas::upload_genincremented inAtlas::rows_uploaded, compared perSlotEntryviapending_upload(upload_gen)(including keeping un-uploaded slots reported aschanged: trueacross missed drawables onstill_waiting/last_cov == scratch_covsowrite_patchednever panics or drops updates).crates/rune-text/src/atlas.rs:229-232,320,crates/rune-text/src/atlas/fill.rs:126-127,crates/rune-text/src/icon/anim/mod.rs:97-111,339,358-390,454-484676852e5):loop_stepcalledAtlas::put_borderedlazily and could evict a live glyph page without rebuildingself.instances(plusShelf::live_texelsaccumulated monotonically duringloop_step)frame_quad) and touched both valid slots on full paint (touch_entry_slots). IntroducedAtlas::in_place() -> InPlaceAtlas<'_>exposing onlypage_gen,upload_gen, and pixel-onlywrite_bordered(noalloc,place,put_bordered,evict_page, ortouchmethods), soframe_quad_in_place/loop_stepis unable by construction to allocate in or evict from the glyph atlas or inflatelive_texels. Guardedloop_stepwithicon_slots_ready()to fall back to an ordinary frame whenever any slot is absent or evicted.crates/rune-text/src/atlas.rs:518-599,crates/rune-text/src/icon/anim/mod.rs:207-224,398-498,crates/rune-text/src/lib.rs:732-781,crates/rune/src/runtime/paint/cycle.rs:178,280-283,301676852e5): Webpaint_cycle_tickfroze animated icons beside aCyclespinner|| !keep.icons.is_empty()topaint_cycle_tickso Web falls back to an ordinary frame whenever animated icons are present.crates/rune/src/runtime/paint/cycle.rs:127676852e5): Overdueloop_wakeleft stuck beside a non-ambientSlidelooploop_stepto take the icon fast path only when noLoopSpec(Cycle/Slide) is active (has_icons && !self.motion.loops_is_empty()falls back to an ordinary frame, wherebuild()clears and re-arms wakes cleanly), leaving existingCycle/Slideloop_stepcode untouched and makingsample_icon_slotsunconditionally clearloop_wakebefore armingnext_wake.crates/rune/src/runtime/paint/cycle.rs:153-218,324-329676852e5):icon.rs:291blanked benign monochrome icons whose only<animate>targeted an unsupported attributecompile()intoCompileOutcome::{Animated, StaticOnly, Rejected}andrender_rest_coverage()intoRestCoverage::{Rendered, StaticFallback, Rejected}so benign icons within all caps draw static while hostile/cap-violating SVGs still return empty coverage.crates/rune-text/src/icon/anim/parse.rs:199-216,359-366,crates/rune-text/src/icon/anim/mod.rs:76-84,184-201,crates/rune-text/src/icon.rs:291-297,crates/rune-text/src/icon/color.rs:148-151Checks
0test files modified,0#[test]/#[cfg(test)]/#[ignore]attributes added/edited,0unsafe.train/1120s(a7a0ab78,#1304+#1291bdf974caondevdc8f7f72): Windows RTX whole suite 3,106 passed / 0 failed / 0 new (42 binaries, all 11 crates), Mac whole suite 3,323 passed / 0 failed / 0 new, 4-target check (native / wasm32 / Apple / Linux) all clean.--release --features frame-profile,proof/ws6/rune-1291-bench/checks-v4.txt):UNSUPPORTED_ATTR_STATIC_OK,TWO_ICONS_SAME_SHELF_OK,ATLAS_PRESSURE_GPU_READBACK_OK(5 pages, 6 evictions,text_diff_px=0),SPINNER_BESIDE_ICON_OK,SLIDE_BESIDE_ICON_OK,ALL_CHECKS_PASSED elapsed_ms=2395.9.proof/ws6/rune-1291-bench/summary-v4.json) and paired no-animated-icon zero-regression A/B (proof/ws6/rune-1291-shipping-ab/summary.json).