Truly independent web browser
LibCompositing: Drop the bounding rect from display list record headers
Aliaksandr Kalenik029d3d7530f1
diff --git a/Libraries/LibCompositing/Rust/src/display_list/builder.rs b/Libraries/LibCompositing/Rust/src/display_list/builder.rsindex 3f81d19cf91..953cd74f235 100644--- a/Libraries/LibCompositing/Rust/src/display_list/builder.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/builder.rs@@ -103,8 +103,45 @@ impl PendingInlineClip {}}- fn rect_confining_the_command(&self) -> Option<FloatRect> {- (self.space.is_none() && self.mode == ClipMode::Intersect).then_some(self.clip_rect_or_path_device_bounds)+ fn confines_the_command(&self) -> bool {+ self.space.is_none() && self.mode == ClipMode::Intersect+ }++ fn recorded_clip_rect(&self, clip_rect_narrowed_to_the_command_bounding_rect: FloatRect) -> FloatRect {+ if self.narrows_clip_rect_to_the_command_bounding_rect {+ clip_rect_narrowed_to_the_command_bounding_rect+ } else {+ self.clip_rect_or_path_device_bounds+ }+ }+}++struct RecordBounds {+ clip_rect_narrowed_to_the_command_bounding_rect: FloatRect,+ bounding_rect: Option<IntRect>,+}++fn record_bounds<C: DisplayListCommand>(+ command: &C,+ inline_clips: &[PendingInlineClip],+ inline_transform: Option<AffineTransform>,+) -> RecordBounds {+ let command_bounding_rect = command.bounding_rect();+ let confining_clips = || inline_clips.iter().filter(|clip| clip.confines_the_command());+ let clip_rect_narrowed_to_the_command_bounding_rect = record_bounding_rect(+ command_bounding_rect,+ inline_transform,+ confining_clips().map(|clip| clip.clip_rect_or_path_device_bounds),+ )+ .unwrap_or_default()+ .to_float();+ RecordBounds {+ clip_rect_narrowed_to_the_command_bounding_rect,+ bounding_rect: record_bounding_rect(+ command_bounding_rect,+ inline_transform,+ confining_clips().map(|clip| clip.recorded_clip_rect(clip_rect_narrowed_to_the_command_bounding_rect)),+ ),}}@@ -276,7 +313,14 @@ impl DisplayListBuilder {});}- fn note_command(&mut self, header: &DisplayListCommandHeader, context: ContextRef, offset: usize, size: usize) {+ fn note_command(+ &mut self,+ command_type: DisplayListCommandType,+ bounding_rect: Option<IntRect>,+ context: ContextRef,+ offset: usize,+ size: usize,+ ) {// Every run so far belongs to a chunk that has ended.if self.chunks@@ -289,7 +333,7 @@ impl DisplayListBuilder {..Default::default()});}- note_command(&mut self.runs, header, context, offset, size);+ note_command(&mut self.runs, command_type, bounding_rect, context, offset, size);}pub fn byte_size(&self) -> usize {@@ -327,7 +371,8 @@ impl DisplayListBuilder {let payload_size = padded_record_size - HEADER_SIZE;let entries_offset = payload_size - entries_size;debug_assert_eq!(entries_offset % COMMAND_ALIGNMENT, 0);- let header = Self::header_for(command, inline_clips, inline_transform, payload_size);+ let header = Self::header_for::<C>(inline_clips, inline_transform, payload_size);+ let bounds = record_bounds(command, inline_clips, inline_transform);let start = self.bytes.len();self.bytes.resize(start + padded_record_size, 0);header.write_ffi_bytes(&mut self.bytes[start..start + HEADER_SIZE]);@@ -341,10 +386,16 @@ impl DisplayListBuilder {&path_spans,payload_start,entries_offset,- &header,+ bounds.clip_rect_narrowed_to_the_command_bounding_rect,);if self.open_group_depth == 0 {- self.note_command(&header, context, start, padded_record_size);+ self.note_command(+ C::COMMAND_TYPE,+ bounds.bounding_rect,+ context,+ start,+ padded_record_size,+ );} else {self.note_group_context(context);}@@ -441,13 +492,27 @@ impl DisplayListBuilder {(HEADER_SIZE + unpadded_payload_size + entries_size).next_multiple_of(COMMAND_ALIGNMENT);let payload_size = padded_record_size - HEADER_SIZE;let entries_offset = payload_size - entries_size;- let header = Self::header_for(command, &inline_clips, None, payload_size);+ let header = Self::header_for::<C>(&inline_clips, None, payload_size);+ let bounds = record_bounds(command, &inline_clips, None);self.bytes.resize(group.record_start + padded_record_size, 0);header.write_ffi_bytes(&mut self.bytes[group.record_start..group.record_start + HEADER_SIZE]);command.write_ffi_bytes(&mut self.bytes[payload_start..payload_start + std::mem::size_of::<C>()]);- self.write_tail_entries(&inline_clips, None, &path_spans, payload_start, entries_offset, &header);+ self.write_tail_entries(+ &inline_clips,+ None,+ &path_spans,+ payload_start,+ entries_offset,+ bounds.clip_rect_narrowed_to_the_command_bounding_rect,+ );if self.open_group_depth == 0 {- self.note_command(&header, context, group.record_start, padded_record_size);+ self.note_command(+ C::COMMAND_TYPE,+ bounds.bounding_rect,+ context,+ group.record_start,+ padded_record_size,+ );self.open_group_context = None;}}@@ -489,27 +554,16 @@ impl DisplayListBuilder {}fn header_for<C: DisplayListCommand>(- command: &C,inline_clips: &[PendingInlineClip],inline_transform: Option<AffineTransform>,payload_size: usize,) -> DisplayListCommandHeader {const { assert!(std::mem::align_of::<C>() <= COMMAND_ALIGNMENT) };- let inline_clip_count = u8::try_from(inline_clips.len()).expect("too many inline clips on one command");- let bounding_rect = record_bounding_rect(- command.bounding_rect(),- inline_transform,- inline_clips- .iter()- .filter_map(PendingInlineClip::rect_confining_the_command),- );DisplayListCommandHeader {command_type: C::COMMAND_TYPE,- has_bounding_rect: bounding_rect.is_some(),- inline_clip_count,+ inline_clip_count: u8::try_from(inline_clips.len()).expect("too many inline clips on one command"),has_inline_transform: inline_transform.is_some(),payload_size: u32::try_from(payload_size).expect("display list payload exceeds u32"),- bounding_rect: bounding_rect.unwrap_or_default(),}}@@ -520,7 +574,7 @@ impl DisplayListBuilder {path_spans: &[DisplayListDataSpan],payload_start: usize,entries_offset: usize,- header: &DisplayListCommandHeader,+ clip_rect_narrowed_to_the_command_bounding_rect: FloatRect,) {let mut entries_offset = entries_offset;if let Some(transform) = inline_transform {@@ -538,11 +592,8 @@ impl DisplayListBuilder {self.bytes[path_start..path_start + path_bytes.len()].copy_from_slice(path_bytes);}let entry = DisplayListInlineClip {- clip_rect_or_path_device_bounds: if clip.narrows_clip_rect_to_the_command_bounding_rect {- header.bounding_rect.to_float()- } else {- clip.clip_rect_or_path_device_bounds- },+ clip_rect_or_path_device_bounds: clip+ .recorded_clip_rect(clip_rect_narrowed_to_the_command_bounding_rect),corner_radii: clip.corner_radii,path_data: path_spans[index],path_winding_rule: clip.path_winding_rule,@@ -564,7 +615,7 @@ pub fn append_record<C: DisplayListCommand>(bytes: &mut Vec<u8>, command: &C, indebug_assert_eq!(bytes.len() % COMMAND_ALIGNMENT, 0);let padded_record_size =(HEADER_SIZE + std::mem::size_of::<C>() + inline_data.len()).next_multiple_of(COMMAND_ALIGNMENT);- let header = DisplayListBuilder::header_for(command, &[], None, padded_record_size - HEADER_SIZE);+ let header = DisplayListBuilder::header_for::<C>(&[], None, padded_record_size - HEADER_SIZE);let start = bytes.len();bytes.resize(start + padded_record_size, 0);header.write_ffi_bytes(&mut bytes[start..start + HEADER_SIZE]);@@ -576,7 +627,8 @@ pub fn append_record<C: DisplayListCommand>(bytes: &mut Vec<u8>, command: &C, inpub(crate) fn note_command(runs: &mut Vec<DisplayListCommandRun>,- header: &DisplayListCommandHeader,+ command_type: DisplayListCommandType,+ bounding_rect: Option<IntRect>,context: ContextRef,offset: usize,record_size: usize,@@ -593,11 +645,11 @@ pub(crate) fn note_command(let run = runs.last_mut().expect("a run was pushed above");debug_assert_eq!(run.offset + run.size, offset);run.size += record_size;- if header.command_type.is_compositor_metadata() {+ if command_type.is_compositor_metadata() {run.has_compositor_metadata = true;} else {- debug_assert!(header.has_bounding_rect, "a draw command must report its bounding rect");- run.ink_bounds = run.ink_bounds.united(header.bounding_rect);+ debug_assert!(bounding_rect.is_some(), "a draw command must report its bounding rect");+ run.ink_bounds = run.ink_bounds.united(bounding_rect.unwrap_or_default());}}@@ -671,19 +723,9 @@ pub fn read_header(bytes: &[u8]) -> DisplayListCommandHeader {cursor.u8_at(std::mem::offset_of!(DisplayListCommandHeader, command_type)),).expect("invalid display list command type"),- has_bounding_rect: cursor.bool_at(std::mem::offset_of!(DisplayListCommandHeader, has_bounding_rect)),inline_clip_count: cursor.u8_at(std::mem::offset_of!(DisplayListCommandHeader, inline_clip_count)),has_inline_transform: cursor.bool_at(std::mem::offset_of!(DisplayListCommandHeader, has_inline_transform)),payload_size: cursor.u32_at(std::mem::offset_of!(DisplayListCommandHeader, payload_size)),- bounding_rect: {- let base = std::mem::offset_of!(DisplayListCommandHeader, bounding_rect);- libgfx_rust::IntRect {- x: cursor.i32_at(base),- y: cursor.i32_at(base + 4),- width: cursor.i32_at(base + 8),- height: cursor.i32_at(base + 12),- }- },}}@@ -701,9 +743,6 @@ impl HeaderReader<'_> {fn u32_at(&self, offset: usize) -> u32 {u32::from_ne_bytes(self.bytes[offset..offset + 4].try_into().unwrap())}- fn i32_at(&self, offset: usize) -> i32 {- i32::from_ne_bytes(self.bytes[offset..offset + 4].try_into().unwrap())- }}#[cfg(test)]@@ -841,8 +880,17 @@ mod tests {.collect()}+ fn bounding_rect_of_record_at(builder: &DisplayListBuilder, record_offset: usize) -> Option<IntRect> {+ let header = read_header(&builder.bytes()[record_offset..]);+ let payload_start = record_offset + HEADER_SIZE;+ bounding_rect_computed_from_payload(+ &header,+ &builder.bytes()[payload_start..payload_start + header.payload_size as usize],+ )+ }+#[test]- fn a_confining_clip_narrows_the_header_and_appends_a_tail_entry() {+ fn a_confining_clip_narrows_the_bounding_rect_and_appends_a_tail_entry() {let mut builder = DisplayListBuilder::new();let root = context(0, None);builder.append_with_inline_clips(@@ -856,8 +904,10 @@ mod tests {builder.append(&fill_rect(50, 50, 10, 10), &[], root);let header = read_header(builder.bytes());assert_eq!(header.inline_clip_count, 1);- assert!(header.has_bounding_rect);- assert_eq!(header.bounding_rect, IntRect::new(10, 10, 20, 20));+ assert_eq!(+ bounding_rect_of_record_at(&builder, 0),+ Some(IntRect::new(10, 10, 20, 20))+ );let entries = inline_clip_entries(&builder, 0);assert_eq!(entries[0].kind, InlineClipKind::Rect);assert_eq!(entries[0].mode, ClipMode::Intersect);@@ -885,7 +935,10 @@ mod tests {);let header = read_header(builder.bytes());assert_eq!(header.inline_clip_count, 2);- assert_eq!(header.bounding_rect, IntRect::new(5, 5, 95, 95));+ assert_eq!(+ bounding_rect_of_record_at(&builder, 0),+ Some(IntRect::new(5, 5, 95, 95))+ );let entries = inline_clip_entries(&builder, 0);assert_eq!(entries[0].clip_rect_or_path_device_bounds,diff --git a/Libraries/LibCompositing/Rust/src/display_list/canvas_2d.rs b/Libraries/LibCompositing/Rust/src/display_list/canvas_2d.rsindex 0ea8605bc01..40a0c4ac447 100644--- a/Libraries/LibCompositing/Rust/src/display_list/canvas_2d.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/canvas_2d.rs@@ -454,7 +454,6 @@ mod tests {);assert_eq!(validate_canvas_2d_tape(writer.bytes()), Ok(()));let header = read_header(writer.bytes());- assert!(!header.has_bounding_rect);assert_eq!(header.inline_clip_count, 0);let records = records(writer.bytes());assert_eq!(records.len(), 1);@@ -688,20 +687,6 @@ mod tests {}}- #[test]- fn a_command_with_a_bounding_rect_is_rejected() {- let mut writer = TapeWriter::default();- writer.save();- writer.clear_rect(FloatRect::new(0.0, 0.0, 1.0, 1.0), Color(0));- let mut tape = writer.bytes().to_vec();- let second_record = read_header(&tape).payload_size as usize + HEADER_SIZE;- tape[second_record + std::mem::offset_of!(DisplayListCommandHeader, has_bounding_rect)] = 1;- assert_eq!(- validate_canvas_2d_tape(&tape),- Err("Canvas 2D stream command has a bounding rect")- );- }-#[test]fn a_span_outside_its_payload_is_rejected() {let mut writer = TapeWriter::default();diff --git a/Libraries/LibCompositing/Rust/src/display_list/damage.rs b/Libraries/LibCompositing/Rust/src/display_list/damage.rsindex 7a08bd0f59c..e19dacebcdc 100644--- a/Libraries/LibCompositing/Rust/src/display_list/damage.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/damage.rs@@ -1360,12 +1360,11 @@ mod tests {}// Appends one record the way the Rust builder writes it: header, payload, then zero padding up to- // the command alignment, but with the header fields chosen by the test.+ // the command alignment, but with the inline clip entries chosen by the test.fn append_record<C: DisplayListCommand>(display_list: &mut TestDisplayList,command: &C,inline_data: &[u8],- bounding_rect: Option<IntRect>,context: ContextRef,inline_clips: &[DisplayListInlineClip],) {@@ -1375,11 +1374,9 @@ mod tests {let padded_record_size = (HEADER_SIZE + unpadded_payload_size + entries_size).next_multiple_of(16);let header = DisplayListCommandHeader {command_type: C::COMMAND_TYPE,- has_bounding_rect: bounding_rect.is_some(),inline_clip_count: inline_clips.len() as u8,has_inline_transform: false,payload_size: (padded_record_size - HEADER_SIZE) as u32,- bounding_rect: bounding_rect.unwrap_or_default(),};let start = bytes.len();bytes.resize(start + padded_record_size, 0);@@ -1393,6 +1390,8 @@ mod tests {let entry_start = entries_start + index * INLINE_CLIP_ENTRY_SIZE;entry.write_ffi_bytes(&mut bytes[entry_start..entry_start + INLINE_CLIP_ENTRY_SIZE]);}+ let bounding_rect =+ bounding_rect_computed_from_payload(&header, &bytes[payload_start..start + padded_record_size]);if display_list.runs.len() == display_list.first_run_of_open_chunk() {display_list.runs.push(DisplayListCommandRun {offset: start as u32,@@ -1400,16 +1399,19 @@ mod tests {..DisplayListCommandRun::default()});}- note_command(&mut display_list.runs, &header, context, start, padded_record_size);+ note_command(+ &mut display_list.runs,+ C::COMMAND_TYPE,+ bounding_rect,+ context,+ start,+ padded_record_size,+ );}- fn command_bytes<C: DisplayListCommand>(- command: &C,- bounding_rect: Option<IntRect>,- context: ContextRef,- ) -> TestDisplayList {+ fn command_bytes<C: DisplayListCommand>(command: &C, context: ContextRef) -> TestDisplayList {let mut bytes = TestDisplayList::default();- append_record(&mut bytes, command, &[], bounding_rect, context, &[]);+ append_record(&mut bytes, command, &[], context, &[]);bytes.end_chunk();bytes}@@ -1430,7 +1432,6 @@ mod tests {compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,background_color_animation_effect: EffectNodeIndex::NONE,},- Some(rect),ContextRef::default(),)}@@ -1455,7 +1456,7 @@ mod tests {canvas_id: CanvasId(1),scaling_mode: ScalingMode::NearestNeighbor,};- command_bytes(&command, Some(rect), ContextRef::default())+ command_bytes(&command, ContextRef::default())}fn transform(matrix: FloatMatrix4x4) -> TransformData {@@ -1550,8 +1551,8 @@ mod tests {compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,background_color_animation_effect: EffectNodeIndex::NONE,};- let old_display_list = command_bytes(&fill, Some(rect), context_in(VISUAL_VIEWPORT_NODE_INDEX, old_context));- let new_display_list = command_bytes(&fill, Some(rect), context_in(VISUAL_VIEWPORT_NODE_INDEX, new_context));+ let old_display_list = command_bytes(&fill, context_in(VISUAL_VIEWPORT_NODE_INDEX, old_context));+ let new_display_list = command_bytes(&fill, context_in(VISUAL_VIEWPORT_NODE_INDEX, new_context));damage(&old_display_list, &old_tree, &new_display_list, &new_tree)}@@ -1655,7 +1656,6 @@ mod tests {video_sink_handle: VideoSinkHandle(1),scaling_mode: ScalingMode::NearestNeighbor,},- Some(rect),ContextRef::default(),);let changed_video = LiveContentChanges {@@ -1681,7 +1681,6 @@ mod tests {isolated_backdrop_color: OptionalColor::default(),apply_force_dark: false,},- Some(rect),ContextRef::default(),);let changed_image = LiveContentChanges {@@ -1705,7 +1704,6 @@ mod tests {spatial_node_index: VISUAL_VIEWPORT_NODE_INDEX,snap_origin_if_untransformed: true,},- Some(rect),ContextRef::default(),);let changed_nested_context = LiveContentChanges {@@ -1740,7 +1738,6 @@ mod tests {canvas_id: CanvasId(1),scaling_mode: ScalingMode::NearestNeighbor,},- Some(rect),context,);let changed_canvas = LiveContentChanges {@@ -1775,7 +1772,6 @@ mod tests {mask_kind: MaskKind::Alpha,},&content,- Some(group_rect),ContextRef::default(),&[],);@@ -1812,7 +1808,6 @@ mod tests {compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,background_color_animation_effect: EffectNodeIndex::NONE,},- Some(rect),context_in(scroll_node, ContextRef::default()),);// Each of the three offsets rounds to a whole pixel, so the rect is drawn 3px above where it was recorded.@@ -1869,7 +1864,6 @@ mod tests {};let remaining = command_bytes(&fill,- Some(rect),ContextRef {clip: local_clip,effect,@@ -1882,7 +1876,6 @@ mod tests {rect: escaped_rect,..fill},- Some(escaped_rect),ContextRef {clip: ClipNodeIndex::NONE,effect,@@ -1916,7 +1909,7 @@ mod tests {vertical: false,};- let display_list = command_bytes(&scrollbar, scrollbar.bounding_rect(), ContextRef::default());+ let display_list = command_bytes(&scrollbar, ContextRef::default());assert_eq!(damage_with_scroll_offsets(@@ -1954,7 +1947,6 @@ mod tests {background_color_animation_effect: EffectNodeIndex::NONE,},&[],- Some(rect),ContextRef::default(),&[clip],);@@ -2034,7 +2026,6 @@ mod tests {background_color_animation_effect: EffectNodeIndex::NONE,},&[],- Some(rect),ContextRef::default(),&[DisplayListInlineClip {has_own_space: true,@@ -2108,7 +2099,6 @@ mod tests {background_color_animation_effect: EffectNodeIndex::NONE,},&[],- Some(viewport),context,&[DisplayListInlineClip {has_own_space: true,@@ -2168,14 +2158,12 @@ mod tests {&CompositorMainThreadWheelEventRegion {rect: FloatRect::new(0.0, 0.0, 10.0, 10.0),},- None,ContextRef::default(),);let new_display_list = command_bytes(&CompositorMainThreadWheelEventRegion {rect: FloatRect::new(20.0, 20.0, 10.0, 10.0),},- None,ContextRef::default(),);assert_eq!(@@ -2205,11 +2193,7 @@ mod tests {}fn compositor_scrollbar_bytes(is_painted_by_compositor: bool) -> TestDisplayList {- command_bytes(- &compositor_scrollbar(is_painted_by_compositor),- None,- ContextRef::default(),- )+ command_bytes(&compositor_scrollbar(is_painted_by_compositor), ContextRef::default())}#[test]@@ -2290,7 +2274,7 @@ mod tests {compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,background_color_animation_effect: EffectNodeIndex::NONE,};- (command_bytes(&fill, Some(rect), context), tree)+ (command_bytes(&fill, context), tree)};let (old_bytes, old_tree) = make_scene(1.0, 200.0, ClipMode::Intersect, true);let (new_bytes, new_tree) = make_scene(200.0, 200.0, ClipMode::Intersect, true);@@ -2342,7 +2326,6 @@ mod tests {compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,background_color_animation_effect: EffectNodeIndex::NONE,},- Some(rect),ContextRef {effect: EffectNodeIndex(0),..ContextRef::default()@@ -2365,8 +2348,8 @@ mod tests {compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,background_color_animation_effect: EffectNodeIndex::NONE,};- let old_bytes = command_bytes(&fill(RED), Some(rect), context);- let new_bytes = command_bytes(&fill(BLUE), Some(rect), context);+ let old_bytes = command_bytes(&fill(RED), context);+ let new_bytes = command_bytes(&fill(BLUE), context);damage(&old_bytes, &tree, &new_bytes, &tree)}@@ -2469,7 +2452,6 @@ mod tests {compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,background_color_animation_effect: EffectNodeIndex::NONE,},- Some(rect),context,)};@@ -2499,14 +2481,9 @@ mod tests {compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,background_color_animation_effect: EffectNodeIndex::NONE,},- Some(fill_rect),ContextRef::default(),);- bytes.extend_from_slice(&command_bytes(- &BackdropFilterRegion { rect: region },- Some(region),- backdrop_context,- ));+ bytes.extend_from_slice(&command_bytes(&BackdropFilterRegion { rect: region }, backdrop_context));bytes};let within_reach = IntRect::new(0, 10, 30, 20);@@ -2529,7 +2506,7 @@ mod tests {VISUAL_VIEWPORT_NODE_INDEX,effect_context(&mut tree, backdrop_effects(blur_filter(4.0), region)),);- let bytes = command_bytes(&BackdropFilterRegion { rect: region }, Some(region), backdrop_context);+ let bytes = command_bytes(&BackdropFilterRegion { rect: region }, backdrop_context);let forced_damage = |forced_damage_rect| {damage_for_live_content_changes(&bytes,@@ -2581,12 +2558,10 @@ mod tests {compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,background_color_animation_effect: EffectNodeIndex::NONE,},- Some(fill_rect),ContextRef::default(),);bytes.extend_from_slice(&command_bytes(&BackdropFilterRegion { rect: region },- Some(region),shadowed_backdrop_context,));bytes@@ -2632,21 +2607,9 @@ mod tests {let mut unchanged_tree = identity_tree();let unchanged_context = effect_context(&mut unchanged_tree, backdrop_effects(blur_filter(1.0), region));let marker = BackdropFilterRegion { rect: region };- let old_display_list = command_bytes(- &marker,- Some(region),- context_in(VISUAL_VIEWPORT_NODE_INDEX, old_context),- );- let new_display_list = command_bytes(- &marker,- Some(region),- context_in(VISUAL_VIEWPORT_NODE_INDEX, new_context),- );- let unchanged_display_list = command_bytes(- &marker,- Some(region),- context_in(VISUAL_VIEWPORT_NODE_INDEX, unchanged_context),- );+ let old_display_list = command_bytes(&marker, context_in(VISUAL_VIEWPORT_NODE_INDEX, old_context));+ let new_display_list = command_bytes(&marker, context_in(VISUAL_VIEWPORT_NODE_INDEX, new_context));+ let unchanged_display_list = command_bytes(&marker, context_in(VISUAL_VIEWPORT_NODE_INDEX, unchanged_context));assert_eq!(damage(&old_display_list, &old_tree, &new_display_list, &new_tree),Some(IntRect::new(9, 9, 22, 22))@@ -2670,7 +2633,6 @@ mod tests {compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,background_color_animation_effect: EffectNodeIndex::NONE,},- Some(IntRect::new(10, 10, 20, 20)),context_in(VISUAL_VIEWPORT_NODE_INDEX, old_context),);let new_display_list = command_bytes(@@ -2680,7 +2642,6 @@ mod tests {compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,background_color_animation_effect: EffectNodeIndex::NONE,},- Some(IntRect::new(30, 30, 20, 20)),context_in(VISUAL_VIEWPORT_NODE_INDEX, new_context),);assert_eq!(@@ -2701,16 +2662,8 @@ mod tests {compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,background_color_animation_effect: EffectNodeIndex::NONE,};- let old_display_list = command_bytes(- &fill,- Some(fill.rect),- context_in(VISUAL_VIEWPORT_NODE_INDEX, old_context),- );- let new_display_list = command_bytes(- &fill,- Some(fill.rect),- context_in(VISUAL_VIEWPORT_NODE_INDEX, new_context),- );+ let old_display_list = command_bytes(&fill, context_in(VISUAL_VIEWPORT_NODE_INDEX, old_context));+ let new_display_list = command_bytes(&fill, context_in(VISUAL_VIEWPORT_NODE_INDEX, new_context));assert_eq!(damage(&old_display_list, &old_tree, &new_display_list, &new_tree),Some(IntRect::new(9, 9, 22, 22))@@ -2745,16 +2698,8 @@ mod tests {compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,background_color_animation_effect: EffectNodeIndex::NONE,};- let old_display_list = command_bytes(- &fill,- Some(fill.rect),- context_in(old_command_spatial, ContextRef::default()),- );- let new_display_list = command_bytes(- &fill,- Some(fill.rect),- context_in(new_command_spatial, ContextRef::default()),- );+ let old_display_list = command_bytes(&fill, context_in(old_command_spatial, ContextRef::default()));+ let new_display_list = command_bytes(&fill, context_in(new_command_spatial, ContextRef::default()));assert_eq!(damage(&old_display_list, &old_tree, &new_display_list, &new_tree),Some(IntRect::default())@@ -2824,7 +2769,7 @@ mod tests {background_color_animation_effect: EffectNodeIndex::NONE,};(- command_bytes(&fill, Some(rect), context_in(VISUAL_VIEWPORT_NODE_INDEX, context)),+ command_bytes(&fill, context_in(VISUAL_VIEWPORT_NODE_INDEX, context)),tree,)};@@ -2859,16 +2804,8 @@ mod tests {background_color_animation_effect: EffectNodeIndex::NONE,};let filtered_rect = IntRect::new(10, 10, 20, 20);- let mut bytes = command_bytes(- &fill(viewport),- Some(viewport),- context_in(cover_spatial, ContextRef::default()),- );- bytes.extend_from_slice(&command_bytes(- &fill(filtered_rect),- Some(filtered_rect),- filtered_context,- ));+ let mut bytes = command_bytes(&fill(viewport), context_in(cover_spatial, ContextRef::default()));+ bytes.extend_from_slice(&command_bytes(&fill(filtered_rect), filtered_context));(bytes, tree)};let flood = || {@@ -2905,7 +2842,7 @@ mod tests {}fn fill_in(rect: IntRect, color: Color, context: ContextRef) -> TestDisplayList {- command_bytes(&fill(rect, color), Some(rect), context)+ command_bytes(&fill(rect, color), context)}fn scroll_data() -> SpatialData {@@ -3220,7 +3157,6 @@ mod tests {},},content,- Some(rect),context,&[],);@@ -3273,7 +3209,6 @@ mod tests {color: RED,orientation: Orientation::Horizontal,},- Some(text_rect),masked,);let list = list_of(&[@@ -3317,22 +3252,8 @@ mod tests {let rect = IntRect::new(10, 10, 20, 20);let scene = |color| {let mut list = TestDisplayList::default();- append_record(- &mut list,- &compositor_scrollbar(true),- &[],- None,- ContextRef::default(),- &[],- );- append_record(- &mut list,- &fill(rect, color),- &[],- Some(rect),- ContextRef::default(),- &[],- );+ append_record(&mut list, &compositor_scrollbar(true), &[], ContextRef::default(), &[]);+ append_record(&mut list, &fill(rect, color), &[], ContextRef::default(), &[]);list};let moved_tree = VisualContextTree::create(transform(translation_matrix(10.0, 0.0, 0.0)));diff --git a/Libraries/LibCompositing/Rust/src/display_list/tape.rs b/Libraries/LibCompositing/Rust/src/display_list/tape.rsindex 7f833fa9e10..aaefa3ad5d7 100644--- a/Libraries/LibCompositing/Rust/src/display_list/tape.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/tape.rs@@ -17,21 +17,17 @@ use libgfx_rust::*;#[repr(C, align(8))]pub struct DisplayListCommandHeader {pub command_type: DisplayListCommandType,- pub has_bounding_rect: bool,pub inline_clip_count: u8,pub has_inline_transform: bool,pub payload_size: u32,- pub bounding_rect: IntRect,}ffi_bytes_fields!(DisplayListCommandHeader {command_type,- has_bounding_rect,inline_clip_count,has_inline_transform,- payload_size,- bounding_rect+ payload_size});-const _: () = assert!(std::mem::size_of::<DisplayListCommandHeader>() == 24);+const _: () = assert!(std::mem::size_of::<DisplayListCommandHeader>() == 8);#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]#[repr(u8)]diff --git a/Libraries/LibCompositing/Rust/src/display_list/validate.rs b/Libraries/LibCompositing/Rust/src/display_list/validate.rsindex 51ba1152d2b..a5132bc50de 100644--- a/Libraries/LibCompositing/Rust/src/display_list/validate.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/validate.rs@@ -9,7 +9,7 @@//! damage and the player make of it are sound. The tape of a page and that of a 2D canvas each hold only the//! commands of their own kind.-use super::builder::{COMMAND_ALIGNMENT, HEADER_SIZE, read_header};+use super::builder::{COMMAND_ALIGNMENT, HEADER_SIZE, bounding_rect_computed_from_payload, read_header};use super::commands::*;use libgfx_rust::{CapStyle, Color, CompositingAndBlendingOperator, GradientInterpolationMethod, GradientInterpolationType,@@ -604,7 +604,7 @@ fn validate_inline_clip(payload: Payload, offset: usize) -> Result<(), ValidatioOk(())}-// What a run says about its records, recomputed by the rules the builder summarizes them with.+// What a run says about its records, recomputed from their payloads by the rules the builder summarizes them with.#[derive(Default)]struct RunSummary {ink_bounds: IntRect,@@ -612,11 +612,13 @@ struct RunSummary {}impl RunSummary {- fn note(&mut self, header: &DisplayListCommandHeader) {+ fn note(&mut self, header: &DisplayListCommandHeader, payload: &[u8]) {if header.command_type.is_compositor_metadata() {self.has_compositor_metadata = true;} else {- self.ink_bounds = self.ink_bounds.united(header.bounding_rect);+ self.ink_bounds = self+ .ink_bounds+ .united(bounding_rect_computed_from_payload(header, payload).unwrap_or_default());}}@@ -643,9 +645,7 @@ fn validate_header_bytes(bytes: &[u8], kind: TapeKind) -> Result<DisplayListCommif DisplayListCommandType::from_u8(bytes[offset_of!(DisplayListCommandHeader, command_type)]).is_none() {return Err("Display list command has an invalid type");}- if bytes[offset_of!(DisplayListCommandHeader, has_bounding_rect)] > 1- || bytes[offset_of!(DisplayListCommandHeader, has_inline_transform)] > 1- {+ if bytes[offset_of!(DisplayListCommandHeader, has_inline_transform)] > 1 {return Err("Display list command header has an invalid bool");}let header = read_header(bytes);@@ -654,9 +654,6 @@ fn validate_header_bytes(bytes: &[u8], kind: TapeKind) -> Result<DisplayListCommif header.command_type.is_canvas_2d() {return Err("Display list holds a command of the canvas 2D stream");}- if !header.has_bounding_rect && !header.command_type.is_compositor_metadata() {- return Err("Display list draw command has no bounding rect");- }}TapeKind::Canvas2D => {if !header.command_type.is_canvas_2d() {@@ -666,10 +663,6 @@ fn validate_header_bytes(bytes: &[u8], kind: TapeKind) -> Result<DisplayListCommif header.inline_clip_count != 0 || header.has_inline_transform {return Err("Canvas 2D stream command has inline clips or an inline transform");}- // A command of the canvas draws under the state that the commands before it left, so no rect bounds it.- if header.has_bounding_rect {- return Err("Canvas 2D stream command has a bounding rect");- }}}Ok(header)@@ -727,7 +720,7 @@ fn validate_records<'a>(pending.push(&payload.bytes[start..start + size]);}if let Some(summary) = summary.as_deref_mut() {- summary.note(&header);+ summary.note(&header, payload.bytes);}offset = payload_start + payload_size;}@@ -825,7 +818,6 @@ mod tests {use super::*;use crate::display_list::builder::DisplayListBuilder;use crate::display_list::storage::write_run;- use libgfx_rust::FloatRect;fn fill_rect() -> FillRect {FillRect {@@ -845,39 +837,25 @@ mod tests {}#[test]- fn a_draw_command_without_a_bounding_rect_is_rejected_at_any_depth() {- let context = ContextRef::default();+ fn run_ink_bounds_are_checked_against_the_payloads_of_their_records() {let mut builder = DisplayListBuilder::new();- builder.append(&fill_rect(), &[], context);- let nested_record_offset =- builder.byte_size() + HEADER_SIZE + size_of::<DrawIsolatedGroup>().next_multiple_of(COMMAND_ALIGNMENT);- let group = builder.begin_group::<DrawIsolatedGroup>(Vec::new());- builder.append(&fill_rect(), &[], context);- let content = builder.group_content_span(&group);- builder.finish_group(- group,- &DrawIsolatedGroup {- clip_rect: FloatRect::new(0.0, 0.0, 10.0, 10.0),- content,- mask: DisplayListDataSpan::default(),- filter: DisplayListDataSpan::default(),- opacity: 1.0,- compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,- mask_kind: MaskKind::Alpha,- },- context,- );+ builder.append(&fill_rect(), &[], ContextRef::default());let recorded = builder.finish();let run_bytes = run_table_bytes(&recorded.command_runs);assert!(validate_tape(&recorded.bytes, &run_bytes).is_ok());- for record_offset in [0, nested_record_offset] {- let mut tape = recorded.bytes.clone();- tape[record_offset + offset_of!(DisplayListCommandHeader, has_bounding_rect)] = 0;- assert_eq!(- validate_tape(&tape, &run_bytes),- Err("Display list draw command has no bounding rect")- );- }+ let mut widened_tape = recorded.bytes.clone();+ let width_offset = HEADER_SIZE + offset_of!(FillRect, rect) + offset_of!(IntRect, width);+ widened_tape[width_offset..width_offset + 4].copy_from_slice(&20i32.to_ne_bytes());+ assert_eq!(+ validate_tape(&widened_tape, &run_bytes),+ Err("Display list command run summary disagrees with its records")+ );++ let widened_runs = [DisplayListCommandRun {+ ink_bounds: IntRect::new(0, 0, 20, 10),+ ..recorded.command_runs[0]+ }];+ assert!(validate_tape(&widened_tape, &run_table_bytes(&widened_runs)).is_ok());}}