| 6 | Date: 2026-10-09. Question: can the system WebView be replaced with a native |
| 7 | HTML/CSS engine for rendering speed in the message list without lowering the |
| 8 | widgets' CSS profile (as litehtml would). The candidate is [Blitz](https://github.com/DioxusLabs/blitz) |
| 9 | (Rust: stylo from Servo + taffy + parley + vello), commit `971f1a3` of 2026-10-09, |
| 10 | version `0.3.0-beta.2`. Blitz does not execute JS, so this is a test of the |
| 11 | renderer only: JS and the DOM stay in our sandbox, and what goes out is the same |
| 12 | validated DOM. |
| 13 |
| 14 | ## Method |
| 15 |
| 16 | 1. `scripts/blitz-experiment/dump-dom.mts` opens each of the 40 widgets in |
| 17 | `corpus/generated` in the dev UI's reference mode (native Chromium, the same |
| 18 | frame that `pnpm test:generated` screenshots): load, 800 ms, clicks on the |
| 19 | first four buttons, 500 ms. At that moment the reference PNG is taken |
| 20 | (404 px wide, dpr 1) and the DOM is serialised after the scripts have run: |
| 21 | `<canvas>` is replaced by its bitmap (with Blitz our command stream would be |
| 22 | drawing the canvas anyway), form state is written into attributes, `<script>`/`<link>` |
| 23 | are removed, non-`data:` `src` attributes are stripped (CSP blocks them in Chromium), `:hover` and |
| 24 | `:focus` are removed on both sides. |
| 25 | 2. `scripts/blitz-experiment/twidget_render.rs` (an example inside the Blitz |
| 26 | checkout) lays this HTML out headless at the same width, in two passes |
| 27 | like the iframe in the dev UI (first a 24 px viewport, then the document height, so that |
| 28 | `100vh` does not inflate the page), and rasterises it through `vello_cpu` into a PNG. |
| 29 | `TW_SHARED_FONTS=1` builds the `FontContext` once per process, as the host |
| 30 | would. |
| 31 | 3. `scripts/blitz-experiment/compare.mts` compares the PNGs with the same `pixelmatch` |
| 32 | and the same thresholds as `tests/generated.spec.ts` (threshold 0.15, AA |
| 33 | on, pass threshold 3%), and writes the table below. Output PNGs and |
| 34 | diff images: `reports/blitz-experiment/` (gitignored, wiped by |
| 35 | `tests/global-setup.ts` on the next Playwright run). |
| 36 |
| 37 | Machine: Apple Silicon, release build, CPU rasterisation at 1× scale. |
| 38 |
| 39 | ## Result |
| 40 |
| 41 | ## with-profile: Blitz 0 / 20 within 3% (sandbox WebKit/Chromium path: 20 / 20) |
| 42 |
| 43 | | Widget | Blitz diff | Sandbox diff | Blitz parse / layout / paint (ms) | Height Blitz / ref | Clicks | canvas / svg / inputs | Error | |
| 44 | |---|---|---|---|---|---|---|---| |
| 45 | | 01-show-me-a-mortgage-calculator-loan-amount.html | 25.73% ❌ | 0.00% | 1 / 1 / 11 | 368 / 404 | 1 | 0 / 0 / 3 | | |
| 46 | | 02-make-an-interactive-quiz-about-the-solar.html | 8.10% ❌ | 0.00% | 1 / 1 / 2 | 388 / 388 | 4 | 0 / 0 / 0 | | |
| 47 | | 03-visualize-this-weekly-budget-as-a-chart.html | 8.56% ❌ | 0.00% | 1 / 1 / 11 | 348 / 353 | 0 | 1 / 0 / 0 | | |
| 48 | | 04-build-a-tip-calculator-with-a-slider-for.html | 17.72% ❌ | 0.00% | 1 / 1 / 2 | 416 / 436 | 3 | 0 / 0 / 2 | | |
| 49 | | 05-create-a-pomodoro-timer-with-start-pause.html | 20.99% ❌ | 0.00% | 1 / 1 / 11 | 362 / 360 | 4 | 0 / 1 / 0 | | |
| 50 | | 06-show-a-comparison-table-of-three-laptops.html | 14.32% ❌ | 0.00% | 1 / 1 / 2 | 269 / 284 | 3 | 0 / 0 / 0 | | |
| 51 | | 07-make-a-bmi-calculator-with-metric-and.html | 13.95% ❌ | 0.00% | 0 / 1 / 2 | 335 / 369 | 2 | 0 / 0 / 5 | | |
| 52 | | 08-draw-a-line-chart-of-monthly-temperatures.html | 22.64% ❌ | 0.00% | 1 / 4 / 2 | 350 / 355 | 0 | 0 / 1 / 0 | | |
| 53 | | 09-create-a-unit-converter-for-length-weight.html | 8.67% ❌ | 0.00% | 1 / 1 / 1 | 221 / 270 | 4 | 0 / 0 / 4 | | |
| 54 | | 10-show-me-an-interactive-multiplication.html | 11.60% ❌ | 0.00% | 1 / 2 / 3 | 417 / 400 | 0 | 0 / 0 / 0 | | |
| 55 | | 11-make-a-to-do-list-widget-where-i-can-add.html | 5.81% ❌ | 0.00% | 0 / 0 / 1 | 187 / 182 | 4 | 0 / 0 / 2 | | |
| 56 | | 12-create-a-countdown-to-new-year-with-days.html | 10.83% ❌ | 0.24% | 1 / 1 / 2 | 179 / 183 | 0 | 0 / 0 / 0 | | |
| 57 | | 13-visualize-a-simple-project-timeline-gantt.html | 11.45% ❌ | 0.00% | 1 / 1 / 3 | 350 / 355 | 4 | 0 / 0 / 0 | | |
| 58 | | 14-build-a-color-palette-generator-pick-a.html | 7.30% ❌ | 0.00% | 1 / 1 / 5 | 288 / 292 | 4 | 0 / 0 / 2 | | |
| 59 | | 15-create-a-flashcard-widget-for-8-spanish.html | 55.68% ❌ | 0.00% | 0 / 0 / 2 | 305 / 310 | 3 | 0 / 0 / 0 | | |
| 60 | | 16-make-a-bar-chart-of-the-top-6-programming.html | 12.94% ❌ | 0.00% | 1 / 0 / 2 | 369 / 374 | 0 | 1 / 0 / 0 | | |
| 61 | | 17-show-a-tic-tac-toe-game-against-a-simple.html | 5.27% ❌ | 0.34% | 0 / 0 / 2 | 457 / 462 | 4 | 0 / 0 / 0 | | |
| 62 | | 18-create-a-currency-converter-for-usd-eur.html | 7.74% ❌ | 0.00% | 0 / 0 / 1 | 227 / 249 | 1 | 0 / 0 / 7 | | |
| 63 | | 19-make-a-step-by-step-recipe-card-for.html | 13.90% ❌ | 0.00% | 0 / 1 / 3 | 834 / 805 | 4 | 0 / 0 / 7 | | |
| 64 | | 20-build-a-habit-tracker-grid-for-one-month.html | 6.32% ❌ | 0.00% | 1 / 1 / 3 | 445 / 448 | 4 | 0 / 0 / 0 | | |
| 65 |
| 66 | ## without-profile: Blitz 0 / 20 within 3% (sandbox WebKit/Chromium path: 20 / 20) |
| 67 |
| 68 | | Widget | Blitz diff | Sandbox diff | Blitz parse / layout / paint (ms) | Height Blitz / ref | Clicks | canvas / svg / inputs | Error | |
| 69 | |---|---|---|---|---|---|---|---| |
| 70 | | 01-show-me-a-mortgage-calculator-loan-amount.html | 9.22% ❌ | 0.00% | 0 / 0 / 2 | 396 / 425 | 0 | 0 / 0 / 3 | | |
| 71 | | 02-make-an-interactive-quiz-about-the-solar.html | 35.35% ❌ | 0.00% | 0 / 0 / 2 | 568 / 900 | 4 | 0 / 0 / 0 | | |
| 72 | | 03-visualize-this-weekly-budget-as-a-chart.html | 6.99% ❌ | 0.00% | 1 / 0 / 1 | 471 / 475 | 0 | 1 / 0 / 0 | | |
| 73 | | 04-build-a-tip-calculator-with-a-slider-for.html | 15.14% ❌ | 0.00% | 0 / 1 / 2 | 431 / 451 | 2 | 0 / 0 / 2 | | |
| 74 | | 05-create-a-pomodoro-timer-with-start-pause.html | 24.61% ❌ | 0.00% | 0 / 1 / 1 | 366 / 364 | 4 | 0 / 1 / 0 | | |
| 75 | | 06-show-a-comparison-table-of-three-laptops.html | 11.67% ❌ | 0.00% | 0 / 1 / 2 | 276 / 326 | 0 | 0 / 0 / 0 | | |
| 76 | | 07-make-a-bmi-calculator-with-metric-and.html | 13.16% ❌ | 0.00% | 0 / 1 / 2 | 353 / 386 | 2 | 0 / 0 / 5 | | |
| 77 | | 08-draw-a-line-chart-of-monthly-temperatures.html | 10.91% ❌ | 0.00% | 1 / 0 / 1 | 348 / 352 | 0 | 1 / 0 / 0 | | |
| 78 | | 09-create-a-unit-converter-for-length-weight.html | 6.42% ❌ | 0.00% | 0 / 0 / 2 | 276 / 324 | 4 | 0 / 0 / 4 | | |
| 79 | | 10-show-me-an-interactive-multiplication.html | 11.17% ❌ | 0.00% | 1 / 1 / 2 | 419 / 401 | 0 | 0 / 0 / 0 | | |
| 80 | | 11-make-a-to-do-list-widget-where-i-can-add.html | 5.71% ❌ | 0.00% | 1 / 1 / 2 | 330 / 315 | 4 | 0 / 0 / 4 | | |
| 81 | | 12-create-a-countdown-to-new-year-with-days.html | 14.67% ❌ | 0.74% | 1 / 1 / 2 | 195 / 203 | 0 | 0 / 0 / 0 | | |
| 82 | | 13-visualize-a-simple-project-timeline-gantt.html | 8.44% ❌ | 0.00% | 0 / 1 / 2 | 358 / 362 | 0 | 0 / 0 / 0 | | |
| 83 | | 14-build-a-color-palette-generator-pick-a.html | 14.64% ❌ | 0.00% | 0 / 0 / 2 | 217 / 230 | 0 | 0 / 0 / 2 | | |
| 84 | | 15-create-a-flashcard-widget-for-8-spanish.html | 49.67% ❌ | 0.00% | 1 / 1 / 3 | 325 / 329 | 2 | 0 / 0 / 0 | | |
| 85 | | 16-make-a-bar-chart-of-the-top-6-programming.html | 11.44% ❌ | 0.00% | 1 / 0 / 1 | 367 / 371 | 0 | 1 / 0 / 0 | | |
| 86 | | 17-show-a-tic-tac-toe-game-against-a-simple.html | 4.14% ❌ | 0.00% | 0 / 0 / 2 | 469 / 472 | 1 | 0 / 0 / 0 | | |
| 87 | | 18-create-a-currency-converter-for-usd-eur.html | 6.13% ❌ | 0.00% | 0 / 1 / 2 | 281 / 302 | 1 | 0 / 0 / 7 | | |
| 88 | | 19-make-a-step-by-step-recipe-card-for.html | 24.36% ❌ | 0.00% | 1 / 14 / 4 | 900 / 900 | 4 | 0 / 0 / 7 | | |
| 89 | | 20-build-a-habit-tracker-grid-for-one-month.html | 4.32% ❌ | 0.00% | 0 / 1 / 2 | 411 / 416 | 0 | 0 / 0 / 0 | | |
| 90 |
| 91 | Medians over 40 rendered widgets: Blitz diff 11.45%, sandbox diff 0.00%; Blitz parse 0.5 ms, layout 0.6 ms, paint 2.0 ms, first document in the process (one-time init included) 9 ms, whole process 72 ms. |
| 92 |
| 93 | For comparison: our "sandbox → WebKit/Chromium" path gives 40/40 within |
| 94 | 3% (`docs/compat-report-generated.md`). Blitz: 0/40 within 3%, 16/40 within |
| 95 | 10%, 30/40 within 15%; quartiles 7.7 / 11.4 / 15.1%, maximum |
| 96 | 55.7%. |
| 97 |
| 98 | ## Where the differences come from |
| 99 |
| 100 | Breakdown from the dumps and by eye (images in `reports/blitz-experiment/`): |
| 101 |
| 102 | | Cause | Widgets | Diff | Status in Blitz | |
| 103 | |---|---|---|---| |
| 104 | | 3D transform (`rotateY` + `backface-visibility`, card flip) | 15 in both batches | 50–56% | 2D transforms only; the back of the card is visible | |
| 105 | | Inline SVG styled through CSS (`fill: none`, `stroke` in `<style>`) | 05 (timer ring), 08 with-profile (line chart) | 21–25% | the SVG is drawn, but CSS properties are not applied to it: outlines are filled black | |
| 106 | | Forms: the `<input>` value is not drawn, `range` has no thumb, `<select>` is empty, `<input type=color>` is a circle, checkboxes are larger | 01, 04, 07, 14, 18, 19 | 13–26% | forms are declared as a goal, partially implemented | |
| 107 | | `min-height: 100vh` on `body` | 02, 12 without-profile | 15–35% | an artefact of the reference: the dev-UI iframe adapts to the document height, `100vh` grows with it up to the 900 px ceiling; Blitz converges to a smaller height | |
| 108 | | Emoji with the VS16 selector (`⏱️`, `🍳`) | 19 | part of the diff | tofu; ordinary colour emoji (`🏠`, `💰`) are drawn | |
| 109 | | The rest: the same `.SF NS`, a different rasteriser and text metrics, occasionally a different line break | all | 4–12% | the "floor" of the comparison; `pixelmatch` at 3% does not forgive it, by eye the cards are indistinguishable | |
| 110 |
| 111 | Grid, flex, `var(--…)`, `calc()`, `box-shadow`, gradients, `border-radius`, |
| 112 | `opacity`, tables, `position` — everything litehtml lacks, Blitz has, and it |
| 113 | matches Chromium down to the text. Not a single widget crashed or |
| 114 | hung. |
| 115 |
| 116 | ## Speed |
| 117 |
| 118 | Per document (median / p90 over 40 widgets, `TW_SHARED_FONTS=1`): |
| 119 |
| 120 | | Stage | Median | p90 | Maximum | |
| 121 | |---|---|---|---| |
| 122 | | HTML + CSS parsing | 0.5 ms | — | 0.8 ms | |
| 123 | | Styles + layout (both passes) | 0.6 ms | — | 14 ms (39 of 40); outlier 160–190 ms, see below | |
| 124 | | Rasterisation of 404 px on the CPU, 1× | 2.0 ms | — | 11 ms | |
| 125 | | Total | 3 ms | 12 ms | — | |
| 126 |
| 127 | The outlier: `without-profile/19` (the recipe card) consistently takes 160–190 ms |
| 128 | to lay out against 1 ms for its twin from `with-profile`. The cause was not found; |
| 129 | the suspicion is fallback-font lookup for the VS16 emoji sequences, which in this |
| 130 | same widget are drawn as tofu. Such pathologies in a beta engine are expected, and |
| 131 | in the product they would have to be caught with a layout timeout. |
| 132 |
| 133 | One-time per process: scanning the system fonts ≈ 40 ms. Without a shared |
| 134 | `FontContext` Blitz repeats it for every document (38 ms even on |
| 135 | `<p>hi</p>`): the host must create the font context once. |
| 136 |
| 137 | Not measured: JS execution and applying the diffs (they stay as they are), |
| 138 | rasterisation at 3× (9 times the pixels, expected 10–20 ms on the CPU, or the |
| 139 | `vello` GPU backend), the cost of incremental re-layout on updates, |
| 140 | memory per document. |
| 141 |
| 142 | ## The same check for litehtml |
| 143 |
| 144 | Added on the evening of 2026-10-09 with the same pipeline: `scripts/blitz-experiment/twidget_litehtml.cpp` |
| 145 | (litehtml master `4a651c5` of 2026-10-08 with the `containers/cairo` container |
| 146 | from the repository itself, cairo + pango from Homebrew, no GTK; `data:` PNGs |
| 147 | are decoded into cairo surfaces, `-apple-system`/`sans-serif` mapped to SF Pro Text through |
| 148 | `scripts/blitz-experiment/fonts.conf`, as in Chromium). |
| 149 | Three columns and diff maps: `reports/blitz-experiment/gallery.html` |
| 150 | (`scripts/blitz-experiment/gallery.mts`), the numbers are in `metrics.json` next to it. |
| 151 |
| 152 | | | Blitz | litehtml | |
| 153 | |---|---|---| |
| 154 | | Rendered without crashing | 40 / 40 | 40 / 40 (after fixing the destruction order of the document and the container in my harness) | |
| 155 | | strict-diff, median (the test's metric) | 11.4% | 12.5% | |
| 156 | | soft+shift, median (threshold 0.3, no AA, shift ±2 px) | 5.4% | 7.1% | |
| 157 | | Parsing + layout + rasterisation, median | 3 ms | 44 ms (layout runs inside `createFromString` and is not measured separately; `<p>hi</p>` is 5.5 ms, the rest is creating pango fonts through fontconfig for every font description) | |
| 158 |
| 159 | What today's litehtml can do beyond its documented profile: |
| 160 | `var(--…)` and `calc()` are implemented (the mortgage calculator with 10 variables, |
| 161 | the laptop table, the chart legend match Chromium down to the |
| 162 | text). What is still missing, and how it looks in the gallery: |
| 163 |
| 164 | | Gap | Widgets | How it looks | |
| 165 | |---|---|---| |
| 166 | | `display: grid` | 13 (gantt), 14 (palette), 20 (habit tracker), 12 without-profile (countdown) | the grid collapses into a single column: the tracker's 31 days in one column, the countdown cards one under another; the document height is 1.5–2 times the reference | |
| 167 | | Inline `<svg>` | 05 (timer ring), 08 with-profile (line chart) | the SVG is not drawn at all: no ring, the chart collapsed into a row of axis labels | |
| 168 | | `transform`, `box-shadow`, `opacity`, `transition` | 15 (card flip) and everywhere there are shadows | the same result as Blitz for 3D, the rest are flat cards without shadows | |
| 169 | | Forms | 01, 04, 07, 14 | as with Blitz: the `<input>` value is not drawn, no thumb, `<select>` is empty | |
| 170 |
| 171 | The main lesson about the metric: by strict-diff litehtml looks almost like Blitz |
| 172 | (12.5% against 11.4%), although by eye the difference is gross. A missing ring or |
| 173 | chart costs few pixels, a collapsed grid costs many, and the "floor" from text is |
| 174 | the same. The pixel percentage against Chromium is not a measure of a native |
| 175 | renderer's accuracy; the gallery is what to look at. The conclusion on litehtml |
| 176 | does not change: without grid, SVG, transforms and shadows |
| 177 | it is a different widget profile, not a renderer replacement; in this corpus |
| 178 | 17 of 40 use grid. |
| 179 |
| 180 | ## Conclusion |
| 181 |
| 182 | - Blitz is the only open engine that holds the CSS profile of LLM widgets |
| 183 | (grid/var/calc/shadow/opacity) and still lays out a card in single-digit |
| 184 | milliseconds without a WebContent process. For a "preview in the bubble" it is a |
| 185 | working option already: a static card from the validated DOM. |
| 186 | - Not yet for a live widget: no 3D transforms, CSS does not reach SVG, forms |
| 187 | without values and thumbs, no canvas (we would have to put our command stream onto |
| 188 | vello ourselves), no `overflow: auto`, beta status. These are three concrete gaps with |
| 189 | known code, not "months of our own engine" as in the litehtml case. |
| 190 | - A 3% pixel threshold against Chromium is unattainable in principle for a native rasteriser |
| 191 | (different text); such a renderer needs a different acceptance |
| 192 | criterion (a structural diff or a comparison with a threshold of ~10%). |
| 193 | - Stack: Rust in iOS/Android/tdesktop. Acceptable for tdesktop; for the mobile |
| 194 | ports it is a new build dependency, ask before pulling it in. |
| 195 |
| 196 | Next step, if we go further: run `corpus/compat` (22 real |
| 197 | widgets, Chart.js/D3/Tailwind) through the same pipeline and measure 3× rasterisation |
| 198 | on the GPU backend. |
| 199 |
| 200 | ## PaintScene on CoreGraphics: Blitz layout, platform pixels (2026-10-10) |
| 201 |
| 202 | Question: can we keep stylo + taffy + parley (cascade, layout, shaping) |
| 203 | and hand painting to the platform, as our litehtml port does through a display |
| 204 | list, so that text and emoji are the system's. The seam exists: blitz-paint does not draw |
| 205 | itself but calls the `anyrender::PaintScene` trait (`fill`, `stroke`, `draw_glyphs`, |
| 206 | `draw_box_shadow`, `push_layer`/`push_clip_layer`, images through a brush). |
| 207 | `vello_cpu` is one of its backends. The second one is now ours: |
| 208 | `apps/renderer-blitz/src/cg.rs` (Apple only, raw FFI to CoreGraphics/CoreText, |
| 209 | no new crates; skrifa moved from the dev-dependencies to a regular one for reading the font |
| 210 | name and axes). |
| 211 |
| 212 | What the backend does: a `CGBitmapContextCreate` context over the same |
| 213 | RGBA buffer that vello returns, the CTM flipped to y-down; paths → `CGPath`; |
| 214 | fills and strokes → CG; layers with alpha and blend → `CGContextBeginTransparencyLayer`; |
| 215 | linear and radial gradients → `CGGradient`, conic ones as 96 flat |
| 216 | sectors; images → `CGImage` from the blob (cached by id); the box shadow is the analytic |
| 217 | Gaussian blur of a rounded rectangle (the same formula as vello's) into an |
| 218 | image. Glyphs: `CTFontDrawGlyphs` with parley's glyph ids and positions, the font |
| 219 | opened **from the same bytes** parley shaped with (`CTFontManagerCreateFontDescriptorsFromData`), |
| 220 | variable axes (SF weight) through `kCTFontVariationAttribute` from parley's normalised |
| 221 | coordinates. Gradient text takes the colour of the first stop; CSS filters and |
| 222 | `Extend::Repeat`/`Reflect` on gradients are not supported (drawn once). |
| 223 |
| 224 | Switching: `TWB_BACKEND=cg` in the process environment or `twb_set_backend(h, "cg")` |
| 225 | (`twb_backend(h)` answers with the name). Everything else is the same crate, the same C ABI, |
| 226 | the same Swift glue: the iOS/macOS demos and `twidget-run` know nothing about the |
| 227 | backend. |
| 228 |
| 229 | Pitfalls along the way: CoreText refuses to draw with a mirrored text |
| 230 | matrix (zero pixels, silently) — for glyph runs the CTM is flipped back |
| 231 | to y-up and the baselines are taken negated; hidden system fonts |
| 232 | cannot be created by name (`.SFNS-Regular` gives Times), and descriptors from the bytes |
| 233 | of variable SF enumerate all 369 named instances, Ultralight first — the |
| 234 | face is picked by its PostScript name, which skrifa reads from the default |
| 235 | instance. |
| 236 |
| 237 | ### Result (`twidget-run --corpus … --blitz --dpr 2 --png-dir`, 400 CSS px, Apple Silicon) |
| 238 |
| 239 | | | vello (CPU) | CoreGraphics | litehtml | |
| 240 | |---|---|---|---| |
| 241 | | generated/with-profile, 20 widgets: paint median / p90 / max | 3.9 / 7.1 / 9.3 ms | 1.6 / 7.1 / 9.2 ms | 1.7 / 3.1 / 7.5 ms | |
| 242 | | compat, 21 widgets: paint median / p90 / max | 1.6 / 3.2 / 4.1 ms | 1.3 / 5.7 / 10.7 ms | 0.8 / 2.2 / 6.6 ms | |
| 243 | | strict-diff against vello, generated: median / p90 | — | 0.5% / 1.6% | 21.9% / 59% | |
| 244 | | strict-diff against vello, compat: median / p90 | — | 0.4% / 1.1% | 7.4% / 72% | |
| 245 |
| 246 | All 41 loaded and rendered on all three; CoreGraphics is no slower than |
| 247 | vello on the CPU at 2×. The CG-vs-vello diff is a fraction of a percent: the geometry matches |
| 248 | to the pixel, only the text differs. A gallery with 2× zoom and 1:1 strips |
| 249 | (`scripts/blitz-experiment/gallery-native.mts`, `magnify.mts`): |
| 250 | `reports/blitz-experiment/native/{generated,compat}/gallery.html`. |
| 251 |
| 252 | By eye on SF at 2×: vello and CoreText rasterisation are indistinguishable (the same |
| 253 | face, the same glyph ids, the same positions; weight through the axes works — |
| 254 | `font-weight:700` covers more pixels, test `coregraphics_backend_paints_text_and_emoji`). |
| 255 | So on macOS/iOS with Retina the "nativeness" of Blitz's text was never held back by the |
| 256 | rasteriser, but by the emoji fonts. |
| 257 |
| 258 | Emoji: |
| 259 |
| 260 | - ordinary colour ones (`🏠`, `🥞`, `🔥`) are drawn in both (on macOS vello |
| 261 | reads the PNG strikes); |
| 262 | - **VS16 sequences (`⏱️`, `🍽️`) remain tofu in both Blitz backends, |
| 263 | while litehtml through CoreText draws them.** This is not rasterisation but font |
| 264 | selection in parley/fontique: the run gets a face without these glyphs, and CoreText |
| 265 | faithfully draws `.notdef`. To be fixed in shaping (fallback to the emoji family for |
| 266 | sequences); the backend has nothing to do with it; |
| 267 | - the iOS emoji font (`emjc` strikes, which skrifa does not decode): CoreText on |
| 268 | macOS draws outline glyphs from the same `.ttc`, but not the `emjc` bitmaps |
| 269 | (`🪐` — 0 px in both backends, test `emoji_is_painted_with_the_ios_font` |
| 270 | stays ignored); this cannot be checked on a Mac. On iOS itself CoreText draws |
| 271 | its own font: **verified on the iPhone 17 simulator (iOS 26.5)** — |
| 272 | `SIMCTL_CHILD_TWB_BACKEND=cg xcrun simctl launch booted org.telegram.widgetsandbox.TwidgetDemo --blitz`, |
| 273 | widget 01 (the mortgage calculator): `🏠` is drawn, the same launch without the |
| 274 | variable (vello) — an empty space (`reports/blitz-experiment/native/ios-blitz-{cg,vello}.png`). |
| 275 | This is the closed "emoji on iOS" gap from the table above. |
| 276 |
| 277 | ### Conclusion |
| 278 |
| 279 | Yes, "litehtml with a wide profile" works out: layout and cascade from Blitz |
| 280 | (grid, shadows, transforms, incremental updates), pixels and fonts from the |
| 281 | platform, and the price is a primitive executor per platform, exactly |
| 282 | like the one already written for the litehtml display list (Apple ≈ 900 lines of |
| 283 | Rust here). The Android variant is the same `PaintScene`, but through a display list over |
| 284 | JNI to `Canvas`, like `LitehtmlRenderer.kt`; tdesktop — QPainter. This step does not touch the other |
| 285 | Blitz gaps: `<canvas>` is empty, controls are drawn, not native |
| 286 | (`custom-widget` is the next candidate), VS16 emoji are a question for parley. |
| 287 |
| 288 | ## Display list on the Android `Canvas`: the same seam, a second platform (2026-10-10) |
| 289 |
| 290 | The same question for Android, but without raw FFI to the platform: the crate gained a |
| 291 | third `anyrender` backend, `apps/renderer-blitz/src/dl.rs`, a platform- |
| 292 | neutral **recorder**: the blitz-paint scene is written into a compact binary |
| 293 | display list (format in the file header: layers, clips, fills and strokes with paths, |
| 294 | solid/linear/radial/sweep/image brushes, glyph runs with font id, face, |
| 295 | size, variation axes and positions, box shadow), and fonts and images are |
| 296 | handed out by blob id through a registry. It is checked by unit tests on the host and |
| 297 | suits any executor — QPainter in tdesktop would be next. |
| 298 |
| 299 | The executor on Android is `apps/android/renderer-blitz/.../CanvasScene.kt`: |
| 300 | it parses the stream once per frame into a list of commands with ready-made `Path`/`Paint`/ |
| 301 | `Matrix` and replays them in `onDraw` on the `View`'s own `Canvas` |
| 302 | (the hardware canvas, no Bitmap copy): `clipPath`/`saveLayer` with alpha and |
| 303 | `BlendMode`, `LinearGradient`/`RadialGradient`/`SweepGradient`/`BitmapShader`, |
| 304 | `DashPathEffect`, `BlurMaskFilter` for the shadow (σ → radius recomputed with Skia's |
| 305 | formula) and **`Canvas.drawGlyphs` (API 31+) with a `Font` assembled from the same bytes |
| 306 | parley shaped with** (`Font.Builder(ByteBuffer)` + `setTtcIndex` + |
| 307 | `setFontVariationSettings`): the buffer is a direct `ByteBuffer` over fontique |
| 308 | memory that Rust keeps alive for the whole process (`BlitzNative.fontBytes`), |
| 309 | images are `imagePixels` as premultiplied RGBA8 in a `Bitmap`. JNI: |
| 310 | `setBackend`, `displayList`, `fontBytes`, `imagePixels`. In the demo there is a fourth |
| 311 | item in the picker, **Blitz·Canvas** (`--es renderer blitz_canvas`, |
| 312 | `BlitzRenderer.canvasFactory`); the `blitz-backend` and `blitz-paint` rows |
| 313 | (parse ms, number of operations, KB) in the panel. |
| 314 |
| 315 | Result on the emulator (AVD twidget-35, API 35, 3×; timing numbers on the |
| 316 | emulator are indicative only as orders of magnitude): |
| 317 |
| 318 | - generated/01 (the mortgage calculator): display list of 28 operations, 4 KB, |
| 319 | first-frame parse 10.7 ms (including font assembly), fractions of a ms afterwards; |
| 320 | the same frame with vello on the emulator's CPU — 64 ms of 945×951 px rasterisation. |
| 321 | - By eye: Roboto text through `drawGlyphs`, `🏠`, `🥞`, `🔥` in the system Noto |
| 322 | Color Emoji, gradients, rounded corners, control borders — as with vello. |
| 323 | On Android vello draws emoji too (Noto, not the Apple format), so |
| 324 | here the win of the native path is Skia's text rasterisation, not emoji. |
| 325 | - VS16 sequences (`⏱️`, `🍽️`) are tofu here too: face selection in |
| 326 | parley, the backend has nothing to do with it (see the CoreGraphics section). |
| 327 |
| 328 | Executor gaps: a radial gradient is a single circle (Android has no |
| 329 | public two-point one), conic through `SweepGradient` with a rotation, |
| 330 | `Extend` on the image brush only `CLAMP`/`REPEAT`/`MIRROR` as in Skia, CSS |
| 331 | filters are ignored, gradient text takes the first stop, `<canvas>` |
| 332 | is still empty; before API 31 text is not drawn (no `drawGlyphs`), the module's minSdk |
| 333 | is 26. Screenshots: `reports/blitz-experiment/native/android-blitz-{canvas,vello}-{01,19}.png`. |
| 334 |
| 335 | ## Prototype in the demos (2026-10-09, evening) |
| 336 |
| 337 | (2026-10-10: litehtml is embedded in the same demos as a third renderer behind the same seam — |
| 338 | `docs/litehtml-renderer.md`.) |
| 339 |
| 340 | The same engine is embedded as a swappable renderer in the native demos: `apps/renderer-blitz/` |
| 341 | at the repository root is one Rust crate (`renderer.rs`: validated |
| 342 | `RenderOp`s → blitz-dom, layout queries, events through `EventDriver`, |
| 343 | `net.rs`: `data:` only, `text.rs`: `measureText` through parley) with two |
| 344 | bindings — JNI (`android.rs`, the `apps/android/renderer-blitz` module, Kotlin |
| 345 | `BlitzRenderer.kt`) and C ABI (`ffi.rs` + `include/twidget_blitz.h`, |
| 346 | `apps/ios/DemoApp/Sources/BlitzRenderer.swift` for UIKit and AppKit). The sandbox and |
| 347 | validator do not change: `WidgetHost` got a `Renderer` seam (`Renderer.kt`, |
| 348 | `Renderer.swift`) and a factory, the Rust side sees only validated ops and |
| 349 | `data:` images, it has no script and no network. Enabled with the **Blitz** toggle in the |
| 350 | demo (`--ez blitz true` on Android, `--blitz` on iOS/macOS, persisted across |
| 351 | launches), and works in the runners too: `--autorun generated --blitz`. |
| 352 |
| 353 | On the iPhone 17 simulator (3×): the calculator from `corpus/compat` is laid out and |
| 354 | drawn in 2–3 ms per frame (1080 × 1077 px, CPU), touches reach the widget's |
| 355 | handlers and come back through the same JSON contract, `size` drives the bubble |
| 356 | height, **Dark** switches `prefers-color-scheme`. The gaps are the same as in the |
| 357 | table above, plus an empty `<canvas>` (the command stream is not yet put onto vello). |
| 358 | Build: a pre-build phase of the Xcode project calls `apps/renderer-blitz/build-apple.sh` |
| 359 | (rustup cargo, targets `aarch64-apple-ios[-sim]` / `aarch64-apple-darwin`, |
| 360 | static library ≈ 39 MB before linking, first build 1–2 min). |
| 361 |
| 362 | ## Prototype in the C++ core `packages/desktop/` (2026-10-10) |
| 363 |
| 364 | The same crate is wired into the C++ core for tdesktop-class hosts: |
| 365 | `cmake -DTW_BLITZ=ON` calls rustup's `cargo` for the host triple and |
| 366 | links the static library through the C ABI (`include/twidget_blitz.h`, the |
| 367 | same one Swift uses). The core gained a `twidget/renderer.h` seam (`Renderer` + |
| 368 | `RendererFactory`, the twin of `Renderer.swift` / `Renderer.kt`) and `WidgetHost` |
| 369 | (`twidget/widget_host.h`: engine + validator + renderer, the fourth copy of |
| 370 | `WidgetHost.swift` / `.kt` / `widget-host.ts`); `twidget/blitz_renderer.h` is a |
| 371 | `Renderer` over the C ABI without a view: the owner takes the rasters (`paint()` or |
| 372 | `onPaint` from the renderer's own 60 Hz clock, which also delivers |
| 373 | `requestAnimationFrame`) and feeds pointers in CSS px (`touch()`, `click()`). |
| 374 | A library without Qt has no main thread — `WidgetHost` keeps its own |
| 375 | "host thread" instead; in Qt the UI thread replaces it one to one. |
| 376 |
| 377 | Harness: `twidget-run … --blitz [--png FILE | --png-dir DIR] [--click X,Y] |
| 378 | [--dpr N]`. On macOS arm64 (2×): `corpus/compat` 21/21 and `corpus/generated` |
| 379 | 40/40 load and draw, 1–9 ms per frame at 800 px width; in |
| 380 | `--attacks --blitz` a load attempt from the Rust document counts as a leak — |
| 381 | 89 attacks, 0 leaks, 0 attempts. Three tests in `twidget-tests` (26 in total): |
| 382 | layout answers come from the document (not the harness's 100×20), a click on a button |
| 383 | reaches the handler, the last raster remains after kill. The gaps are the same |
| 384 | as the crate's everywhere. Windows is not wired up (no link line). |
| 385 |
| 386 | ## Prototype in the web demo (2026-10-10) |
| 387 |
| 388 | The same crate is built for `wasm32-unknown-unknown` (`pnpm build:blitz-web`: |
| 389 | cargo with the `wasm-release` profile, then `wasm-bindgen --target web` — it is needed |
| 390 | only because of `web-time` inside blitz-dom, the `twb_*` exports themselves remain |
| 391 | a plain C ABI, and the TS glue calls them directly through the module's memory). The browser does not |
| 392 | give wasm the system fonts, so this build embeds DejaVu Sans |
| 393 | (`apps/renderer-blitz/assets/`, 259 KB woff2, Bitstream Vera licence) for all |
| 394 | generic families: monospace and serif text comes out sans, emoji are empty. |
| 395 | The module is 8 MB (`opt-level = "s"`, LTO), the first widget on the page pays ~150 ms |
| 396 | for fetch + compilation + document, after that the instance is shared. |
| 397 |
| 398 | `packages/core/src/host/` gained a `renderer.ts` seam (`Renderer` + `RendererFactory`, |
| 399 | the twin of `Renderer.swift` / `.kt` / `packages/desktop/.../renderer.h`), the former iframe |
| 400 | moved out into `iframe-renderer.ts`, `widget-host.ts` takes the factory from the options; |
| 401 | `blitz-renderer.ts` is a `Renderer` on a `<canvas>`: validated ops go to |
| 402 | wasm as JSON, pointers from the canvas in CSS px go to `twb_touch`, the raster |
| 403 | (premultiplied RGBA from vello) is taken on `requestAnimationFrame`, and the same |
| 404 | clock delivers `requestAnimationFrame` frames to the widget. The **Blitz** toggle / |
| 405 | `?blitz=1` in the dev app; without a built module there is a `renderer` diagnostic. |
| 406 | The module lives in `apps/renderer-blitz/pkg-web/` (gitignored) and is served by a Vite plugin |
| 407 | under `/blitz/` outside the module graph, like `/libs/`; it does not go into `vite build` — |
| 408 | it is a development tool. |
| 409 |
| 410 | Checks: `apps/web/tests/unit/blitz-wasm.test.ts` (6 tests on Node through the same ABI: |
| 411 | font, layout and query answers from the geometry, dpr, tap → `click`, |
| 412 | a `data:` image without a single load attempt, frozen) and |
| 413 | `TW_RENDERER=blitz pnpm test:generated` (the sandbox side on Blitz, report in |
| 414 | `docs/compat-report-generated-blitz.md`, the pixel threshold there is informational): |
| 415 | 40/40 load without errors and draw on the canvas; the gallery is |
| 416 | `reports/generated-blitz/`, the gaps are the same as in the table above, plus empty emoji. |
| 417 |
| 418 | ## Reproduction |
| 419 |
| 420 | ```bash |
| 421 | # Blitz |
| 422 | git clone --depth 1 https://github.com/DioxusLabs/blitz.git /tmp/blitz && git -C /tmp/blitz checkout 971f1a3 |
| 423 | cp scripts/blitz-experiment/twidget_render.rs /tmp/blitz/examples/ |
| 424 | (cd /tmp/blitz && cargo build --release --example twidget_render) |
| 425 | corepack pnpm dev # reference mode must be live |
| 426 | corepack pnpm tsx scripts/blitz-experiment/dump-dom.mts reports/blitz-experiment/dump |
| 427 | TW_SHARED_FONTS=1 corepack pnpm tsx scripts/blitz-experiment/compare.mts reports/blitz-experiment/dump /tmp/blitz/target/release/examples/twidget_render reports/blitz-experiment |
| 428 | # litehtml (brew install pango; build: see the header of twidget_litehtml.cpp) |
| 429 | git clone --depth 1 https://github.com/litehtml/litehtml.git /tmp/litehtml && cmake -S /tmp/litehtml -B /tmp/litehtml/build -G Ninja -DCMAKE_BUILD_TYPE=Release -DLITEHTML_BUILD_TESTING=OFF -DLITEHTML_ENABLE_LINT=OFF && cmake --build /tmp/litehtml/build |
| 430 | mkdir -p reports/blitz-experiment/litehtml && for f in reports/blitz-experiment/dump/*.html.html; do n=$(basename $f .html); printf "%s " $n; FONTCONFIG_FILE=scripts/blitz-experiment/fonts.conf ./twidget_litehtml $f 404 reports/blitz-experiment/litehtml/$n.litehtml.png; done > reports/blitz-experiment/litehtml/timings.txt |
| 431 | corepack pnpm tsx scripts/blitz-experiment/gallery.mts reports/blitz-experiment/dump reports/blitz-experiment reports/blitz-experiment/litehtml reports/blitz-experiment/gallery.html |
| 432 | ``` |
| 433 |