From 56976efaa2ff0f11d954625c98841517830a5ae8 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Sat, 9 Sep 2023 19:43:09 +0200 Subject: [PATCH] Layout 2013: Don't make gradient display items for zero-sized gradients (#30321) Before WebRender would ignore these, but newer version of WebRender have issues with them. This change simply prevents legacy layout from creating display items for these types of gradients. This is already the behavior of non-legacy layout. --- components/layout/display_list/background.rs | 17 +++++++++++++---- components/layout/display_list/builder.rs | 12 +++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/components/layout/display_list/background.rs b/components/layout/display_list/background.rs index 60fd72fd4c3..4f37dcf25c3 100644 --- a/components/layout/display_list/background.rs +++ b/components/layout/display_list/background.rs @@ -138,8 +138,10 @@ pub fn clip( /// Determines where to place an element background image or gradient. /// -/// Photos have their resolution as intrinsic size while gradients have +/// Images have their resolution as intrinsic size while gradients have /// no intrinsic size. +/// +/// Return `None` if the background size is zero, otherwise a [`BackgroundPlacement`]. pub fn placement( bg: &Background, viewport_size: Size2D, @@ -149,7 +151,7 @@ pub fn placement( border_padding: SideOffsets2D, border_radii: BorderRadius, index: usize, -) -> BackgroundPlacement { +) -> Option { let bg_attachment = *get_cyclic(&bg.background_attachment.0, index); let bg_clip = *get_cyclic(&bg.background_clip.0, index); let bg_origin = *get_cyclic(&bg.background_origin.0, index); @@ -180,6 +182,9 @@ pub fn placement( }; let mut tile_size = compute_background_image_size(bg_size, bounds.size, intrinsic_size); + if tile_size.is_empty() { + return None; + } let mut tile_spacing = Size2D::zero(); let own_position = bounds.size - tile_size; @@ -206,14 +211,18 @@ pub fn placement( clip_rect.size.height, ); - BackgroundPlacement { + if tile_size.is_empty() { + return None; + } + + Some(BackgroundPlacement { bounds, tile_size, tile_spacing, clip_rect, clip_radii, fixed, - } + }) } fn tile_image_round( diff --git a/components/layout/display_list/builder.rs b/components/layout/display_list/builder.rs index e6980ebdd6a..bdd6142d781 100644 --- a/components/layout/display_list/builder.rs +++ b/components/layout/display_list/builder.rs @@ -831,9 +831,10 @@ impl Fragment { index, ); - if placement.tile_size.is_empty() { - return; - } + let placement = match placement { + Some(placement) => placement, + None => return, + }; state.clipping_and_scrolling_scope(|state| { if !placement.clip_radii.is_zero() { @@ -953,6 +954,11 @@ impl Fragment { index, ); + let placement = match placement { + Some(placement) => placement, + None => return, + }; + state.clipping_and_scrolling_scope(|state| { if !placement.clip_radii.is_zero() { let clip_id =