Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

A filter's layer stops at paint containment and at its own clip over the boxes its stacking context paints

James Dimachkie4c773e5fcf63
diff --git a/bench/filter-overflow/check.sh b/bench/filter-overflow/check.sh
index 5c559050..7ce2f2d0 100755
--- a/bench/filter-overflow/check.sh
+++ b/bench/filter-overflow/check.sh
@@ -5,10 +5,11 @@
# of a 200x100 child. page.tsx draws both, and the same box clipping its overflow (which must still cut the child)
# and clipping x alone (which cuts its side and shows all its height), and a grayscale box around a square whose
# own drop shadow falls outside it. Each probe is Chrome 157's pixel, within 3.
-# The layer stops at a clip in the way: clipped.tsx's 60 small filtered boxes each hold a clipping box with a child
-# that covers the frame (30 of the clipping boxes in flow, 30 painted by the filtered box's stacking context), and 30
-# layers the size of the frame are more than Vello's image atlas holds, so its 60 tiles are counted (from the
-# frame's mean: each is 60x60 of grey 92 on white). Exits 1 on a failure.
+# The layer stops at a clip in the way: clipped.tsx's 120 small filtered boxes each show 60 px of a child that
+# covers the frame, cut four ways, 30 boxes each (a clipping box inside, one the stacking context paints, the
+# filtered box's own clip over a z-indexed child, a `contain: paint` box inside). 30 layers the size of the frame
+# are more than Vello's image atlas holds, so its 120 tiles are counted (from the frame's mean: each is 60x60 of
+# grey 92 on white). Exits 1 on a failure.
# bench/filter-overflow/check.sh (RAEA_BIN: the raea to run, default target/release/raea)
cd "$(dirname "$0")/../.." || exit 2
BIN=${RAEA_BIN:-$PWD/target/release/raea}
@@ -38,6 +39,6 @@ want 450,270 255 255 255 "its child past the box, clipped"
want 500,300 92 92 92 "a box clipping x alone: its child below the box"
want 580,250 255 255 255 "and its child past its side, clipped"
tiles=$(magick "$OUT/clipped/frame-00000.png" -alpha off -colorspace gray -format "%[fx:int((1-mean)*1920*1080/(3600*(1-92/255))+0.5)]" info:)
-[ "$tiles" = 60 ] || { echo "FAIL clipped.tsx: $tiles of its 60 tiles drawn"; status=1; }
+[ "$tiles" = 120 ] || { echo "FAIL clipped.tsx: $tiles of its 120 tiles drawn"; status=1; }
[ $status = 0 ] && echo "PASS a filter over what its element draws outside its box"
exit $status
diff --git a/bench/filter-overflow/clipped.tsx b/bench/filter-overflow/clipped.tsx
index 3d3a9c84..0343cf23 100644
--- a/bench/filter-overflow/clipped.tsx
+++ b/bench/filter-overflow/clipped.tsx
@@ -1,19 +1,23 @@
-// 60 small filtered boxes, each around a clipping box of its size holding a child that covers the frame from any of
-// them (the last 30 clipping boxes positioned with a z-index, so the filtered box's stacking context paints them):
-// 60 grey 60 px tiles on white. A filter's layer reaches over what its element draws, and stops at a clip in
+// 120 small filtered boxes, each showing 60 px of a child that covers the frame from any of them, cut four ways, 30
+// boxes each: by a clipping box inside; by one positioned with a z-index (the filtered box's stacking context paints
+// it); by the filtered box's own clip, the child positioned with a z-index; and by a `contain: paint` box inside.
+// 120 grey 60 px tiles on white. A filter's layer reaches over what its element draws, and stops at a clip in
// the way: made from the element's overflow, which reaches through clips, each of these layers would be the size of
// the frame, and 30 of them are more than Vello's image atlas holds, of either kind. bench/filter-overflow/check.sh
import { AbsoluteFill, Composition, registerRoot } from "raea";
function O() {
return (
<AbsoluteFill style={{ background: "#fff" }}>
- {Array.from({ length: 60 }, (_, i) => (
- <div key={i} style={{ position: "absolute", left: 60 + (i % 10) * 180, top: 60 + Math.floor(i / 10) * 170, width: 60, height: 60, filter: "grayscale(1)" }}>
- <div style={{ width: 60, height: 60, overflow: "hidden", ...(i < 30 ? {} : { position: "relative", zIndex: 1 }) }}>
- <div style={{ position: "relative", left: -2000, top: -1500, width: 4000, height: 3000, background: "#008000" }} />
+ {Array.from({ length: 120 }, (_, i) => {
+ const kind = Math.floor(i / 30);
+ const cover = <div style={{ position: "relative", left: -2000, top: -1500, width: 4000, height: 3000, background: "#008000", ...(kind === 2 ? { zIndex: 1 } : {}) }} />;
+ const inner = [{ overflow: "hidden" }, { overflow: "hidden", position: "relative", zIndex: 1 }, null, { contain: "paint" }][kind];
+ return (
+ <div key={i} style={{ position: "absolute", left: 30 + (i % 12) * 155, top: 20 + Math.floor(i / 12) * 105, width: 60, height: 60, filter: "grayscale(1)", ...(kind === 2 ? { overflow: "hidden" } : {}) }}>
+ {inner ? <div style={{ width: 60, height: 60, ...inner }}>{cover}</div> : cover}
</div>
- </div>
- ))}
+ );
+ })}
</AbsoluteFill>
);
}
diff --git a/vendor/blitz-paint/src/render.rs b/vendor/blitz-paint/src/render.rs
index ab258bdc..3e9fb3b4 100644
--- a/vendor/blitz-paint/src/render.rs
+++ b/vendor/blitz-paint/src/render.rs
@@ -723,8 +723,8 @@ impl<'dom, 'a> BlitzDomPainter<'dom, 'a> {
}
/// raea: the boxes `node_id` and its descendants draw, in its own space: `scrollable_overflow`'s walk (blitz-dom's
- /// resolve_transforms), cut on each axis an element clips to that element's box grown by its
- /// overflow-clip-margin, as its overflow clip cuts what is drawn (the root element clips nothing: `should_clip`).
+ /// resolve_transforms), cut on each axis an element clips (both, under `contain: paint`) to that element's box
+ /// grown by its overflow-clip-margin, as its clip cuts what is drawn (the root element clips nothing: `should_clip`).
/// The overflow itself reaches through every clip, so a layer made from it is as large as content nobody sees: a
/// filtered card around a small clipping box with a page of content in it would be drawn into a texture the size
/// of the page. With `own_filter`, grown by the reach of the element's own filter, which draws past its boxes (a
@@ -736,8 +736,8 @@ impl<'dom, 'a> BlitzDomPainter<'dom, 'a> {
let own = Rect::new(0.0, 0.0, size.width as f64 * self.scale, size.height as f64 * self.scale);
let styles = node.primary_styles();
let (clips_x, clips_y, grow) = styles.as_ref().filter(|_| self.root_element_id != Some(node_id)).map_or((false, false, 0.0), |s| {
- let b = s.get_box();
- (!matches!(b.overflow_x, Overflow::Visible), !matches!(b.overflow_y, Overflow::Visible), s.get_margin().overflow_clip_margin.offset.0.px() as f64 * self.scale.max(1.0))
+ let (b, paint) = (s.get_box(), contains_paint(s));
+ (paint || !matches!(b.overflow_x, Overflow::Visible), paint || !matches!(b.overflow_y, Overflow::Visible), s.get_margin().overflow_clip_margin.offset.0.px() as f64 * self.scale.max(1.0))
});
let filtered = |r: Rect| match styles.as_ref().filter(|_| own_filter).and_then(|s| convert_filters(&s.get_effects().filter.0)) {
Some(f) => {
@@ -1236,10 +1236,12 @@ impl<'dom, 'a> BlitzDomPainter<'dom, 'a> {
// raea: a filter's input is all the element draws, what its descendants draw outside its box
// included, as Chrome filters it (a 0x0 wrapper's absolutely positioned children were cut off at its
// box, a blur's reach of them left): its boxes up to the clips in their way (`drawn_bounds`), and the
- // same of each box its stacking context paints, where that puts it (hoisted_content_bbox's places)
+ // same of each out-of-flow box its stacking context paints past its clip, from a containing block
+ // above it (#39's `from_above`: the walk doesn't meet those), where hoisted_content_bbox places it.
+ // The stacking context's other boxes are met by the walk, under the clips they're painted under
if filter.is_some() {
effect_layer_clip = effect_layer_clip.union(self.drawn_bounds(node_id, false));
- for hoisted in node.stacking_context.iter().flat_map(|sc| sc.children.iter()) {
+ for hoisted in node.stacking_context.iter().flat_map(|sc| sc.children.iter()).filter(|c| cx.from_above(c.node_id)) {
let Some(child) = self.dom.as_ref().get_node(hoisted.node_id) else { continue };
let (p, at) = (hoisted.position(node.tree(), node_id), child.final_layout().location);
let mut to_own = Affine::translate(((p.x + at.x) as f64 * self.scale, (p.y + at.y) as f64 * self.scale));
@@ -2494,6 +2496,14 @@ fn create_css_rect(style: &ComputedValues, layout: &Layout, scale: f64) -> CssBo
frame
}
+/// raea: whether `contain: paint` clips an element's contents, as render_element's `contain_paint` has it (not a
+/// non-atomic inline's, nor an internal table box's other than a cell)
+fn contains_paint(styles: &style::properties::ComputedValues) -> bool {
+ let display = styles.clone_display();
+ let table_part = display.outside() == DisplayOutside::InternalTable && display.inside() != DisplayInside::TableCell;
+ styles.get_box().clone_contain().contains(Contain::PAINT) && !display.is_inline_flow() && !table_part
+}
+
/// raea: what an overflow clip clips to: overflow-clip-margin's visual box (the padding box by default), grown by its
/// offset (bevy_ui's OverflowClipMargin, ComputedNode::resolve_clip_rect). A grown one is a rect, as Bevy's clip is.
fn overflow_clip_box(frame: &CssBox, m: &style::values::computed::OverflowClipMargin) -> crate::kurbo_css::BoxShape {