Auto merge of #26758 - jdm:stacking-context-transform-zero, r=mrobinson

Don't create empty stacking contexts in display lists

A recent change to euclid exposed that our display lists can contain Rects that contain NaN values. These NaNs originate from creating stacking contexts with transforms that scale the horizontal or vertical dimensions to 0. WebRender isn't prepared to handle these, so we need to not produce these empty stacking contexts when building the display list.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #26592 and fix #26590
- [x] There are tests for these changes
This commit is contained in:
bors-servo 2020-06-09 13:37:30 -04:00 committed by GitHub
commit cb4e3cb16a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 103 additions and 1 deletions

View file

@ -1571,6 +1571,11 @@ impl Fragment {
return;
}
// If this fragment takes up no space, we don't need to build any display items for it.
if self.has_non_invertible_transform() {
return;
}
debug!(
"Fragment::build_display_list at rel={:?}, abs={:?}: {:?}",
self.border_box, stacking_relative_border_box, self
@ -2376,6 +2381,11 @@ impl BlockFlow {
state: &mut StackingContextCollectionState,
flags: StackingContextCollectionFlags,
) {
// This block flow produces no stacking contexts if it takes up no space.
if self.has_non_invertible_transform() {
return;
}
let mut preserved_state = SavedStackingContextCollectionState::new(state);
let stacking_context_type = self.stacking_context_type(flags);

View file

@ -217,6 +217,12 @@ impl StackingContext {
parent_clipping_and_scrolling: ClippingAndScrolling,
established_reference_frame: Option<ClipScrollNodeIndex>,
) -> StackingContext {
if let Some(ref t) = transform {
// These are used as scale values by webrender, and it can't handle
// divisors of 0 when scaling.
assert_ne!(t.m11, 0.);
assert_ne!(t.m22, 0.);
}
StackingContext {
id,
context_type,

View file

@ -273,6 +273,22 @@ pub trait Flow: HasBaseFlow + fmt::Debug + Sync + Send + 'static {
might_have_floats_in_or_out
}
fn has_non_invertible_transform(&self) -> bool {
if !self.class().is_block_like() ||
self.as_block()
.fragment
.style
.get_box()
.transform
.0
.is_empty()
{
return false;
}
self.as_block().fragment.has_non_invertible_transform()
}
fn get_overflow_in_parent_coordinates(&self) -> Overflow {
// FIXME(#2795): Get the real container size.
let container_size = Size2D::zero();
@ -1160,7 +1176,9 @@ impl BaseFlow {
state: &mut StackingContextCollectionState,
) {
for kid in self.children.iter_mut() {
kid.collect_stacking_contexts(state);
if !kid.has_non_invertible_transform() {
kid.collect_stacking_contexts(state);
}
}
}

View file

@ -2730,6 +2730,12 @@ impl Fragment {
self.style().get_box().perspective != Perspective::None
}
/// Returns true if this fragment has a transform applied that causes it to take up no space.
pub fn has_non_invertible_transform(&self) -> bool {
self.transform_matrix(&Rect::default())
.map_or(false, |matrix| !matrix.is_invertible())
}
/// Returns true if this fragment establishes a new stacking context and false otherwise.
pub fn establishes_stacking_context(&self) -> bool {
// Text fragments shouldn't create stacking contexts.

View file

@ -1871,6 +1871,11 @@ impl Flow for InlineFlow {
let previous_cb_clipping_and_scrolling = state.containing_block_clipping_and_scrolling;
for fragment in self.fragments.fragments.iter_mut() {
// If a particular fragment would establish a stacking context but has a transform
// applied that causes it to take up no space, we can skip it entirely.
if fragment.has_non_invertible_transform() {
continue;
}
state.containing_block_clipping_and_scrolling = previous_cb_clipping_and_scrolling;
let abspos_containing_block = fragment.style.get_box().position != Position::Static;

View file

@ -346,6 +346,10 @@ pub struct BuildDisplayList<'a> {
impl<'a> BuildDisplayList<'a> {
#[inline]
pub fn traverse(&mut self, flow: &mut dyn Flow) {
if flow.has_non_invertible_transform() {
return;
}
let parent_stacking_context_id = self.state.current_stacking_context_id;
self.state.current_stacking_context_id = flow.base().stacking_context_id;