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.

An absolutely positioned box is painted inside the opacity (or other stacking context) between it and its containing block, as Chrome paints it (closes #39). blitz-dom hands an out-of-flow box to its containing block to paint (hoisted_children), and the containing block painted it in its own layer. So in `<div style="opacity:0.3"><div style="position:absolute">`, where the wrapper isn't positioned and the containing block is further up, the box was drawn at full opacity, outside the group it belongs to. Chrome 148 draws it faded, since a stacking context paints everything inside it, positioned or not.

shinyobjectz4219d620f6b8
diff --git a/bench/opacity-out-of-flow/check.sh b/bench/opacity-out-of-flow/check.sh
new file mode 100755
index 00000000..57cbfc8f
--- /dev/null
+++ b/bench/opacity-out-of-flow/check.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+# #39: an absolutely positioned child is faded with an unpositioned parent's opacity, as Chrome paints it. index.html
+# draws four black 160 px boxes in groups at opacity 0.3 on white; each box's centre must be Chrome's grey (178), and
+# the fourth box must stay where its containing block puts it though its wrapper is moved down (white above it, at
+# y 30, and grey at its top edge, y 45). Exits 1 on a failure.
+# bench/opacity-out-of-flow/check.sh (RAEA_BIN: the raea to run, default target/release/raea)
+cd "$(dirname "$0")/../.." || exit 2
+BIN=${RAEA_BIN:-$PWD/target/release/raea}
+export RAEA_SIGN=0 RAEA_MARK=0 RAEA_EXPORT_CACHE=0
+OUT=$(mktemp -d "${TMPDIR:-/tmp}/raea-opacity-oof.XXXXXX")
+trap 'rm -rf "$OUT"' EXIT
+"$BIN" render bench/opacity-out-of-flow/index.html -o "$OUT/a.png" > "$OUT/log" 2>&1 || { echo "FAIL render (log below)"; sed 's/^/ /' "$OUT/log"; exit 1; }
+grey() { magick "$OUT/a.png" -format "%[fx:int(255*p{$1}.r+0.5)]" info:; }
+status=0
+want() { # X,Y GREY WHAT: within 3
+ local g; g=$(grey "$1")
+ (( g - $2 <= 3 && $2 - g <= 3 )) || { echo "FAIL at $1: $g, wanted $2 ($3)"; status=1; }
+}
+want 120,120 178 "1: an absolute child of an unpositioned wrapper"
+want 320,120 178 "2: an in-flow child"
+want 520,120 178 "3: an absolute child of a positioned wrapper"
+want 720,120 178 "4: as 1, its wrapper moved down"
+want 720,30 255 "4: above the box, white"
+want 720,45 178 "4: the box's top edge, where its containing block puts it"
+[ $status = 0 ] && echo "PASS opacity over out-of-flow children"
+exit $status
diff --git a/bench/opacity-out-of-flow/index.html b/bench/opacity-out-of-flow/index.html
new file mode 100644
index 00000000..1099dbf2
--- /dev/null
+++ b/bench/opacity-out-of-flow/index.html
@@ -0,0 +1,23 @@
+<!doctype html>
+<!-- #39: opacity below 1 makes a stacking context, which paints every box inside it, positioned or not, faded with
+ it. Four black boxes in groups at opacity 0.3 on white; Chrome draws all four grey (178). 1: an absolute child of
+ an unpositioned wrapper (raea drew it black: it was painted by its containing block, outside the group). 2: an
+ in-flow child. 3: an absolute child of a positioned wrapper. 4: as 1, the wrapper moved down 120 px by a margin,
+ which mustn't move the child (its place is from its containing block; flow-root keeps that margin from
+ collapsing into the container). bench/opacity-out-of-flow/check.sh -->
+<html><body style="margin:0;background:#fff">
+<div data-composition-id="main" data-start="0" data-duration="1" data-width="960" data-height="240" style="position:relative;display:flow-root;width:960px;height:240px">
+ <div style="opacity:0.3">
+ <div style="position:absolute;left:40px;top:40px;width:160px;height:160px;background:#000"></div>
+ </div>
+ <div style="position:absolute;left:240px;top:40px">
+ <div style="opacity:0.3"><div style="width:160px;height:160px;background:#000"></div></div>
+ </div>
+ <div style="position:absolute;left:440px;top:40px;opacity:0.3">
+ <div style="position:absolute;left:0;top:0;width:160px;height:160px;background:#000"></div>
+ </div>
+ <div style="opacity:0.3;margin-top:120px">
+ <div style="position:absolute;left:640px;top:40px;width:160px;height:160px;background:#000"></div>
+ </div>
+</div>
+</body></html>
diff --git a/vendor/blitz-dom/src/layout/paint_tree.rs b/vendor/blitz-dom/src/layout/paint_tree.rs
index 494ad293..5196cc26 100644
--- a/vendor/blitz-dom/src/layout/paint_tree.rs
+++ b/vendor/blitz-dom/src/layout/paint_tree.rs
@@ -49,8 +49,10 @@ pub fn hoisted_child_position(tree: &NodeTree, sc_root_id: NodeId, child_id: Nod
position.y += scroll_offset.y as f32 + viewport_scroll.y as f32;
}
+ let mut reached = false;
while let Some(id) = current {
if id == sc_root_id {
+ reached = true;
break;
}
let Some(node) = tree.get(id) else {
@@ -62,6 +64,21 @@ pub fn hoisted_child_position(tree: &NodeTree, sc_root_id: NodeId, child_id: Nod
position.y += location.y - scroll_offset.y as f32;
current = node.containing_block();
}
+ // raea: a root below the child's containing block (an out-of-flow box it paints, #39): both placed from the top,
+ // the root's own place taken off, and not scrolled with the root (its containing block is outside it)
+ if !reached && let Some(root) = tree.get(sc_root_id) {
+ let (mut x, mut y) = (root.final_layout().location.x, root.final_layout().location.y);
+ let mut up = root.containing_block();
+ while let Some(node) = up.and_then(|a| tree.get(a)) {
+ let (l, sc) = (node.final_layout().location, *node.scroll_offset());
+ x += l.x - sc.x as f32;
+ y += l.y - sc.y as f32;
+ up = node.containing_block();
+ }
+ let sc = *root.scroll_offset();
+ position.x += sc.x as f32 - x;
+ position.y += sc.y as f32 - y;
+ }
position
}
@@ -324,6 +341,8 @@ impl BaseDocument {
self.nodes
.get(id)
.is_some_and(|n| n.layout_parent.get() != Some(node_id))
+ // raea: not one a stacking context below this node paints (#39: paint_owner)
+ && self.paint_owner(id) == Some(node_id)
})
.map(|id| {
let anchor = self
@@ -389,6 +408,11 @@ impl BaseDocument {
*node.layout_children.borrow_mut() = Some(children);
}
+ // raea: a stacking-context root paints the out-of-flow boxes inside it whose containing block is above it (#39)
+ if stacking_context.is_none() {
+ self.take_out_of_flow(node_id, &mut entries);
+ }
+
let node = &mut self.nodes[node_id];
if let Some(stacking_context) = stacking_context {
node.stacking_context = None;
@@ -413,6 +437,42 @@ impl BaseDocument {
}
}
+ /// raea: who paints an out-of-flow box (#39): the nearest stacking-context root between it and its containing
+ /// block, as Chrome paints it inside that root's group (an unpositioned `opacity: 0.3` wrapper fades its absolute
+ /// child), else the containing block. None for a box in flow.
+ fn paint_owner(&self, id: NodeId) -> Option<NodeId> {
+ let cb = self.nodes.get(id)?.oof_containing_block.get()?;
+ let mut current = self.nodes[id].layout_parent.get();
+ while let Some(a) = current.filter(|a| *a != cb) {
+ let node = self.nodes.get(a)?;
+ if node.is_stacking_context_root(false) {
+ return Some(a);
+ }
+ current = node.layout_parent.get();
+ }
+ Some(cb)
+ }
+
+ /// raea: the out-of-flow boxes `root` paints though their containing blocks are above it (paint_owner), each an
+ /// entry of its stacking context, placed by hoisted_child_position from where it's laid out (#39)
+ fn take_out_of_flow(&mut self, root: NodeId, entries: &mut ThinVec<HoistedPaintChild>) {
+ let mut taken = Vec::new();
+ let mut up = self.nodes[root].layout_parent.get();
+ while let Some(a) = up {
+ let Some(node) = self.nodes.get(a) else { break };
+ taken.extend(node.hoisted_children.borrow().iter().copied().filter(|&id| self.paint_owner(id) == Some(root)));
+ up = node.layout_parent.get();
+ }
+ for id in taken {
+ let is_sc_root = self.nodes[id].is_stacking_context_root(false);
+ self.build_paint_tree_impl(id, if is_sc_root { None } else { Some(entries) });
+ if is_sc_root {
+ self.take_globals(id, entries);
+ }
+ entries.push(HoistedPaintChild::new(id, self.nodes[id].z_index(), self.nodes[id].is_bevy_global_z()));
+ }
+ }
+
/// Visit an out-of-flow box hoisted to its containing block past its
/// layout parent and place it in the paint lists: z-indexed boxes go to
/// the enclosing stacking context like any other z-indexed positioned
diff --git a/vendor/blitz-paint/src/render.rs b/vendor/blitz-paint/src/render.rs
index eea408ba..350a5f9b 100644
--- a/vendor/blitz-paint/src/render.rs
+++ b/vendor/blitz-paint/src/render.rs
@@ -833,7 +833,14 @@ impl<'dom, 'a> BlitzDomPainter<'dom, 'a> {
};
// Don't render things that are out of view
- let overflow = *node.scrollable_overflow();
+ let mut overflow = *node.scrollable_overflow();
+ // raea: and what a stacking context paints of the out-of-flow boxes inside it whose containing blocks are
+ // above it (#39), which its own overflow leaves to those containing blocks: not culled, and in its opacity layer
+ if let Some(sc) = node.stacking_context.as_ref().filter(|sc| !sc.children.is_empty()) {
+ let b = sc.hoisted_content_bbox(node.tree(), node_id, self.scale);
+ let s = self.scale;
+ overflow = overflow.union(Rect::new(b.left as f64 * s, b.top as f64 * s, b.right as f64 * s, b.bottom as f64 * s));
+ }
// raea: inside a 3D rendering context an element is placed from the context root's parent, not its own
// parent (which may flatten to nothing), and an element that starts one keeps that space for its children
// A projective one (a perspective's) is drawn in its own space into a layer the page warps into place.
@@ -1285,6 +1292,14 @@ impl<'dom, 'a> BlitzDomPainter<'dom, 'a> {
cx.draw_select_chevron(scene);
},
);
+ // raea: the out-of-flow boxes it paints from containing blocks above it (#39), in its group
+ // but outside its overflow clip, which doesn't hold them (a clip layer is a layer of its own:
+ // a blended fixed box inside it blended with nothing)
+ let scrolled = unscrolled_transform.pre_translate(Vec2 {
+ x: -node.scroll_offset().x * self.scale,
+ y: -node.scroll_offset().y * self.scale,
+ });
+ cx.draw_from_above(scene, scrolled, clip_rect);
// Overlay scrollbars, drawn unscrolled above the
// clipped content.
@@ -2002,7 +2017,7 @@ impl ElementCx<'_, '_> {
// Negative z_index hoisted nodes
if let Some(hoisted) = &self.node.stacking_context {
- for hoisted_child in hoisted.neg_z_hoisted_children() {
+ for hoisted_child in hoisted.neg_z_hoisted_children().filter(|c| !self.from_above(c.node_id)) {
let position = hoisted_child.position(self.node.tree(), self.node.id);
let pos = kurbo::Vec2 {
x: position.x as f64 * self.scale,
@@ -2033,7 +2048,7 @@ impl ElementCx<'_, '_> {
// Positive z_index hoisted nodes
if let Some(hoisted) = &self.node.stacking_context {
- for hoisted_child in hoisted.pos_z_hoisted_children() {
+ for hoisted_child in hoisted.pos_z_hoisted_children().filter(|c| !self.from_above(c.node_id)) {
let position = hoisted_child.position(self.node.tree(), self.node.id);
let pos = kurbo::Vec2 {
x: position.x as f64 * self.scale,
@@ -2051,6 +2066,29 @@ impl ElementCx<'_, '_> {
}
}
+ /// raea: whether a hoisted child is an out-of-flow box this stacking context paints though its containing block
+ /// is above it (#39): the root isn't on its chain of containing blocks
+ fn from_above(&self, child: NodeId) -> bool {
+ let tree = self.node.tree();
+ let mut chain = tree.get(child).and_then(|n| n.containing_block());
+ while let Some(id) = chain.filter(|id| *id != self.node.id) {
+ chain = tree.get(id).and_then(|n| n.containing_block());
+ }
+ chain.is_none()
+ }
+
+ /// raea: the out-of-flow boxes this stacking context paints from containing blocks above it (#39), by z, after
+ /// its content: in its group, outside its overflow clip, and under none of the clips between (the boxes they're
+ /// in are the root's too, whose clips are already pushed)
+ fn draw_from_above(&self, scene: &mut impl PaintScene, transform: Affine, clip_rect: Rect) {
+ let Some(sc) = &self.node.stacking_context else { return };
+ for c in sc.neg_z_hoisted_children().chain(sc.pos_z_hoisted_children()).filter(|c| self.from_above(c.node_id)) {
+ let p = c.position(self.node.tree(), self.node.id);
+ let pos = Vec2 { x: p.x as f64 * self.scale, y: p.y as f64 * self.scale };
+ self.render_node(scene, c.node_id, transform.pre_translate(pos), clip_rect);
+ }
+ }
+
/// raea: a hoisted child (a z-index's, painted from its stacking-context root) under the overflow clips of the
/// boxes between it and that root along its containing blocks, as Chrome clips it: each one's padding box, from
/// the root, pushed as a clip layer. Returns how many were pushed. Drawn from the root alone it painted past them
diff --git a/vendor/vendor.toml b/vendor/vendor.toml
index 81de0ab7..2bf35f3f 100644
--- a/vendor/vendor.toml
+++ b/vendor/vendor.toml
@@ -56,14 +56,14 @@ exit = "a bevy_ui_widgets release on parley 0.12"
path = "vendor/blitz-paint"
upstream = "crates.io:0.3.0-beta.4"
kind = "patch"
-reason = "angled tile gradients, many-tile gradient layers as one brush, text-shadow, ellipsis, inline-box opacity, box-shadow blur as Chrome's; filters by GPU passes (B4a/B4b); z-index boxes clipped by the overflow between them and their stacking context; a range input's thumb; what an element paints at an offset of its own (background position and tiles, box and text shadows, scroll, inline SVG) placed in its own axes under a rotated ancestor (#18); background-clip: text, its background masked by the text of the element and everything in it (#37) as Chrome does, unscrolled; inline text in a scroller scrolled once, not twice (#46); a rounded corner where one side has no width (a left-only border on a rounded box), which drew nothing; a bevy_ui node's box shadow (data-raea-bevy-shadow, its BoxShadowSamples) drawn as bevy_ui draws it: spread by its width and its height and corners by the same ratio, then blurred as box_shadow.wesl blurs it, from a CPU bitmap (render/bevy_shadow.rs)"
+reason = "angled tile gradients, many-tile gradient layers as one brush, text-shadow, ellipsis, inline-box opacity, box-shadow blur as Chrome's; filters by GPU passes (B4a/B4b); z-index boxes clipped by the overflow between them and their stacking context; a range input's thumb; what an element paints at an offset of its own (background position and tiles, box and text shadows, scroll, inline SVG) placed in its own axes under a rotated ancestor (#18); background-clip: text, its background masked by the text of the element and everything in it (#37) as Chrome does, unscrolled; inline text in a scroller scrolled once, not twice (#46); a rounded corner where one side has no width (a left-only border on a rounded box), which drew nothing; a bevy_ui node's box shadow (data-raea-bevy-shadow, its BoxShadowSamples) drawn as bevy_ui draws it: spread by its width and its height and corners by the same ratio, then blurred as box_shadow.wesl blurs it, from a CPU bitmap (render/bevy_shadow.rs); a stacking context's out-of-flow boxes from containing blocks above it kept in its layer and not culled (raea #39)"
exit = "a Blitz release that draws these"
[blitz-dom]
path = "vendor/blitz-dom"
upstream = "crates.io:0.3.0-beta.4"
kind = "patch"
-reason = "inline flex/grid baselines, auto table columns, table row rects, inline image load events, SVG text fonts, SVG non-scaling strokes, url() filters; Blitz main's #1244 and #1246; a node removed in a mutation batch dropped from the style, form and title nodes the batch flushes (raea #24); a node in a 3D rendering context (or with a projection) placed again on every resolve, so it follows a preserve-3d parent whose transform a script set (raea #19); a ParseErrorReporter (not_applied.rs) on every author parse, keeping what stylo drops for the render to say once (raea #34); a bevy_text box whose lines are no finite size (an Apple bitmap-only face, which parley scales by a units-per-em of 0) measures 0 by 0, as bevy_text does; a family list ending in "raea-bevy fallback" (bevy_text's FontSource::Family) falls to the collection's fallback families, not to serif nor to the CoreText pick (parley: NO_HOOK_FAMILY)"
+reason = "inline flex/grid baselines, auto table columns, table row rects, inline image load events, SVG text fonts, SVG non-scaling strokes, url() filters; Blitz main's #1244 and #1246; a node removed in a mutation batch dropped from the style, form and title nodes the batch flushes (raea #24); a node in a 3D rendering context (or with a projection) placed again on every resolve, so it follows a preserve-3d parent whose transform a script set (raea #19); a ParseErrorReporter (not_applied.rs) on every author parse, keeping what stylo drops for the render to say once (raea #34); a bevy_text box whose lines are no finite size (an Apple bitmap-only face, which parley scales by a units-per-em of 0) measures 0 by 0, as bevy_text does; a family list ending in "raea-bevy fallback" (bevy_text's FontSource::Family) falls to the collection's fallback families, not to serif nor to the CoreText pick (parley: NO_HOOK_FAMILY); an out-of-flow box painted by the stacking context between it and its containing block, inside its opacity group (raea #39)"
exit = "a Blitz release with #1244/#1246 and these"
[parley_engine]