layout: Only create a LayoutContext if restyling (#37726)

The creation of `LayoutContext` does more work than necessary if layout
just needs to do something like make a display list and not restyle and
relayout. This change makes it so that these kind of non-restyle layouts
do not need to create a display list. In addition, the creation of
`LayoutContext` is better encapsulate

Testing: This should not change observable behavior and is thus covered
by existing WPT tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Martin Robinson 2025-06-27 17:01:30 +02:00 committed by GitHub
parent 5e44582277
commit 9232b0f550
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 208 additions and 196 deletions

View file

@ -161,7 +161,9 @@ impl ReplacedContents {
};
if let ReplacedContentKind::Image(Some(Image::Raster(ref image))) = kind {
context.handle_animated_image(element.opaque(), image.clone());
context
.image_resolver
.handle_animated_image(element.opaque(), image.clone());
}
let natural_size = if let Some(naturalc_size_in_dots) = natural_size_in_dots {
@ -190,7 +192,7 @@ impl ReplacedContents {
image_url: &ComputedUrl,
) -> Option<Self> {
if let ComputedUrl::Valid(image_url) = image_url {
let (image, width, height) = match context.get_or_request_image_or_meta(
let (image, width, height) = match context.image_resolver.get_or_request_image_or_meta(
element.opaque(),
image_url.clone().into(),
UsePlaceholder::No,
@ -323,12 +325,13 @@ impl ReplacedContents {
.and_then(|image| match image {
Image::Raster(raster_image) => raster_image.id,
Image::Vector(vector_image) => {
let scale = layout_context.shared_context().device_pixel_ratio();
let scale = layout_context.style_context.device_pixel_ratio();
let width = object_fit_size.width.scale_by(scale.0).to_px();
let height = object_fit_size.height.scale_by(scale.0).to_px();
let size = Size2D::new(width, height);
let tag = self.base_fragment_info.tag?;
layout_context
.image_resolver
.rasterize_vector_image(vector_image.id, size, tag.node)
.and_then(|i| i.id)
},
@ -355,7 +358,7 @@ impl ReplacedContents {
},
ReplacedContentKind::IFrame(iframe) => {
let size = Size2D::new(rect.size.width.to_f32_px(), rect.size.height.to_f32_px());
let hidpi_scale_factor = layout_context.shared_context().device_pixel_ratio();
let hidpi_scale_factor = layout_context.style_context.device_pixel_ratio();
layout_context.iframe_sizes.lock().insert(
iframe.browsing_context_id,