layout: Combine layout_2020 and layout_thread_2020 into a crate called layout (#36613)

Now that legacy layout has been removed, the name `layout_2020` doesn't
make much sense any longer, also it's 2025 now for better or worse. The
split between the "layout thread" and "layout" also doesn't make as much
sense since layout doesn't run on it's own thread. There's a possibility
that it will in the future, but that should be something that the user
of the crate controls rather than layout iself.

This is part of the larger layout interface cleanup and optimization
that
@Looriool and I are doing.

Testing: Covered by existing tests as this is just code movement.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-04-19 12:17:03 +02:00 committed by GitHub
parent 3ab5b8c447
commit 7787cab521
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
62 changed files with 58 additions and 122 deletions

46
Cargo.lock generated
View file

@ -4142,7 +4142,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
[[package]]
name = "layout_2020"
name = "layout"
version = "0.0.1"
dependencies = [
"app_units",
@ -4151,6 +4151,7 @@ dependencies = [
"bitflags 2.9.0",
"canvas_traits",
"compositing_traits",
"constellation_traits",
"data-url",
"embedder_traits",
"euclid",
@ -4169,10 +4170,13 @@ dependencies = [
"num-traits",
"parking_lot",
"pixels",
"profile_traits",
"quickcheck",
"range",
"rayon",
"script",
"script_layout_interface",
"script_traits",
"selectors",
"servo_arc",
"servo_config",
@ -4180,6 +4184,7 @@ dependencies = [
"servo_malloc_size_of",
"servo_url",
"stylo",
"stylo_atoms",
"stylo_traits",
"taffy",
"tracing",
@ -4190,43 +4195,6 @@ dependencies = [
"xi-unicode",
]
[[package]]
name = "layout_thread_2020"
version = "0.0.1"
dependencies = [
"app_units",
"base",
"compositing_traits",
"constellation_traits",
"embedder_traits",
"euclid",
"fnv",
"fonts",
"fonts_traits",
"fxhash",
"ipc-channel",
"layout_2020",
"log",
"metrics",
"net_traits",
"parking_lot",
"profile_traits",
"script",
"script_layout_interface",
"script_traits",
"servo_allocator",
"servo_arc",
"servo_config",
"servo_malloc_size_of",
"servo_url",
"stylo",
"stylo_atoms",
"stylo_traits",
"tracing",
"url",
"webrender_api",
]
[[package]]
name = "lazy_static"
version = "1.5.0"
@ -4334,7 +4302,7 @@ dependencies = [
"http 1.3.1",
"ipc-channel",
"keyboard-types",
"layout_thread_2020",
"layout",
"libservo",
"log",
"media",

View file

@ -1,5 +1,5 @@
[package]
name = "layout_2020"
name = "layout"
version.workspace = true
authors.workspace = true
license.workspace = true
@ -8,7 +8,7 @@ publish.workspace = true
rust-version.workspace = true
[lib]
name = "layout_2020"
name = "layout"
path = "lib.rs"
test = true
doctest = false
@ -23,6 +23,7 @@ base = { workspace = true }
bitflags = { workspace = true }
canvas_traits = { workspace = true }
compositing_traits = { workspace = true }
constellation_traits = { workspace = true }
data-url = { workspace = true }
embedder_traits = { workspace = true }
euclid = { workspace = true }
@ -41,15 +42,19 @@ malloc_size_of_derive = { workspace = true }
net_traits = { workspace = true }
parking_lot = { workspace = true }
pixels = { path = "../pixels" }
profile_traits = { workspace = true }
range = { path = "../range" }
rayon = { workspace = true }
script = { path = "../script" }
script_layout_interface = { workspace = true }
script_traits = { workspace = true }
selectors = { workspace = true }
servo_arc = { workspace = true }
servo_config = { path = "../config" }
servo_geometry = { path = "../geometry" }
servo_url = { path = "../url" }
stylo = { workspace = true }
stylo_atoms = { workspace = true }
stylo_traits = { workspace = true }
taffy = { workspace = true }
tracing = { workspace = true, optional = true }

View file

@ -2,11 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// Work around https://github.com/rust-lang/rust/issues/62132
#![recursion_limit = "128"]
//! Layout. Performs layout on the DOM, builds display lists and sends them to be
//! painted.
#![allow(unsafe_code)]
use std::cell::{Cell, LazyCell, RefCell};
use std::collections::{HashMap, HashSet};
@ -29,15 +25,6 @@ use fonts::{FontContext, FontContextWebFontMethods};
use fonts_traits::StylesheetWebFontLoadFinishedCallback;
use fxhash::{FxHashMap, FxHashSet};
use ipc_channel::ipc::IpcSender;
use layout::context::LayoutContext;
use layout::display_list::{DisplayList, WebRenderImageInfo};
use layout::query::{
get_the_text_steps, process_content_box_request, process_content_boxes_request,
process_node_geometry_request, process_node_scroll_area_request, process_offset_parent_query,
process_resolved_font_style_query, process_resolved_style_request, process_text_index_request,
};
use layout::traversal::RecalcStyle;
use layout::{BoxTree, FragmentTree};
use log::{debug, error};
use malloc_size_of::{MallocConditionalSizeOf, MallocSizeOf, MallocSizeOfOps};
use net_traits::image_cache::{ImageCache, UsePlaceholder};
@ -87,8 +74,18 @@ use style::{Zero, driver};
use style_traits::{CSSPixel, SpeculativePainter};
use stylo_atoms::Atom;
use url::Url;
use webrender_api::units::{DevicePixel, LayoutPixel};
use webrender_api::{ExternalScrollId, HitTestFlags, units};
use webrender_api::units::{DevicePixel, DevicePoint, LayoutPixel, LayoutPoint, LayoutSize};
use webrender_api::{ExternalScrollId, HitTestFlags};
use crate::context::LayoutContext;
use crate::display_list::{DisplayList, WebRenderImageInfo};
use crate::query::{
get_the_text_steps, process_content_box_request, process_content_boxes_request,
process_node_geometry_request, process_node_scroll_area_request, process_offset_parent_query,
process_resolved_font_style_query, process_resolved_style_request, process_text_index_request,
};
use crate::traversal::RecalcStyle;
use crate::{BoxTree, FragmentTree};
// This mutex is necessary due to syncronisation issues between two different types of thread-local storage
// which manifest themselves when the layout thread tries to layout iframes in parallel with the main page
@ -283,7 +280,7 @@ impl Layout for LayoutThread {
// particular pipeline, so we need to tell WebRender about that.
flags.insert(HitTestFlags::POINT_RELATIVE_TO_PIPELINE_VIEWPORT);
let client_point = units::DevicePoint::from_untyped(point);
let client_point = DevicePoint::from_untyped(point);
let results = self
.compositor_api
.hit_test(Some(self.id.into()), client_point, flags);
@ -838,7 +835,7 @@ impl LayoutThread {
self.compositor_api.send_scroll_node(
self.webview_id,
self.id.into(),
units::LayoutPoint::from_untyped(point),
LayoutPoint::from_untyped(point),
state.scroll_id,
);
}
@ -867,7 +864,7 @@ impl LayoutThread {
epoch.next();
self.epoch.set(epoch);
let viewport_size = units::LayoutSize::from_untyped(Size2D::new(
let viewport_size = LayoutSize::from_untyped(Size2D::new(
self.viewport_size.width.to_f32_px(),
self.viewport_size.height.to_f32_px(),
));

View file

@ -4,6 +4,9 @@
#![deny(unsafe_code)]
//! Layout. Performs layout on the DOM, builds display lists and sends them to be
//! painted.
mod cell;
pub mod context;
pub mod display_list;
@ -15,6 +18,7 @@ mod formatting_contexts;
mod fragment_tree;
pub mod geom;
mod layout_box_base;
mod layout_impl;
mod taffy;
#[macro_use]
mod construct_modern;
@ -32,6 +36,7 @@ use app_units::Au;
pub use cell::ArcRefCell;
pub use flow::BoxTree;
pub use fragment_tree::FragmentTree;
pub use layout_impl::LayoutFactoryImpl;
use malloc_size_of_derive::MallocSizeOf;
use style::logical_geometry::WritingMode;
use style::properties::ComputedValues;

View file

@ -133,7 +133,7 @@ impl taffy::LayoutPartialTree for TaffyContainerContext<'_> {
with_independant_formatting_context(
&mut child.taffy_level_box,
|independent_context| -> taffy::LayoutOutput {
// TODO: re-evaluate sizing constraint conversions in light of recent layout_2020 changes
// TODO: re-evaluate sizing constraint conversions in light of recent layout changes
let containing_block = &self.content_box_size_override;
let style = independent_context.style();

View file

@ -11,11 +11,11 @@ use std::sync::{Mutex, MutexGuard};
use std::{thread, u32};
use app_units::Au;
use layout_2020::flow::float::{
use layout::flow::float::{
Clear, ContainingBlockPositionInfo, FloatBand, FloatBandNode, FloatBandTree, FloatContext,
FloatSide, PlacementInfo,
};
use layout_2020::geom::{LogicalRect, LogicalVec2};
use layout::geom::{LogicalRect, LogicalVec2};
use num_traits::identities::Zero;
use quickcheck::{Arbitrary, Gen};

View file

@ -6,8 +6,8 @@
mod tables {
use euclid::Vector2D;
use layout_2020::ArcRefCell;
use layout_2020::table::{Table, TableBuilder, TableSlot, TableSlotCell, TableSlotOffset};
use layout::ArcRefCell;
use layout::table::{Table, TableBuilder, TableSlot, TableSlotCell, TableSlotOffset};
fn row_lengths(table: &Table) -> Vec<usize> {
table.slots.iter().map(|row| row.len()).collect()

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
mod text {
use layout_2020::flow::inline::construct::WhitespaceCollapse;
use layout::flow::inline::construct::WhitespaceCollapse;
use style::computed_values::white_space_collapse::T as WhiteSpaceCollapse;
#[test]

View file

@ -1,48 +0,0 @@
[package]
name = "layout_thread_2020"
version.workspace = true
authors.workspace = true
license.workspace = true
edition.workspace = true
publish.workspace = true
rust-version.workspace = true
[lib]
name = "layout_thread_2020"
path = "lib.rs"
[features]
tracing = ["dep:tracing", "layout/tracing"]
[dependencies]
app_units = { workspace = true }
base = { workspace = true }
compositing_traits = { workspace = true }
constellation_traits = { workspace = true }
embedder_traits = { workspace = true }
euclid = { workspace = true }
fnv = { workspace = true }
fonts = { path = "../fonts" }
fonts_traits = { workspace = true }
fxhash = { workspace = true }
ipc-channel = { workspace = true }
layout = { path = "../layout_2020", package = "layout_2020" }
log = { workspace = true }
malloc_size_of = { workspace = true }
metrics = { path = "../metrics" }
net_traits = { workspace = true }
parking_lot = { workspace = true }
profile_traits = { workspace = true }
script = { path = "../script" }
script_layout_interface = { workspace = true }
script_traits = { workspace = true }
servo_allocator = { path = "../allocator" }
servo_arc = { workspace = true }
servo_config = { path = "../config" }
servo_url = { path = "../url" }
stylo = { workspace = true }
stylo_atoms = { workspace = true }
stylo_traits = { workspace = true }
tracing = { workspace = true, optional = true }
url = { workspace = true }
webrender_api = { workspace = true }

View file

@ -34,7 +34,15 @@ no-wgl = ["mozangle/egl", "mozangle/build_dlls", "surfman/sm-angle-default", "co
dynamic_freetype = ["webrender/dynamic_freetype"]
profilemozjs = ["script/profilemozjs"]
refcell_backtrace = ["script/refcell_backtrace"]
tracing = ["dep:tracing", "compositing/tracing", "constellation/tracing", "fonts/tracing", "layout_thread_2020/tracing", "profile_traits/tracing", "script/tracing"]
tracing = [
"dep:tracing",
"compositing/tracing",
"constellation/tracing",
"fonts/tracing",
"layout/tracing",
"profile_traits/tracing",
"script/tracing",
]
webdriver = ["webdriver_server"]
webgl_backtrace = [
"script/webgl_backtrace",
@ -79,7 +87,7 @@ gleam = { workspace = true }
gstreamer = { workspace = true, optional = true }
ipc-channel = { workspace = true }
keyboard-types = { workspace = true }
layout_thread_2020 = { path = "../layout_thread_2020" }
layout = { path = "../layout" }
log = { workspace = true }
media = { path = "../media" }
mozangle = { workspace = true }

View file

@ -84,6 +84,7 @@ use gleam::gl::RENDERER;
use ipc_channel::ipc::{self, IpcSender};
use ipc_channel::router::ROUTER;
pub use keyboard_types::*;
use layout::LayoutFactoryImpl;
use log::{Log, Metadata, Record, debug, warn};
use media::{GlApi, NativeDisplay, WindowGLContext};
use net::protocols::ProtocolRegistry;
@ -109,9 +110,9 @@ use webview::WebViewInner;
pub use webxr;
pub use {
background_hang_monitor, base, canvas, canvas_traits, devtools, devtools_traits, euclid, fonts,
ipc_channel, layout_thread_2020, media, net, net_traits, profile, profile_traits, script,
script_layout_interface, script_traits, servo_config as config, servo_config, servo_geometry,
servo_url, style, style_traits, webrender_api,
ipc_channel, media, net, net_traits, profile, profile_traits, script, script_layout_interface,
script_traits, servo_config as config, servo_config, servo_geometry, servo_url, style,
style_traits, webrender_api,
};
#[cfg(feature = "bluetooth")]
pub use {bluetooth, bluetooth_traits};
@ -1079,7 +1080,7 @@ fn create_constellation(
user_content_manager,
};
let layout_factory = Arc::new(layout_thread_2020::LayoutFactoryImpl());
let layout_factory = Arc::new(LayoutFactoryImpl());
Constellation::<script::ScriptThread, script::ServiceWorkerManager>::start(
initial_state,
@ -1156,7 +1157,7 @@ pub fn run_content_process(token: String) {
set_logger(content.script_to_constellation_chan().clone());
let background_hang_monitor_register = content.register_with_background_hang_monitor();
let layout_factory = Arc::new(layout_thread_2020::LayoutFactoryImpl());
let layout_factory = Arc::new(LayoutFactoryImpl());
content.register_system_memory_reporter();

View file

@ -168,7 +168,7 @@ class MachCommands(CommandBase):
"devtools",
"fonts",
"hyper_serde",
"layout_2020",
"layout",
"libservo",
"metrics",
"net",