Truly independent web browser
LibCompositing: Damage and cull by where own-space inline clips are
Andreas Klinga6a35cc225b1
diff --git a/Libraries/LibCompositing/Rust/src/display_list/builder.rs b/Libraries/LibCompositing/Rust/src/display_list/builder.rsindex 6e2de168fca..01da6922e9f 100644--- a/Libraries/LibCompositing/Rust/src/display_list/builder.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/builder.rs@@ -612,6 +612,17 @@ pub fn inline_clips_of<'a>(.map(|entry| read_command::<DisplayListInlineClip>(entry))}+/// Whether one of the inline clips of a record applies in a space of its own, read without decoding the clips.+pub fn has_inline_clip_in_its_own_space(header: &DisplayListCommandHeader, payload: &[u8]) -> bool {+ let count = usize::from(header.inline_clip_count);+ let entries = &payload[payload.len() - count * INLINE_CLIP_ENTRY_SIZE..];+ entries+ .as_chunks::<INLINE_CLIP_ENTRY_SIZE>()+ .0+ .iter()+ .any(|entry| entry[std::mem::offset_of!(DisplayListInlineClip, has_own_space)] != 0)+}+pub fn read_header(bytes: &[u8]) -> DisplayListCommandHeader {assert!(bytes.len() >= HEADER_SIZE);let cursor = HeaderReader { bytes };diff --git a/Libraries/LibCompositing/Rust/src/display_list/damage.rs b/Libraries/LibCompositing/Rust/src/display_list/damage.rsindex 94b865e55f4..0a7a44283dd 100644--- a/Libraries/LibCompositing/Rust/src/display_list/damage.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/damage.rs@@ -6,9 +6,11 @@use super::effect_clip_plan::EffectClipPlan;use super::effect_geometry::{Extent, SpaceMatrices, changed_extent_through_filters, nearest_spreading_effects};+use super::replay::{OwnSpaceClipExtent, own_space_clip_extent};use super::summary::{DisplayListSummary, LiveContent};use crate::display_list::builder::{- HEADER_SIZE, for_each_command, inline_clips_of, inline_transform_entry_offset, read_command, read_header,+ HEADER_SIZE, for_each_command, has_inline_clip_in_its_own_space, inline_clips_of, inline_transform_entry_offset,+ read_command, read_header,};use crate::display_list::commands::{CanvasId, ClipMode, ClipNodeIndex, CompositorScrollbar, ContextRef, DeclareMaskContent, DisplayListCommandHeader,@@ -490,6 +492,33 @@ impl SpaceMatrices for TreeSpaces<'_> {}}+// Where a command's inline clips in spaces of their own let it draw on one side of the comparison.+fn own_space_clip_extent_on(command: &CommandReference<'_>, side: TreeSide<'_>) -> Option<OwnSpaceClipExtent> {+ if command.header.inline_clip_count == 0+ || !command.header.has_bounding_rect+ || !has_inline_clip_in_its_own_space(&command.header, command.payload)+ {+ return None;+ }+ let mut to_root_matrices = side.filter_spreading.to_root_matrices.borrow_mut();+ let mut spaces = TreeSpaces {+ tree: side.tree,+ scroll_offsets: side.scroll_offsets,+ to_root_matrices: &mut to_root_matrices,+ };+ let mut to_root = |space: SpatialNodeIndex| {+ ((space.0 as usize) < side.tree.spatial_nodes.len()).then(|| spaces.to_root_matrix(space))+ };+ let command_to_root = to_root(command.context.spatial)?;+ own_space_clip_extent(+ &command.header,+ command.payload,+ command.header.bounding_rect.to_float(),+ command_to_root,+ to_root,+ )+}+// One side of the comparison, as command damage needs it.#[derive(Clone, Copy)]struct TreeSide<'b> {@@ -835,7 +864,15 @@ impl DamageAccumulator {if !command.header.has_bounding_rect {return;}- self.add_changed_content_damage(command.header.bounding_rect.to_float(), context, side);+ // The bounds of a command leave out its inline clips in spaces of their own, so they limit it here.+ let rect = match own_space_clip_extent_on(command, side) {+ Some(OwnSpaceClipExtent::Within(rect)) => rect,+ _ => command.header.bounding_rect.to_float(),+ };+ if rect.is_empty() {+ return;+ }+ self.add_changed_content_damage(rect, context, side);}// Damage for content drawn within `rect` in `context` that changed, wherever the filters above@@ -1031,17 +1068,27 @@ impl DamageAccumulator {}// A command that draws in a different space than one of its inline clips shows another part of- // itself whenever one of the two spaces scrolls, though neither the command nor its context changed.+ // itself whenever one of the two spaces moves, though neither the command nor its context changed.+ // Where the clips can be mapped into the command's space, command damage covers only what they let it draw.fn add_inline_clip_scroll_damage(&mut self,chains: &TreeChainComparison<'_>,old_command: &CommandReference<'_>,new_command: &CommandReference<'_>,) {- let has_inline_clip_in_its_own_space = |command: &CommandReference<'_>| {- inline_clips_of(&command.header, command.payload).any(|clip| clip.has_own_space)+ if old_command.header.inline_clip_count == 0 && new_command.header.inline_clip_count == 0 {+ return;+ }+ let old_extent = own_space_clip_extent_on(old_command, chains.old_side());+ let new_extent = own_space_clip_extent_on(new_command, chains.new_side());+ let clips_did_not_move = match (old_extent, new_extent) {+ (None, None) => true,+ (Some(OwnSpaceClipExtent::Within(old_rect)), Some(OwnSpaceClipExtent::Within(new_rect))) => {+ old_rect == new_rect+ }+ _ => false,};- if !has_inline_clip_in_its_own_space(old_command) && !has_inline_clip_in_its_own_space(new_command) {+ if clips_did_not_move {return;}self.add_old_command_damage(chains, old_command);@@ -1087,9 +1134,10 @@ impl DamageAccumulator {new_run: &DisplayListCommandRun,verdict: ContextPairVerdict,scroll_offsets_differ: bool,+ inline_clip_spaces_may_have_moved: bool,) {let commands_moved = !verdict.equal;- if !commands_moved && !scroll_offsets_differ {+ if !commands_moved && !scroll_offsets_differ && !inline_clip_spaces_may_have_moved {return;}for_each_command(chains.old_tape.run_bytes(old_run), |header, _, payload| {@@ -1111,6 +1159,8 @@ impl DamageAccumulator {}if scroll_offsets_differ {self.add_scrollbar_scroll_damage(chains, &old_command, &new_command);+ }+ if inline_clip_spaces_may_have_moved {self.add_inline_clip_scroll_damage(chains, &old_command, &new_command);}});@@ -1123,6 +1173,7 @@ impl DamageAccumulator {old_commands: &[CommandReference<'_>],new_commands: &[CommandReference<'_>],scroll_offsets_differ: bool,+ inline_clip_spaces_may_have_moved: bool,) {let common_length = old_commands.len().min(new_commands.len());let mut common_prefix_length = 0;@@ -1147,6 +1198,8 @@ impl DamageAccumulator {damage.add_visual_context_damage(chains, old_command, new_command);if scroll_offsets_differ {damage.add_scrollbar_scroll_damage(chains, old_command, new_command);+ }+ if inline_clip_spaces_may_have_moved {damage.add_inline_clip_scroll_damage(chains, old_command, new_command);}};@@ -1314,11 +1367,25 @@ pub fn animated_content_may_affect_viewport(runs: command_runs,};for run in command_runs {- for_each_command(tape.run_bytes(run), |header, _, _| {+ for_each_command(tape.run_bytes(run), |header, _, payload| {if may_affect_viewport || header.command_type.is_compositor_metadata() {return;}let spatial_is_animated = in_rotating_subtree[run.context.spatial.0 as usize];+ let has_inline_clip_in_its_own_space =+ header.inline_clip_count != 0 && has_inline_clip_in_its_own_space(header, payload);+ if has_inline_clip_in_its_own_space+ && !spatial_is_animated+ && inline_clips_of(header, payload).any(|inline_clip| {+ inline_clip.has_own_space+ && in_rotating_subtree+ .get(inline_clip.space.0 as usize)+ .is_none_or(|is_animated| *is_animated)+ })+ {+ may_affect_viewport = true;+ return;+ }let mut clip = run.context.clip;while !clip.is_none() {let node = &tree.clip_nodes[clip.0 as usize];@@ -1353,13 +1420,25 @@ pub fn animated_content_may_affect_viewport(may_affect_viewport = true;return;}- let rect = header.bounding_rect;- let Some(bounds) = tree.rect_with_rotation_bounds_to_viewport(- run.context.spatial,- FloatRect::new(rect.x as f32, rect.y as f32, rect.width as f32, rect.height as f32),- &rotating_nodes,- scroll_offsets,- ) else {+ let mut rect = header.bounding_rect.to_float();+ if has_inline_clip_in_its_own_space && header.has_bounding_rect {+ let to_root = |space: SpatialNodeIndex| {+ ((space.0 as usize) < tree.spatial_nodes.len())+ .then(|| tree.accumulated_matrix(space, scroll_offsets, IncludeVisualViewportTransform::Yes))+ };+ if let Some(command_to_root) = to_root(run.context.spatial)+ && let Some(OwnSpaceClipExtent::Within(clipped_rect)) =+ own_space_clip_extent(header, payload, rect, command_to_root, to_root)+ {+ if clipped_rect.is_empty() {+ return;+ }+ rect = clipped_rect;+ }+ }+ let Some(bounds) =+ tree.rect_with_rotation_bounds_to_viewport(run.context.spatial, rect, &rotating_nodes, scroll_offsets)+ else {may_affect_viewport = true;return;};@@ -1468,6 +1547,10 @@ pub fn compute_display_list_damage(new_filter_spreading: FilterSpreading::default(),};let scroll_offsets_differ = old_scroll_offsets != new_scroll_offsets;+ // NB: An inline clip in a space of its own names its space by index, which a new tree can give to another node,+ // so a new tree can move the clip as much as a scroll can.+ let inline_clip_spaces_may_have_moved =+ scroll_offsets_differ || !std::ptr::eq(old_visual_context_tree, new_visual_context_tree);let max_common_run_count = old_command_runs.len().min(new_command_runs.len());let mut identical_prefix_verdicts = Vec::with_capacity(max_common_run_count);@@ -1511,7 +1594,14 @@ pub fn compute_display_list_damage(if damage.covers_viewport() {break;}- damage.add_identical_run_damage(&chains, old_run, new_run, *verdict, scroll_offsets_differ);+ damage.add_identical_run_damage(+ &chains,+ old_run,+ new_run,+ *verdict,+ scroll_offsets_differ,+ inline_clip_spaces_may_have_moved,+ );}if !damage.covers_viewport() {@@ -1524,7 +1614,13 @@ pub fn compute_display_list_damage(old_tape.collect_commands_of_runs(old_middle_runs, &mut old_commands);let mut new_commands = Vec::new();new_tape.collect_commands_of_runs(new_middle_runs, &mut new_commands);- damage.add_command_diff_damage(&chains, &old_commands, &new_commands, scroll_offsets_differ);+ damage.add_command_diff_damage(+ &chains,+ &old_commands,+ &new_commands,+ scroll_offsets_differ,+ inline_clip_spaces_may_have_moved,+ );}}@@ -2238,7 +2334,15 @@ mod tests {#[test]fn changed_scroll_offset_damages_a_draw_with_an_inline_clip_in_another_space() {- let tree = identity_tree();+ let mut tree = identity_tree();+ let scroll = tree.append_spatial(+ SpatialData::Scroll(ScrollData {+ state_slot: 1,+ owner_paintable: NodeSlotId::INVALID,+ registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,+ }),+ VISUAL_VIEWPORT_NODE_INDEX,+ );let rect = IntRect::new(10, 10, 20, 20);let draw_with_clip = |clip: DisplayListInlineClip| {let mut display_list = TestDisplayList::default();@@ -2269,17 +2373,246 @@ mod tests {)};+ let clip_in_space = |space: SpatialNodeIndex| DisplayListInlineClip {+ has_own_space: true,+ space,+ ..rect_inline_clip(rect)+ };+assert!(damage_after_scroll(&draw_with_clip(rect_inline_clip(rect))).is_none_or(|damage| damage.is_empty()));+ // A clip whose space does not move with the scroll leaves the draw as it was.+ assert!(+ damage_after_scroll(&draw_with_clip(clip_in_space(VISUAL_VIEWPORT_NODE_INDEX)))+ .is_none_or(|damage| damage.is_empty())+ );+ // The scroll moves the clip off the draw, so only where it was changes.+ assert_eq!(+ damage_after_scroll(&draw_with_clip(clip_in_space(scroll))),+ Some(IntRect::new(9, 9, 22, 22))+ );+ // A partial move changes only the part of the draw that the clip uncovers or covers.+ let damage_after_small_scroll = |display_list: &TestDisplayList| {+ damage_with_scroll_offsets(+ display_list,+ &tree,+ &[FloatPoint::default(), FloatPoint::default()],+ display_list,+ &tree,+ &[FloatPoint::default(), FloatPoint { x: 0.0, y: -5.0 }],+ IntRect::new(0, 0, 100, 100),+ )+ };+ let small_scroll_damage = damage_after_small_scroll(&draw_with_clip(DisplayListInlineClip {+ has_own_space: true,+ space: scroll,+ ..rect_inline_clip(IntRect::new(10, 10, 20, 5))+ }));+ assert!(small_scroll_damage.is_some_and(|damage| damage.height < 22 && !damage.is_empty()));+ }++ #[test]+ fn moving_an_inline_clip_to_another_space_damages_its_draw() {+ let mut tree = identity_tree();+ let scroll = tree.append_spatial(+ SpatialData::Scroll(ScrollData {+ state_slot: 1,+ owner_paintable: NodeSlotId::INVALID,+ registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,+ }),+ VISUAL_VIEWPORT_NODE_INDEX,+ );+ let rect = IntRect::new(10, 10, 20, 20);+ let draw_with_clip_in = |space: SpatialNodeIndex, color: Color| {+ let mut display_list = TestDisplayList::default();+ append_record(+ &mut display_list,+ &FillRect {+ rect,+ color,+ compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,+ background_color_animation_effect: EffectNodeIndex::NONE,+ },+ &[],+ Some(rect),+ ContextRef::default(),+ &[DisplayListInlineClip {+ has_own_space: true,+ space,+ ..rect_inline_clip(rect)+ }],+ );+ display_list+ };+ let scrolled = [FloatPoint::default(), FloatPoint { x: 0.0, y: -40.0 }];+ let damage_between = |old: &TestDisplayList, new: &TestDisplayList| {+ damage_with_scroll_offsets(+ old,+ &tree,+ &scrolled,+ new,+ &tree,+ &scrolled,+ IntRect::new(0, 0, 100, 100),+ )+ };+ assert!(+ damage_between(+ &draw_with_clip_in(VISUAL_VIEWPORT_NODE_INDEX, RED),+ &draw_with_clip_in(VISUAL_VIEWPORT_NODE_INDEX, RED)+ )+ .is_none_or(|damage| damage.is_empty())+ );assert_eq!(- damage_after_scroll(&draw_with_clip(DisplayListInlineClip {+ damage_between(+ &draw_with_clip_in(VISUAL_VIEWPORT_NODE_INDEX, RED),+ &draw_with_clip_in(scroll, RED)+ ),+ Some(IntRect::new(9, 9, 22, 22))+ );+ }++ #[test]+ fn a_new_tree_that_moves_the_space_of_an_inline_clip_damages_its_draw() {+ let mut old_tree = identity_tree();+ let old_space = old_tree.append_spatial(+ SpatialData::Transform(transform(FloatMatrix4x4::identity())),+ VISUAL_VIEWPORT_NODE_INDEX,+ );+ // The new tree gives the index of the clip's space to a node that sits elsewhere.+ let mut new_tree = identity_tree();+ let new_space = new_tree.append_spatial(+ SpatialData::Transform(transform(translation_matrix(0.0, 40.0, 0.0))),+ VISUAL_VIEWPORT_NODE_INDEX,+ );+ assert_eq!(old_space, new_space);+ let rect = IntRect::new(10, 10, 20, 20);+ let mut display_list = TestDisplayList::default();+ append_record(+ &mut display_list,+ &FillRect {+ rect,+ color: RED,+ compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,+ background_color_animation_effect: EffectNodeIndex::NONE,+ },+ &[],+ Some(rect),+ ContextRef::default(),+ &[DisplayListInlineClip {has_own_space: true,- space: SpatialNodeIndex(1),+ space: old_space,..rect_inline_clip(rect)- })),+ }],+ );+ let offsets = [FloatPoint::default()];+ let viewport = IntRect::new(0, 0, 100, 100);+ assert!(+ damage_with_scroll_offsets(+ &display_list,+ &old_tree,+ &offsets,+ &display_list,+ &old_tree,+ &offsets,+ viewport+ )+ .is_none_or(|damage| damage.is_empty())+ );+ assert_eq!(+ damage_with_scroll_offsets(+ &display_list,+ &old_tree,+ &offsets,+ &display_list,+ &new_tree,+ &offsets,+ viewport+ ),Some(IntRect::new(9, 9, 22, 22)));}+ #[test]+ fn animated_content_follows_inline_clips_in_spaces_of_their_own() {+ let mut tree = identity_tree();+ let scroll = tree.append_spatial(+ SpatialData::Scroll(ScrollData {+ state_slot: 1,+ owner_paintable: NodeSlotId::INVALID,+ registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,+ }),+ VISUAL_VIEWPORT_NODE_INDEX,+ );+ let rotating = tree.append_spatial(+ SpatialData::Transform(transform(FloatMatrix4x4::identity())),+ VISUAL_VIEWPORT_NODE_INDEX,+ );+ let effect = tree.append_effect(+ EffectNodeData::Effects(EffectsData {+ isolation: false,+ opacity: 0.5,+ blend_mode: CompositingAndBlendingOperator::Normal,+ filter: None,+ backdrop_filter: None,+ }),+ EffectNodeIndex::NONE,+ VISUAL_VIEWPORT_NODE_INDEX,+ ClipNodeIndex::NONE,+ );+ let viewport = IntRect::new(0, 0, 800, 600);+ let draw_clipped_to = |clip_space: SpatialNodeIndex, clip_rect: IntRect, context: ContextRef| {+ let mut display_list = TestDisplayList::default();+ append_record(+ &mut display_list,+ &FillRect {+ rect: viewport,+ color: RED,+ compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,+ background_color_animation_effect: EffectNodeIndex::NONE,+ },+ &[],+ Some(viewport),+ context,+ &[DisplayListInlineClip {+ has_own_space: true,+ space: clip_space,+ ..rect_inline_clip(clip_rect)+ }],+ );+ display_list+ };+ let may_affect_viewport = |display_list: &TestDisplayList, rotation_nodes: &[SpatialNodeIndex]| {+ animated_content_may_affect_viewport(+ display_list,+ &display_list.runs,+ &tree,+ &[FloatPoint::default(), FloatPoint::default()],+ rotation_nodes,+ &[effect],+ viewport,+ )+ };+ let faded = ContextRef {+ effect,+ ..ContextRef::default()+ };++ // An animated opacity only affects the viewport where the clip lets the draw show.+ let box_on_screen = IntRect::new(0, 10, 10, 10);+ let box_off_screen = IntRect::new(0, 2000, 10, 10);+ assert!(may_affect_viewport(&draw_clipped_to(scroll, box_on_screen, faded), &[]));+ assert!(!may_affect_viewport(+ &draw_clipped_to(scroll, box_off_screen, faded),+ &[]+ ));++ // A clip in a rotating space moves the draw it clips, though the draw's own space stands still.+ assert!(may_affect_viewport(+ &draw_clipped_to(rotating, box_on_screen, ContextRef::default()),+ &[rotating]+ ));+ }+#[test]fn inactive_optional_storage_does_not_damage_scaled_images() {let tree = identity_tree();diff --git a/Libraries/LibCompositing/Rust/src/display_list/replay.rs b/Libraries/LibCompositing/Rust/src/display_list/replay.rsindex be0048d7ec2..0312aac2e82 100644--- a/Libraries/LibCompositing/Rust/src/display_list/replay.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/replay.rs@@ -4,10 +4,12 @@* SPDX-License-Identifier: BSD-2-Clause*/-use crate::display_list::builder::{for_each_command, inline_clips_of, inline_transform_of, read_command};+use crate::display_list::builder::{+ for_each_command, has_inline_clip_in_its_own_space, inline_clips_of, inline_transform_of, read_command,+};use crate::display_list::commands::{- ClipNodeIndex, DisplayListCommandRun, DisplayListCommandType, EffectNodeIndex, InlineClipKind, OptionalFloatRect,- PaintScrollBar, ReplayClip, ReplayLayer, ReplayMask, SpatialNodeIndex,+ ClipMode, ClipNodeIndex, DisplayListCommandHeader, DisplayListCommandRun, DisplayListCommandType, EffectNodeIndex,+ InlineClipKind, OptionalFloatRect, PaintScrollBar, ReplayClip, ReplayLayer, ReplayMask, SpatialNodeIndex,};use crate::display_list::depth_sorted_plan::{DepthSortedReplayStepKind, build_depth_sorted_replay_plan};use crate::display_list::effect_clip_plan::EffectClipPlan;@@ -22,7 +24,7 @@ use crate::visual_context::{use libgfx_rust::path::Path;use libgfx_rust::{AffineTransform, Color, CornerRadii, FloatMatrix4x4, FloatPoint, FloatRect, FloatVector3, IntRect, WindingRule,- enclosing_int_rect, translation_matrix,+ enclosing_int_rect, multiply_affine, translation_matrix,};use std::cell::RefCell;@@ -55,6 +57,48 @@ pub trait ReplayPainter {}}+/// How far the inline clips of a command that apply in spaces of their own let it draw.+#[derive(Clone, Copy, Debug, PartialEq)]+pub(crate) enum OwnSpaceClipExtent {+ /// One of the clips cannot be mapped into the space of the command, or cuts a hole out of it.+ Unbounded,+ /// Within this rect, in the space of the command.+ Within(FloatRect),+}++/// The part of `bounds`, in the space of a command whose to-root matrix is `command_to_root`, that its inline clips+/// in spaces of their own leave the command to draw in, or None if it has no such clip. `clip_space_matrix` gives+/// the to-root matrix of a clip's space.+pub(crate) fn own_space_clip_extent(+ header: &DisplayListCommandHeader,+ payload: &[u8],+ bounds: FloatRect,+ command_to_root: FloatMatrix4x4,+ mut clip_space_matrix: impl FnMut(SpatialNodeIndex) -> Option<FloatMatrix4x4>,+) -> Option<OwnSpaceClipExtent> {+ let mut extent = None;+ for clip in inline_clips_of(header, payload).filter(|clip| clip.has_own_space) {+ let mapped_clip_rect = (clip.mode == ClipMode::Intersect && command_to_root.is_2d_affine())+ .then(|| clip_space_matrix(clip.space))+ .flatten()+ .filter(|clip_to_root| clip_to_root.is_2d_affine())+ .and_then(|clip_to_root| {+ let root_to_command = command_to_root.extract_2d_affine().inverse()?;+ let clip_to_command = multiply_affine(root_to_command, clip_to_root.extract_2d_affine());+ Some(clip_to_command.map_rect(clip.clip_rect_or_path_device_bounds))+ });+ let Some(mapped_clip_rect) = mapped_clip_rect else {+ return Some(OwnSpaceClipExtent::Unbounded);+ };+ let previous = match extent {+ Some(OwnSpaceClipExtent::Within(rect)) => rect,+ _ => bounds,+ };+ extent = Some(OwnSpaceClipExtent::Within(previous.intersected(mapped_clip_rect)));+ }+ extent+}+/// Plays one stream of records: the records of a run, or the records nested in a command. Compositor/// metadata is skipped, a command whose bounds are empty or clipped away is culled, and each command plays/// inside its inline clips and transform. A scroll bar's thumb moves by the offset of its scroll node.@@ -75,6 +119,21 @@ pub fn replay_records<Painter: ReplayPainter + ?Sized>(}// The matrix of the command's space, while an inline clip in a space of its own has the canvas in another.let mut command_space_matrix = None;+ if header.inline_clip_count != 0 && has_inline_clip_in_its_own_space(header, payload) {+ let command_to_root = painter.canvas_matrix();+ // NB: The bounds of a command do not include its clips in spaces of their own, which move apart from it+ // as they scroll, so the command is culled against where they are now.+ if let Some(OwnSpaceClipExtent::Within(rect)) = own_space_clip_extent(+ header,+ payload,+ header.bounding_rect.to_float(),+ command_to_root,+ clip_space_matrix,+ ) && (rect.is_empty() || painter.would_be_fully_clipped_by_painter(enclosing_int_rect(rect)))+ {+ return;+ }+ }for clip in inline_clips_of(header, payload) {let own_space_matrix = clip.has_own_space.then(|| clip_space_matrix(clip.space)).flatten();if let Some(matrix) = &own_space_matrix {@@ -1174,7 +1233,8 @@ mod tests {.in_space(clip_space),],);- let clip_space_matrix = translation_matrix(0.0, -50.0, 0.0);+ // The clip lands on the command, at (3, 5) in its space.+ let clip_space_matrix = translation_matrix(102.0, 203.0, 0.0);let mut painter = RecordingPainter::new();let command_space_matrix = painter.base_matrix;replay_records(@@ -1197,6 +1257,37 @@ mod tests {);}+ #[test]+ fn a_command_whose_inline_clip_in_a_space_of_its_own_has_scrolled_off_it_is_culled() {+ let clip_space = SpatialNodeIndex(7);+ let mut builder = crate::display_list::builder::DisplayListBuilder::new();+ builder.append_with_inline_clips(+ &crate::display_list::commands::FillRect {+ rect: IntRect::new(0, 0, 10, 10),+ color: Color::default(),+ compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,+ background_color_animation_effect: EffectNodeIndex::NONE,+ },+ &[],+ ContextRef::default(),+ &[+ crate::display_list::builder::PendingInlineClip::intersecting_float_rect(FloatRect::new(+ 1.0, 2.0, 3.0, 4.0,+ ))+ .in_space(clip_space),+ ],+ );+ let clip_space_matrix = translation_matrix(0.0, -50.0, 0.0);+ let mut painter = RecordingPainter::new();+ replay_records(+ builder.bytes(),+ &[],+ &|space| (space == clip_space).then_some(clip_space_matrix),+ &mut painter,+ );+ assert_eq!(painter.events, vec![]);+ }+#[test]fn an_inline_clip_in_an_unknown_space_is_pushed_in_the_space_of_its_command() {let mut builder = crate::display_list::builder::DisplayListBuilder::new();