Truly independent web browser
LibCompositing: Derive every spatial walk from one local_transform
Aliaksandr Kalenikeb3d801df418
diff --git a/Libraries/LibCompositing/Rust/src/display_list/replay.rs b/Libraries/LibCompositing/Rust/src/display_list/replay.rsindex 15b486a5981..2812b4068f0 100644--- a/Libraries/LibCompositing/Rust/src/display_list/replay.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/replay.rs@@ -20,14 +20,14 @@ use crate::display_list::ffi_bytes::FfiBytes;use crate::display_list::nested_records::span_bytes;use crate::visual_context::queries::TreeCullingScratch;use crate::visual_context::{- ClipNodeData, ContextRef, EffectNodeData, SpatialData, SpatialNode, VisualContextTree, device_offset_for_index,+ ClipNodeData, ContextRef, EffectNodeData, ScrollSnap, SpatialData, VisualContextTree, device_offset_for_index,resolve_leaf_to_context_matrices, should_cull_back_face,};use libgfx_rust::filter::Filter;use libgfx_rust::path::Path;use libgfx_rust::{AffineTransform, Color, CornerRadii, FloatMatrix4x4, FloatPoint, FloatRect, FloatVector3, IntRect, WindingRule,- enclosing_int_rect, multiply_affine, translation_matrix,+ enclosing_int_rect, multiply_affine,};use std::cell::RefCell;@@ -375,21 +375,22 @@ fn int_rect_enclosing(rect: FloatRect) -> Option<IntRect> {// The cull state of the element that establishes the 3D rendering context rooted at root: the cull state of the// plane the context is flattened into.fn backface_culled_outside_sorting_context(- spatial_nodes: &[SpatialNode],+ tree: &VisualContextTree,backface_culled: &[bool],root: SpatialNodeIndex,) -> bool {- let mut index = root.0 as usize;+ let mut index = root;loop {- if let SpatialData::Transform(transform) = &spatial_nodes[index].data- && transform.establishes_sorting_context+ if tree+ .local_transform(index, &[], ScrollSnap::None)+ .establishes_sorting_context{- return backface_culled[index];+ return backface_culled[index.0 as usize];}- if index == 0 {+ if index.0 == 0 {return false;}- index = spatial_nodes[index].parent.0 as usize;+ index = tree.spatial_nodes[index.0 as usize].parent;}}@@ -400,101 +401,51 @@ fn fill_replay_palette_in_dependency_order(replay_base_matrix: FloatMatrix4x4,palette: &mut ReplayPaletteStorage,) {- let spatial_nodes = &tree.spatial_nodes;+ let node_count = tree.spatial_nodes.len();palette.to_root_matrices.clear();- palette.to_root_matrices.resize(spatial_nodes.len(), replay_base_matrix);+ palette.to_root_matrices.resize(node_count, replay_base_matrix);palette.local_matrices.clear();- palette- .local_matrices- .resize(spatial_nodes.len(), FloatMatrix4x4::identity());+ palette.local_matrices.resize(node_count, FloatMatrix4x4::identity());palette.draw_spaces.clear();palette.draw_spaces- .extend((0..spatial_nodes.len()).map(|index| SpatialNodeIndex(index as u32)));+ .extend((0..node_count).map(|index| SpatialNodeIndex(index as u32)));palette.backface_culled.clear();- palette.backface_culled.resize(spatial_nodes.len(), false);+ palette.backface_culled.resize(node_count, false);palette.flattens_inherited_transform.clear();- palette.flattens_inherited_transform.resize(spatial_nodes.len(), false);+ palette.flattens_inherited_transform.resize(node_count, false);for &index in spatial_dependency_order {let i = index as usize;- let node = &spatial_nodes[i];- let parent = node.parent.0 as usize;- let write_spatial =- |palette: &mut ReplayPaletteStorage, local_matrix: FloatMatrix4x4, flattens_inherited_transform: bool| {- let parent_matrix = if i == 0 {- replay_base_matrix- } else {- palette.to_root_matrices[parent]- };- let inherited = if flattens_inherited_transform {- parent_matrix.flattened()- } else {- parent_matrix- };- palette.to_root_matrices[i] = inherited.multiplied(local_matrix);- palette.local_matrices[i] = local_matrix;- palette.flattens_inherited_transform[i] = flattens_inherited_transform;- palette.draw_spaces[i] = SpatialNodeIndex(index);- palette.backface_culled[i] = if i == 0 { false } else { palette.backface_culled[parent] };- };- let write_spatial_translation = |palette: &mut ReplayPaletteStorage, offset: FloatPoint| {- // Whole device pixels, so scrolled content never lands on subpixel positions.- write_spatial(- palette,- translation_matrix(offset.x as i32 as f32, offset.y as i32 as f32, 0.0),- false,- );+ let parent = tree.spatial_nodes[i].parent.0 as usize;+ // Whole device pixels, so scrolled content never lands on subpixel positions.+ let local = tree.local_transform(SpatialNodeIndex(index), scroll_offsets, ScrollSnap::Truncate);+ let parent_matrix = if i == 0 {+ replay_base_matrix+ } else {+ palette.to_root_matrices[parent]};- match &node.data {- SpatialData::Transform(transform) => {- write_spatial(- palette,- transform.matrix_including_origin(),- transform.flattens_inherited_transform,- );- // https://drafts.csswg.org/css-transforms-2/#3d-rendering-contexts- // A participant in a 3D rendering context is its own plane, so the hidden backfaces of other planes in- // the context don't cull it. But a context is part of the content flattened into the plane its- // establishing element sits in, so whatever culls that plane culls the whole context: A participant- // starts from the cull state of the element that establishes its context. The spec doesn't yet say if a- // hidden backface culls the 3D rendering contexts nested in it:- // https://github.com/w3c/csswg-drafts/issues/918- if let Some(root) = transform.sorting_context_root_index {- palette.backface_culled[i] =- backface_culled_outside_sorting_context(spatial_nodes, &palette.backface_culled, root);- }- }- SpatialData::Perspective(perspective) => {- write_spatial(palette, perspective.matrix, perspective.flattens_inherited_transform);- }- SpatialData::BackfaceVisibility(backface) => {- let parent_matrix = palette.to_root_matrices[parent];- palette.to_root_matrices[i] = if backface.flattens_inherited_transform {- parent_matrix.flattened()- } else {- parent_matrix- };- palette.local_matrices[i] = FloatMatrix4x4::identity();- palette.flattens_inherited_transform[i] = backface.flattens_inherited_transform;- palette.draw_spaces[i] = palette.draw_spaces[parent];- let mut culled = palette.backface_culled[parent];- if !culled {- let plane_root_matrix = palette.to_root_matrices[backface.plane_root_index.0 as usize];- culled = should_cull_back_face(palette.to_root_matrices[i], plane_root_matrix);- }- palette.backface_culled[i] = culled;- }- SpatialData::Scroll(_) | SpatialData::Sticky(_) => {- write_spatial_translation(- palette,- device_offset_for_index(scroll_offsets, SpatialNodeIndex(index)),- );- }- SpatialData::AnchorScrollShift(shift) => {- write_spatial_translation(palette, shift.masked_offset(scroll_offsets));+ palette.to_root_matrices[i] = local.applied_to(parent_matrix);+ palette.local_matrices[i] = local.matrix;+ palette.flattens_inherited_transform[i] = local.flattens_inherited_transform;+ let mut culled = i != 0 && palette.backface_culled[parent];+ // https://drafts.csswg.org/css-transforms-2/#3d-rendering-contexts+ // A participant in a 3D rendering context is its own plane, so the hidden backfaces of other planes in the+ // context don't cull it. But a context is part of the content flattened into the plane its establishing+ // element sits in, so whatever culls that plane culls the whole context: A participant starts from the cull+ // state of the element that establishes its context. The spec doesn't yet say if a hidden backface culls the+ // 3D rendering contexts nested in it:+ // https://github.com/w3c/csswg-drafts/issues/918+ if let Some(root) = local.sorting_context_root {+ culled = backface_culled_outside_sorting_context(tree, &palette.backface_culled, root);+ }+ if let Some(plane_root) = local.backface_plane_root {+ palette.draw_spaces[i] = palette.draw_spaces[parent];+ if !culled {+ let plane_root_matrix = palette.to_root_matrices[plane_root.0 as usize];+ culled = should_cull_back_face(palette.to_root_matrices[i], plane_root_matrix);}- SpatialData::Dead => {}}+ palette.backface_culled[i] = culled;}}diff --git a/Libraries/LibCompositing/Rust/src/visual_context/mod.rs b/Libraries/LibCompositing/Rust/src/visual_context/mod.rsindex 28c8f3e8a97..b6411bde8bf 100644--- a/Libraries/LibCompositing/Rust/src/visual_context/mod.rs+++ b/Libraries/LibCompositing/Rust/src/visual_context/mod.rs@@ -247,9 +247,44 @@ pub enum IncludeVisualViewportTransform {Yes,}-struct LocalSpatialMatrix {- matrix: FloatMatrix4x4,- flattens_inherited_transform: bool,+#[derive(Clone, Copy, Debug, PartialEq, Eq)]+pub enum ScrollSnap {+ None,+ Truncate,+}++#[derive(Clone, Copy, Debug, PartialEq)]+pub enum LocalTransformKind {+ Identity,+ Translation(FloatPoint),+ Affine2D,+ Projective,+}++/// What one spatial node contributes to the spatial chains through it.+#[derive(Clone, Copy, Debug)]+pub struct LocalTransform {+ pub matrix: FloatMatrix4x4,+ pub flattens_inherited_transform: bool,+ pub kind: LocalTransformKind,+ pub establishes_sorting_context: bool,+ pub sorting_context_root: Option<SpatialNodeIndex>,+ pub backface_plane_root: Option<SpatialNodeIndex>,+}++impl LocalTransform {+ pub fn applied_to(&self, parent_matrix: FloatMatrix4x4) -> FloatMatrix4x4 {+ let inherited = if self.flattens_inherited_transform {+ parent_matrix.flattened()+ } else {+ parent_matrix+ };+ inherited.multiplied(self.matrix)+ }++ pub fn is_transform_or_perspective(&self) -> bool {+ matches!(self.kind, LocalTransformKind::Affine2D | LocalTransformKind::Projective)+ }}#[derive(Clone)]@@ -1181,33 +1216,63 @@ impl VisualContextTree {chain}- fn local_spatial_matrix(&self, index: SpatialNodeIndex, scroll_offsets: &[FloatPoint]) -> LocalSpatialMatrix {- let translation = |offset: FloatPoint| LocalSpatialMatrix {- matrix: translation_matrix(offset.x, offset.y, 0.0),+ pub fn local_transform(+ &self,+ index: SpatialNodeIndex,+ scroll_offsets: &[FloatPoint],+ scroll_snap: ScrollSnap,+ ) -> LocalTransform {+ let mut local = LocalTransform {+ matrix: FloatMatrix4x4::identity(),flattens_inherited_transform: false,+ kind: LocalTransformKind::Identity,+ establishes_sorting_context: false,+ sorting_context_root: None,+ backface_plane_root: None,+ };+ let translation = |offset: FloatPoint| {+ let offset = match scroll_snap {+ ScrollSnap::None => offset,+ ScrollSnap::Truncate => FloatPoint {+ x: offset.x as i32 as f32,+ y: offset.y as i32 as f32,+ },+ };+ (+ translation_matrix(offset.x, offset.y, 0.0),+ LocalTransformKind::Translation(offset),+ )};match &self.spatial_nodes[index.0 as usize].data {- SpatialData::Transform(transform) => LocalSpatialMatrix {- matrix: transform.matrix_including_origin(),- flattens_inherited_transform: transform.flattens_inherited_transform,- },- SpatialData::Perspective(perspective) => LocalSpatialMatrix {- matrix: perspective.matrix,- flattens_inherited_transform: perspective.flattens_inherited_transform,- },SpatialData::Scroll(_) | SpatialData::Sticky(_) => {- translation(device_offset_for_index(scroll_offsets, index))+ (local.matrix, local.kind) = translation(device_offset_for_index(scroll_offsets, index));}- SpatialData::AnchorScrollShift(shift) => translation(shift.masked_offset(scroll_offsets)),- SpatialData::BackfaceVisibility(backface) => LocalSpatialMatrix {- matrix: FloatMatrix4x4::identity(),- flattens_inherited_transform: backface.flattens_inherited_transform,- },- SpatialData::Dead => LocalSpatialMatrix {- matrix: FloatMatrix4x4::identity(),- flattens_inherited_transform: false,- },+ SpatialData::AnchorScrollShift(shift) => {+ (local.matrix, local.kind) = translation(shift.masked_offset(scroll_offsets));+ }+ SpatialData::Transform(transform) => {+ local.matrix = transform.matrix_including_origin();+ local.flattens_inherited_transform = transform.flattens_inherited_transform;+ local.kind = if transform.matrix.is_2d_affine() {+ LocalTransformKind::Affine2D+ } else {+ LocalTransformKind::Projective+ };+ local.establishes_sorting_context = transform.establishes_sorting_context;+ local.sorting_context_root = transform.sorting_context_root_index;+ }+ SpatialData::Perspective(perspective) => {+ local.matrix = perspective.matrix;+ local.flattens_inherited_transform = perspective.flattens_inherited_transform;+ local.kind = LocalTransformKind::Projective;+ }+ SpatialData::BackfaceVisibility(backface) => {+ local.flattens_inherited_transform = backface.flattens_inherited_transform;+ local.backface_plane_root = Some(backface.plane_root_index);+ }+ SpatialData::Dead => {}}+ local}pub fn accumulated_matrix(@@ -1224,13 +1289,9 @@ impl VisualContextTree {{continue;}- let local = self.local_spatial_matrix(node_index, scroll_offsets);- let inherited = if local.flattens_inherited_transform {- matrix.flattened()- } else {- matrix- };- matrix = inherited.multiplied(local.matrix);+ matrix = self+ .local_transform(node_index, scroll_offsets, ScrollSnap::None)+ .applied_to(matrix);}matrix}diff --git a/Libraries/LibCompositing/Rust/src/visual_context/queries.rs b/Libraries/LibCompositing/Rust/src/visual_context/queries.rsindex ae611b64d95..f40f938ca23 100644--- a/Libraries/LibCompositing/Rust/src/visual_context/queries.rs+++ b/Libraries/LibCompositing/Rust/src/visual_context/queries.rs@@ -6,8 +6,8 @@use super::{ClipData, ClipMode, ClipNode, ClipNodeData, ClipNodeIndex, ContextRef, EffectNodeData, EffectNodeIndex,- IncludeVisualViewportTransform, SpatialData, SpatialNodeIndex, TransformDataRole, VISUAL_VIEWPORT_NODE_INDEX,- VisualContextTree, device_offset_for_index,+ IncludeVisualViewportTransform, LocalTransform, LocalTransformKind, ScrollSnap, SpatialData, SpatialNodeIndex,+ TransformDataRole, VISUAL_VIEWPORT_NODE_INDEX, VisualContextTree, device_offset_for_index,};use ak::math;use libgfx_rust::{@@ -139,32 +139,23 @@ impl VisualContextTree {fn chain_contains_3d_transform(&self, index: SpatialNodeIndex) -> bool {let mut current = index;loop {- let node = &self.spatial_nodes[current.0 as usize];- match &node.data {- SpatialData::Transform(transform) => {- if !transform.matrix.is_2d_affine() {- return true;- }- }- SpatialData::Perspective(_) => return true,- _ => {}+ if self.local_transform(current, &[], ScrollSnap::None).kind == LocalTransformKind::Projective {+ return true;}if current == VISUAL_VIEWPORT_NODE_INDEX {- break;+ return false;}- current = node.parent;+ current = self.spatial_nodes[current.0 as usize].parent;}- false}fn begin_hit_test_walk(&self, leaf: SpatialNodeIndex, screen_point: FloatPoint) -> SpatialChainWalk {let mut chain = self.ancestor_chain(leaf);chain.reverse();let chain_has_backface_marker = chain.iter().any(|index| {- matches!(- self.spatial_nodes[index.0 as usize].data,- SpatialData::BackfaceVisibility(_)- )+ self.local_transform(*index, &[], ScrollSnap::None)+ .backface_plane_root+ .is_some()});let has_3d_transform = self.chain_contains_3d_transform(leaf);let needs_accumulated_matrices = chain_has_backface_marker || has_3d_transform;@@ -192,22 +183,15 @@ impl VisualContextTree {screen_point: FloatPoint,scroll_offsets: &[FloatPoint],) -> bool {- let node_index = walk.chain[position];- let node = &self.spatial_nodes[node_index.0 as usize];+ let local = self.local_transform(walk.chain[position], scroll_offsets, ScrollSnap::None);if walk.needs_accumulated_matrices {- let local = self.local_spatial_matrix(node_index, scroll_offsets);- if position == 0 {- walk.accumulated_matrices.push(local.matrix);- } else {- let parent_matrix = *walk.accumulated_matrices.last().expect("walk has a parent matrix");- let inherited = if local.flattens_inherited_transform {- parent_matrix.flattened()- } else {- parent_matrix- };- walk.accumulated_matrices.push(inherited.multiplied(local.matrix));- }+ let parent_matrix = walk+ .accumulated_matrices+ .last()+ .copied()+ .unwrap_or(FloatMatrix4x4::identity());+ walk.accumulated_matrices.push(local.applied_to(parent_matrix));}// https://drafts.csswg.org/css-transforms-2/#3d-rendering-contexts@@ -215,93 +199,55 @@ impl VisualContextTree {// whatever culls the plane its context is flattened into. The spec doesn't yet say if a hidden backface culls// the 3D rendering contexts nested in it:// https://github.com/w3c/csswg-drafts/issues/918- if let SpatialData::Transform(transform) = &node.data {- if transform.establishes_sorting_context {- walk.culled_outside_sorting_context = walk.culled;- } else if transform.sorting_context_root_index.is_some() {- walk.culled = walk.culled_outside_sorting_context;+ if local.establishes_sorting_context {+ walk.culled_outside_sorting_context = walk.culled;+ } else if local.sorting_context_root.is_some() {+ walk.culled = walk.culled_outside_sorting_context;+ }++ if let Some(plane_root) = local.backface_plane_root {+ if !walk.culled {+ let plane_root_position = walk+ .chain+ .iter()+ .position(|index| *index == plane_root)+ .expect("the plane root precedes the backface marker on its root path");+ walk.culled = should_cull_back_face(+ *walk+ .accumulated_matrices+ .last()+ .expect("backface walk accumulates matrices"),+ walk.accumulated_matrices[plane_root_position],+ );}+ return true;}- if walk.has_3d_transform && !matches!(node.data, SpatialData::BackfaceVisibility(_)) {- let Some(inverse) = walk- .accumulated_matrices- .last()- .expect("3D walk accumulates matrices")- .flattened()- .inverse()- else {- return false;- };- let mapped = inverse.map_vector4([screen_point.x, screen_point.y, 0.0, 1.0]);- if mapped[3] < MINIMUM_PROJECTION_W {+ if !walk.has_3d_transform {+ let Some(inverse) = local.matrix.extract_2d_affine().inverse() else {return false;- }- walk.point = FloatPoint {- x: mapped[0] / mapped[3],- y: mapped[1] / mapped[3],};+ walk.point = inverse.map_point(walk.point);return true;}-- match &node.data {- SpatialData::Perspective(perspective) => {- let Some(inverse) = perspective.matrix.extract_2d_affine().inverse() else {- return false;- };- walk.point = inverse.map_point(walk.point);- true- }- SpatialData::BackfaceVisibility(backface) => {- if !walk.culled {- let plane_root_position = walk- .chain- .iter()- .position(|index| *index == backface.plane_root_index)- .expect("the plane root precedes the backface marker on its root path");- walk.culled = should_cull_back_face(- *walk- .accumulated_matrices- .last()- .expect("backface walk accumulates matrices"),- walk.accumulated_matrices[plane_root_position],- );- }- true- }- SpatialData::Scroll(_) | SpatialData::Sticky(_) => {- let offset = device_offset_for_index(scroll_offsets, node_index);- walk.point = FloatPoint {- x: walk.point.x - offset.x,- y: walk.point.y - offset.y,- };- true- }- SpatialData::Transform(transform) => {- let Some(inverse) = transform.matrix.extract_2d_affine().inverse() else {- return false;- };- let offset_point = FloatPoint {- x: walk.point.x - transform.origin.x,- y: walk.point.y - transform.origin.y,- };- let transformed = inverse.map_point(offset_point);- walk.point = FloatPoint {- x: transformed.x + transform.origin.x,- y: transformed.y + transform.origin.y,- };- true- }- SpatialData::AnchorScrollShift(shift) => {- let offset = shift.masked_offset(scroll_offsets);- walk.point = FloatPoint {- x: walk.point.x - offset.x,- y: walk.point.y - offset.y,- };- true- }- SpatialData::Dead => true,+ let Some(inverse) = walk+ .accumulated_matrices+ .last()+ .expect("3D walk accumulates matrices")+ .flattened()+ .inverse()+ else {+ return false;+ };+ let mapped = inverse.map_vector4([screen_point.x, screen_point.y, 0.0, 1.0]);+ if mapped[3] < MINIMUM_PROJECTION_W {+ return false;}+ walk.point = FloatPoint {+ x: mapped[0] / mapped[3],+ y: mapped[1] / mapped[3],+ };+ true}fn apply_hit_test_spatial_steps_through_node(@@ -371,10 +317,9 @@ impl VisualContextTree {return true;}- match &node.data {- SpatialData::Transform(transform) if transform.matrix != FloatMatrix4x4::identity() => return false,- SpatialData::Perspective(_) => return false,- _ => {}+ let local = self.local_transform(spatial_node_index, &[], ScrollSnap::None);+ if local.is_transform_or_perspective() && local.matrix != FloatMatrix4x4::identity() {+ return false;}spatial_node_index = node.parent;@@ -438,29 +383,13 @@ impl VisualContextTree {// themselves. The per-node inverses below are only exact for chains of 2D transforms, so a chain containing a// 3D transform inverts the flattened accumulated matrix, mapping the screen point onto the plane the content// was rendered into.+ let transforms = chain+ .iter()+ .rev()+ .map(|node_index| self.local_transform(*node_index, &[], ScrollSnap::None))+ .filter(LocalTransform::is_transform_or_perspective);if self.chain_contains_3d_transform(index) {- let mut matrix = FloatMatrix4x4::identity();- for node_index in chain.iter().rev() {- match &self.spatial_nodes[node_index.0 as usize].data {- SpatialData::Transform(transform) => {- let inherited = if transform.flattens_inherited_transform {- matrix.flattened()- } else {- matrix- };- matrix = inherited.multiplied(transform.matrix_including_origin());- }- SpatialData::Perspective(perspective) => {- let inherited = if perspective.flattens_inherited_transform {- matrix.flattened()- } else {- matrix- };- matrix = inherited.multiplied(perspective.matrix);- }- _ => {}- }- }+ let matrix = transforms.fold(FloatMatrix4x4::identity(), |matrix, local| local.applied_to(matrix));let Some(inverse) = matrix.flattened().inverse() else {return screen_point;};@@ -473,33 +402,13 @@ impl VisualContextTree {y: mapped[1] / mapped[3],};}-- let mut point = screen_point;- for node_index in chain.iter().rev() {- match &self.spatial_nodes[node_index.0 as usize].data {- SpatialData::Perspective(perspective) => {- if let Some(inverse) = perspective.matrix.extract_2d_affine().inverse() {- point = inverse.map_point(point);- }- }- SpatialData::Transform(transform) => {- if let Some(inverse) = transform.matrix.extract_2d_affine().inverse() {- let offset_point = FloatPoint {- x: point.x - transform.origin.x,- y: point.y - transform.origin.y,- };- let transformed = inverse.map_point(offset_point);- point = FloatPoint {- x: transformed.x + transform.origin.x,- y: transformed.y + transform.origin.y,- };- }- }- _ => {}- }- }-- point+ transforms.fold(screen_point, |point, local| {+ local+ .matrix+ .extract_2d_affine()+ .inverse()+ .map_or(point, |inverse| inverse.map_point(point))+ })}pub fn transform_rect_to_viewport(@@ -525,26 +434,11 @@ impl VisualContextTree {if current != VISUAL_VIEWPORT_NODE_INDEX|| include_visual_viewport_transform == IncludeVisualViewportTransform::Yes{- match &node.data {- SpatialData::Transform(transform) => {- let affine = transform.matrix.extract_2d_affine();- rect = rect.translated(-transform.origin.x, -transform.origin.y);- rect = affine.map_rect(rect);- rect = rect.translated(transform.origin.x, transform.origin.y);- }- SpatialData::Perspective(perspective) => {- rect = perspective.matrix.extract_2d_affine().map_rect(rect);- }- SpatialData::Scroll(_) | SpatialData::Sticky(_) => {- let offset = device_offset_for_index(scroll_offsets, current);- rect = rect.translated(offset.x, offset.y);- }- SpatialData::AnchorScrollShift(shift) => {- let offset = shift.masked_offset(scroll_offsets);- rect = rect.translated(offset.x, offset.y);- }- SpatialData::BackfaceVisibility(_) | SpatialData::Dead => {}- }+ rect = self+ .local_transform(current, scroll_offsets, ScrollSnap::None)+ .matrix+ .extract_2d_affine()+ .map_rect(rect);}if current == VISUAL_VIEWPORT_NODE_INDEX {break;@@ -565,18 +459,13 @@ impl VisualContextTree {let mut offset = FloatPoint::default();let mut current = index;while current != VISUAL_VIEWPORT_NODE_INDEX {- let node = &self.spatial_nodes[current.0 as usize];- let node_offset = match &node.data {- SpatialData::Scroll(_) | SpatialData::Sticky(_) => device_offset_for_index(scroll_offsets, current),- SpatialData::AnchorScrollShift(shift) => shift.masked_offset(scroll_offsets),- SpatialData::Transform(_)- | SpatialData::Perspective(_)- | SpatialData::BackfaceVisibility(_)- | SpatialData::Dead => FloatPoint::default(),- };- offset.x += node_offset.x;- offset.y += node_offset.y;- current = node.parent;+ if let LocalTransformKind::Translation(node_offset) =+ self.local_transform(current, scroll_offsets, ScrollSnap::None).kind+ {+ offset.x += node_offset.x;+ offset.y += node_offset.y;+ }+ current = self.spatial_nodes[current.0 as usize].parent;}offset}@@ -849,7 +738,7 @@ impl VisualContextTree {let radius = math::hypot(dx, dy);rect = FloatRect::new(origin.x - radius, origin.y - radius, 2.0 * radius, 2.0 * radius);} else {- let matrix = self.local_spatial_matrix(index, scroll_offsets).matrix;+ let matrix = self.local_transform(index, scroll_offsets, ScrollSnap::None).matrix;// Projecting a rectangle at each ancestor would discard depth needed by later 3D transforms.if !matrix.is_2d_affine() {return None;