From 56ff8f41e0836ef05f33644ddccc9d4e1f00e6ab Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Tue, 2 Jun 2020 16:59:43 -0400 Subject: [PATCH] layout2020: Don't create stacking contexts for empty fragments and boxes. --- .../display_list/stacking_context.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/components/layout_2020/display_list/stacking_context.rs b/components/layout_2020/display_list/stacking_context.rs index 49c1be101b8..c07eee51393 100644 --- a/components/layout_2020/display_list/stacking_context.rs +++ b/components/layout_2020/display_list/stacking_context.rs @@ -448,6 +448,14 @@ impl Fragment { return; } + // If this fragment has a transform applied that makes it take up no spae + // then we don't need to create any stacking contexts for it. + let has_non_invertible_transform = + fragment.has_non_invertible_transform(&containing_block_info.rect.to_untyped()); + if has_non_invertible_transform { + return; + } + fragment.build_stacking_context_tree( fragment_ref, builder, @@ -778,6 +786,15 @@ impl BoxFragment { }) } + /// Returns true if the given style contains a transform that is not invertible. + fn has_non_invertible_transform(&self, containing_block: &Rect) -> bool { + let list = &self.style.get_box().transform; + match list.to_transform_3d_matrix(Some(containing_block)) { + Ok(t) => !t.0.is_invertible(), + Err(_) => false, + } + } + /// Returns the 4D matrix representing this fragment's transform. pub fn calculate_transform_matrix( &self, @@ -786,6 +803,10 @@ impl BoxFragment { let list = &self.style.get_box().transform; let transform = LayoutTransform::from_untyped(&list.to_transform_3d_matrix(Some(&border_rect)).ok()?.0); + // WebRender will end up dividing by the scale value of this transform, so we + // want to ensure we don't feed it a divisor of 0. + assert_ne!(transform.m11, 0.); + assert_ne!(transform.m22, 0.); let transform_origin = &self.style.get_box().transform_origin; let transform_origin_x = transform_origin