Repository navigation
paint, blitz, dom-shim: CSS filters, background-clip:text, clip-path shapes, canvas bg, tables, and document.write - #214
Conversation
46f3b1c to
ce858a2
Compare
bf45b11 to
e04c36b
Compare
e04c36b to
590ecc0
Compare
590ecc0 to
8fe4de4
Compare
8fe4de4 to
3edd029
Compare
| + }; | ||
| + // Aggregate per-frame/band filter pixmap budget (16 MiB RGBA8) so neither | ||
| + // a single oversized layer nor many small blurred layers can OOM wasm. | ||
| + const MAX_TOTAL_FILTER_PIXMAP_PIXELS: usize = 4 * 1024 * 1024; |
There was a problem hiding this comment.
beep-boop-rui-agent-🤖
Blocking: html { filter: invert(1) } still paints white text on a white page at 1920×1200 and larger.
This is the second half of the earlier thread. The fix works on small viewports, but this budget breaks it on common desktop ones.
The 16 MiB budget covers all filter layers in a single-pass frame. Patch 0043 now gives the root's filter two layers, and each one covers the viewport: the propagated canvas background and the root element's own layer. rasterize_filter_layers walks filter_layers in reverse, so the root layer gets its pixmap first. The canvas layer was pushed first, so it is the one that goes over budget and takes set_unfiltered_fallback (line 232). The background then paints white, and the inverted text is white too.
Frames up to MAX_RETAINED_PIXELS (2560×1440) are single-pass (scene_replay.rs:1706), so band clipping never applies to them. Two layers need 2 × 2.3M px at 1920×1200 and 2 × 3.7M px at 2560×1440. Both are over the 4.19M px budget.
Repro: a scratch program on the head's patched vello_cpu and vello_common. It pushes a full-viewport inverted white layer (the canvas), then an inverted layer over the whole viewport (the root), and samples a canvas pixel. The pixel should be black:
| viewport | canvas pixel | expected |
|---|---|---|
| 1280×720 | (0,0,0) |
black |
| 1920×1080 | (0,0,0) |
black |
| 1920×1200 | (255,255,255) |
black |
| 2560×1440 | (255,255,255) |
black |
At 1920×1080, any other filtered element larger than about 47k px also pushes the canvas layer over the budget.
On the base branch, filters were ignored, so the page showed black text on white and stayed readable.
Fix, any one of:
- Don't count single-pass frames against the budget.
MAX_RETAINED_PIXELSalready bounds them. - Raise the budget to at least 2 ×
MAX_RETAINED_PIXELS. - Always band-clip when the frame has filters.
- Paint the canvas background inside the root's filter layer, so one pixmap serves both.
Test: run html_filter_invert_inverts_propagated_background_and_text at 1920×1200 and 2560×1440 too. Add a 1920×1080 case with one extra filtered child.
There was a problem hiding this comment.
Fixed in 53736573: raised MAX_TOTAL_FILTER_PIXMAP_PIXELS in vello_cpu patch 0005 (src/dispatch/single_threaded.rs) to 3 * 2560 * 1440 so single-pass root-filtered desktop frames (canvas + root + filtered child) fit without falling back to unfiltered white. Added 1920x1080, 1920x1200, and 2560x1440 coverage with an extra filtered child in packages/core/src/paint/tests/negative_z_index_body_bg.rs.
| + .max(root_overflow.x1 as f32); | ||
| + let bg_height = (self.height as f32) | ||
| + .max(root_element.final_layout().size.height) | ||
| + .max(root_overflow.y1 as f32); |
There was a problem hiding this comment.
beep-boop-rui-agent-🤖
Blocking: propagated backgrounds now stretch over the document's overflow instead of the root box.
bg_width and bg_height now include root_overflow.x1/y1. They become canvas_layout.size, which is the origin box for every background layer: box_rect(layer.origin) in background.rs:592-596, and the gradient path. Patch 0040 skips the in-flow root and body paint, so this canvas paint is the only one.
Example: html, body { height: 100% }, a body gradient or a background-size: cover image, and content taller than the viewport.
- On this branch, the image stretches over the full scroll height.
- Chrome sizes it to the root box (100vh) and repeats it.
- Children that sit off-canvas or are transformed and widen
x1also shiftcenter-positioned backgrounds.
Computed from the code path for a black-to-white body gradient with 2000px of content, at scroll 0 (not rendered):
| y=100 | value |
|---|---|
| this branch | about 13/255 (dark grey) |
| base branch and Chrome | about 127/255 (mid grey) |
On the base branch, the in-flow root and body background painted over the root box, so the screenshot at scroll 0 matched Chrome. e04c36b6 also used max(viewport, root size). propagated_percentage_gradient_stays_scroll_stable passes either way, because it only checks that the colour stays the same across scrolls.
Fix: keep the root's border box as the positioning area, as before, and widen only the painting area (the clip) to cover the overflow or the scrolled viewport. Test: html, body { height: 100% }, a body gradient and 2000px of content. Check that y=100 at scroll 0 is mid grey, so the gradient spans one viewport.
There was a problem hiding this comment.
Fixed in 53736573: updated blitz-paint patch 0043 (src/render.rs, src/render/background.rs) so propagated canvas backgrounds keep the root box as their positioning area while canvas_paint_rect widens only the painting clip across overflow and scroll. Extended propagated_percentage_gradient_stays_scroll_stable in packages/core/src/paint/tests/negative_z_index_body_bg.rs to assert mid-grey (~127/255) at y=100 for both html and body.
3edd029 to
5373657
Compare
ruifigueira
left a comment
There was a problem hiding this comment.
beep-boop-rui-agent-🤖
The blocking findings are fixed. Approving.
cc9bfbd to
f909758
Compare
| pub(crate) const TAG_TEXT_RUN: u8 = 0x08; | ||
| pub(crate) const TAG_PART: u8 = 0x09; | ||
| pub(crate) const TAG_GLYPH_TEXT: u8 = 0x0a; | ||
| pub(crate) const TAG_LAYER_FILTER: u8 = 0x0b; |
There was a problem hiding this comment.
beep-boop-rui-agent-🤖
Before merge: these tags clash with main's wire version 18.
Main bumped WIRE_VERSION to 18 in f9e773a11 (the blitz beta.5 bump), with TAG_PUSH_MASK_LAYER = 0x0b and TAG_ALIASED = 0x0c. This PR also uses version 18, with 0x0b and 0x0c for TAG_LAYER_FILTER and TAG_BACKDROP_FILTER.
The file conflicts with main, so the rebase stops on it. But a resolution that keeps both sets of tags and version 18 gives one tag two meanings.
When you rebase: move the filter tags to free values (for example 0x0e and 0x0f, after checking that the tag mask in the decoder still fits them), and bump to 19.
The rest of the stack conflicts with main too: every blitz-*-0.3.0-beta.4 patch has to move to beta.5.
There was a problem hiding this comment.
Still open on this branch: the stack is based on the beta.4 patch series, so moving the filter tags to free values and bumping the wire version only makes sense together with the move to beta.5. I am keeping this thread open for that rebase onto main rather than mixing it into the fix commits.
…e keywords per spec `clip-path: circle(50%)` resolved percentage radii against box width instead of `sqrt(width^2 + height^2) / sqrt(2)`, and `ellipse(closest-side closest-side)` took the minimum of both axes for each semi-axis, collapsing ellipses on non-square boxes into circles. Split `resolve_circle_radius` and `resolve_ellipse_radius` in `clip_path.rs` per CSS Shapes 1 §3.2. https://drafts.csswg.org/css-shapes-1/#funcdef-basic-shape-circle https://drafts.csswg.org/css-shapes-1/#funcdef-basic-shape-ellipse Signed-off-by: bpereira <bpereira@cloudflare.com>
…pans Background layers with `background-clip: text` were skipped by the background painter, so gradient headings with `color: transparent` or `-webkit-text-fill-color: transparent` painted invisible (tanstack.com/table, overreacted.io, gptzero.me). Paint text-clipped background layers inside an isolated layer masked with opaque glyph silhouettes via `Compose::DestIn`, for both inline roots and inline descendant spans, and remove the old transparent-fill fallback. https://drafts.csswg.org/css-backgrounds-4/#valdef-background-clip-text Signed-off-by: bpereira <bpereira@cloudflare.com>
… body When `paint_scene` propagated `<body>`'s (or `<html>`'s) background to the canvas, `render_element` painted that element's background a second time in normal flow, overpainting any `z-index: -1` descendants hoisted into the root stacking context. Record `canvas_bg_source_id` during canvas propagation and skip `draw_background` for that element per CSS Backgrounds 3 §2.11.2. https://drafts.csswg.org/css-backgrounds-3/#body-background Signed-off-by: bpereira <bpereira@cloudflare.com>
…rent `document.write()` previously always appended parsed nodes to `document.body`, displacing inline header/navigation markup written by a script inside `<body>` (such as version-switcher controls written inside a page `<header>`) to the bottom of the document. When `document.write()` runs from a live `<script>` inside `<body>` (and the document has not been reopened via `document.open()`), insert the written nodes into `currentScript.parentNode` before a fixed anchor recorded from `currentScript.nextSibling`, preserving document order across repeated writes. https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-write Signed-off-by: bpereira <bpereira@cloudflare.com>
…to tables
Two table layout gaps caused mismatched cell alignment and column widths:
- HTML `valign` attributes on `<thead>`, `<tbody>`, `<tfoot>`, `<tr>`, `<td>`,
and `<th>` were not mapped as presentational hints, leaving cells with
`valign="top"` vertically centered (`vertical-align: middle`).
- Under `table-layout: auto`, percentage widths on `<col>` and single-column
cells (such as `.w-25 { width: 25% }`) were discarded, causing columns to
split solely by content width.
Map `valign` to Stylo's `alignment-baseline`/`baseline-shift` longhands per
HTML §15.3.9, and size percentage-constrained auto-table columns as
`minmax(min-content, pct)` with cumulative percentages capped at 100% per
CSS Tables 3 §3.9.4.
https://html.spec.whatwg.org/multipage/rendering.html#tables-2
https://drafts.csswg.org/css-tables-3/#distributing-width-to-columns
Signed-off-by: bpereira <bpereira@cloudflare.com>
…ay paths CSS `filter` functions (`blur`, `brightness`, `contrast`, `grayscale`, `hue-rotate`, `invert`, `opacity`, `saturate`, `sepia`, `drop-shadow`) were dropped at two layers: `anyrender_vello_cpu` had its `filters` feature disabled in `Cargo.toml`, and the KSC0 scene wire format ignored layer filters on record/replay. In addition, `vello_common`/`vello_cpu` did not yet execute `ColorMatrix` filter primitives, and `blitz-paint` resolved omitted `drop-shadow()` colors to black instead of `currentColor`. - Enable `anyrender_vello_cpu`'s `filters` feature and skip unsupported `Blend` primitives in `anyrender_vello_cpu` so conversion never hits `unimplemented!`. - Implement `PreparedFilter::ColorMatrix` in `vello_common` and 4x5 RGBA color matrix execution in `vello_cpu` (unpremultiplied per Filter Effects 1 §9). - Pass the element's computed color to `blitz-paint::convert_filters` so `drop-shadow()` inherits `currentColor`. - Serialize layer filters with a zero-overhead `TAG_LAYER_FILTER` prefix in `scene_record`/`scene_decode`/`scene_replay` so `SceneRasterizer` replays them identically to direct rendering. https://drafts.fxtf.org/filter-effects/#FilterProperty https://drafts.fxtf.org/filter-effects/#feColorMatrixElement Signed-off-by: bpereira <bpereira@cloudflare.com>
…rop-filter WPTs `ReplayVisitor` converted whole-pixel clip layers into `push_clip_path` unless a non-SrcOver blend mode was present, which bypassed clipping of composited CSS filter outputs (such as `blur()` under `overflow: hidden` and `drop-shadow()` under `clip-path`). Disable the `push_clip_path` shortcut when a scene carries a `TAG_LAYER_FILTER` so enclosing clip layers clip filtered subtrees. Also rebaseline four `backdrop-filters-*` WPT reftests whose references use `filter:` and previously passed only because `filter:` was also a no-op. Signed-off-by: bpereira <bpereira@cloudflare.com>
…oll 11 WPT tests Implement CSS `backdrop-filter` end-to-end across `blitz-paint`, KSC0 record/replay, `anyrender_vello_cpu`, `vello_common`, and `vello_cpu`: - Record an atomic `RecordedLayerKind::BackdropFilter` leaf layer with unshifted tile-aligned placement expanded by filter padding (`vello_common`). - In `vello_cpu`, rasterize backdrop-filter layers in forward paint order by bucketing the scene up to each backdrop-filter layer (`stop_at_layer`), applying `filter_layer` to the sampled backdrop pixmap, and compositing the filtered result clipped to the element's border box. - Forward `backdrop_filter` through `anyrender_vello_cpu` and KSC0 (`TAG_BACKDROP_FILTER`) and emit it in `blitz-paint` clipped to `border_box_path()` before painting the element's own background and children. - Restore all four `backdrop-filters-*` WPT reftests to `PASS` and enroll 11 newly-passing WPT tests covering `backdrop-filter`, `filter`, `clip-path`, and auto-table width distribution. https://drafts.fxtf.org/filter-effects-2/#BackdropFilterProperty Signed-off-by: bpereira <bpereira@cloudflare.com>
…g, and band-clip filter layers
Bump KSC0 WIRE_VERSION from 17 to 18 for TAG_LAYER_FILTER and
TAG_BACKDROP_FILTER so older decoders fail cleanly with version mismatch.
Paint the propagated canvas background with the root's scroll-adjusted
transform, size it from root layout + scrollable overflow (keeping
percentage gradients scroll-stable), and apply the root element's CSS
filter (such as `html { filter: invert(1) }`) to the propagated canvas
background across the full viewport.
Clip top-level and nested filter/backdrop-filter layers vertically to the
active render band using symmetric halo padding (preserving directional
drop-shadow output across 128-row band seams) and tile-safe u16::MAX
bounds. Clamp drop-shadow dx/dy to +/-256px, enforce a 16 MiB aggregate
per-frame/band filter pixmap budget, and fall back to inlining over-budget
filter layer children unfiltered instead of dropping them.
Signed-off-by: bpereira <bpereira@cloudflare.com>
Keep propagated canvas backgrounds positioned and sized against the root box per CSS Backgrounds 3 §2.11.1 while widening only the painting clip to cover document overflow and scroll. Raise vello_cpu's filter pixmap budget to three 2560x1440 layers so root-filtered pages (canvas + root + filtered child) do not fall back to unfiltered white at 1920x1200+. Signed-off-by: bpereira <bpereira@cloudflare.com>
The per-cell table background pass makes /css/CSS2/tables/ table-backgrounds-bs-table-001.xht and table-backgrounds-bs-cell-001.xht match their references, so both are unexpected passes against their FAIL pins. The column-group, column, row-group and row variants still differ and keep their pins. Verified with //tests/wpt:css-css2-tables-e4897b on the merged tree. Signed-off-by: bpereira <bpereira@cloudflare.com>
…entages on definite width Cull repeated SVG background tiles to the visible viewport in draw_svg_image_layer using visible_tiles, matching draw_gradient_layer, so propagated canvas SVG backgrounds do not disappear on tall pages. Apply percentage column max tracks from table cells only when the table has a definite width, keeping auto-width and shrink-to-fit tables on one line instead of collapsing columns to min-content. Signed-off-by: bpereira <bpereira@cloudflare.com>
f909758 to
c7b5ea1
Compare
Stacked on #210 (
bpereira/compat-svg-responsive-images).Changes
clip-path: circle()/ellipse()(blitz-paint 0037): resolve percentage circle radii againstsqrt(w^2 + h^2) / sqrt(2)and per-axisclosest-side/farthest-sideellipse radii per CSS Shapes 1 §3.2.background-clip: text(blitz-paint 0038): paint text-clipped background layers inside an isolated layer masked by opaque glyph silhouettes viaCompose::DestInfor both inline roots and inline descendant spans, removing the transparent-fill fallback.blitz-paint 0039): recordcanvas_bg_source_idwhen propagating<html>/<body>backgrounds to the canvas and skip re-painting that element's background in normal flow soz-index: -1descendants remain visible per CSS Backgrounds 3 §2.11.2.document.write()insertion point (packages/dom-shim/src/document.ts): insert written markup atcurrentScript.parentNodebefore a fixednextSiblinganchor (preserving order across repeated writes) when called from a live classic<script>inside<body>per HTML §8.4.4.valignhints & auto-table percentage columns (blitz-dom 0106): mapvalignattributes on<thead>,<tbody>,<tfoot>,<tr>,<td>, and<th>to Stylo'salignment-baseline/baseline-shiftlonghands per HTML §15.3.9, and honour percentage column widths on<col>and single-column cells undertable-layout: auto(minmax(min-content, pct), cumulative cap 100%) per CSS Tables 3 §3.9.4.filterrendering (Cargo.toml,vello_common 0002,vello_cpu 0003,anyrender_vello_cpu 0004,blitz-paint 0040,packages/core/src/paint/scene_{record,decode,replay}.rs): enableanyrender_vello_cpu'sfiltersfeature, implementColorMatrixfilter execution invello_common/vello_cpu, resolve omitteddrop-shadow()colors viacurrentColor, and serialize layer filters over KSC0 via a zero-overheadTAG_LAYER_FILTERprefix per CSS Filter Effects 1 §9.Verification
//packages/core:core_test+//:rust_lint(includingrenderer-coreandscene-host-wasmclippy): 30/30 passed, with new pixel/layout tests inclip_path_shapes.rs,background_clip_text.rs,negative_z_index_body_bg.rs,table_valign_and_percent.rs, andcss_filters.rs.//packages/dom-shim:all: 4/4 passed.//packages/engine/test/e2e:written-script-order(8/8 passed) and//packages/engine/test/e2e:background-reopen-lifecycle(2/2 passed).