diff options
author | Martin Robinson <mrobinson@igalia.com> | 2024-02-23 09:14:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-23 08:14:10 +0000 |
commit | 9c0561536d37f64c028d67648091a314b5b88f6f (patch) | |
tree | d9376aebb1970cb89adb76b610e7176a58e7c7da /components/shared/script_layout/message.rs | |
parent | 4849ba901efab9304d71b316ec9e0d7e98e1993b (diff) | |
download | servo-9c0561536d37f64c028d67648091a314b5b88f6f.tar.gz servo-9c0561536d37f64c028d67648091a314b5b88f6f.zip |
script: Do not run layout in a thread (#31346)
* script: Do not run layout in a thread
Instead of spawning a thread for layout that almost always runs
synchronously with script, simply run layout in the script thread.
This is a resurrection of #28708, taking just the bits that remove the
layout thread. It's a complex change and thus is just a first step
toward cleaning up the interface between script and layout. Messages are
still passed from script to layout via a `process()` method and script
proxies some messages to layout from other threads as well.
Big changes:
1. Layout is created in the script thread on Document load, thus every
live document is guaranteed to have a layout. This isn't completely
hidden in the interface, but we can safely `unwrap()` on a Document's
layout.
2. Layout configuration is abstracted away into a LayoutConfig struct
and the LayoutFactory is a struct passed around by the Constellation.
This is to avoid having to monomorphize the entire script thread
for each layout.
3. Instead of having the Constellation block on the layout thread to
figure out the current epoch and whether there are pending web fonts
loading, updates are sent synchronously to the Constellation when
rendering to a screenshot. This practically only used by the WPT.
A couple tests start to fail, which is probably inevitable since removing
the layout thread has introduced timing changes in "exit after load" and
screenshot behavior.
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
* Update test expectations
* Fix some issues found during review
* Clarify some comments
* Address review comments
---------
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
Diffstat (limited to 'components/shared/script_layout/message.rs')
-rw-r--r-- | components/shared/script_layout/message.rs | 60 |
1 files changed, 6 insertions, 54 deletions
diff --git a/components/shared/script_layout/message.rs b/components/shared/script_layout/message.rs index a83557757a4..d07272821b0 100644 --- a/components/shared/script_layout/message.rs +++ b/components/shared/script_layout/message.rs @@ -2,26 +2,16 @@ * 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/. */ -use std::sync::atomic::AtomicBool; -use std::sync::Arc; - use app_units::Au; -use crossbeam_channel::{Receiver, Sender}; +use crossbeam_channel::Sender; use euclid::default::{Point2D, Rect}; -use gfx_traits::Epoch; -use ipc_channel::ipc::{IpcReceiver, IpcSender}; use malloc_size_of_derive::MallocSizeOf; -use metrics::PaintTimeMetrics; -use msg::constellation_msg::{BackgroundHangMonitorRegister, BrowsingContextId, PipelineId}; -use net_traits::image_cache::ImageCache; +use msg::constellation_msg::BrowsingContextId; use profile_traits::mem::ReportsChan; -use script_traits::{ - ConstellationControlMsg, LayoutControlMsg, LayoutMsg as ConstellationMsg, Painter, ScrollState, - WindowSizeData, -}; +use script_traits::{Painter, ScrollState, WindowSizeData}; use servo_arc::Arc as ServoArc; use servo_atoms::Atom; -use servo_url::{ImmutableOrigin, ServoUrl}; +use servo_url::ImmutableOrigin; use style::animation::DocumentAnimationSet; use style::context::QuirksMode; use style::dom::OpaqueNode; @@ -52,42 +42,19 @@ pub enum Msg { /// Get an RPC interface. GetRPC(Sender<Box<dyn LayoutRPC + Send>>), - /// Requests that the layout thread measure its memory usage. The resulting reports are sent back + /// Requests that layout measure its memory usage. The resulting reports are sent back /// via the supplied channel. CollectReports(ReportsChan), - /// Requests that the layout thread enter a quiescent state in which no more messages are - /// accepted except `ExitMsg`. A response message will be sent on the supplied channel when - /// this happens. - PrepareToExit(Sender<()>), - - /// Requests that the layout thread immediately shut down. There must be no more nodes left after + /// Requests that layout immediately shut down. There must be no more nodes left after /// this, or layout will crash. ExitNow, - /// Get the last epoch counter for this layout thread. - GetCurrentEpoch(IpcSender<Epoch>), - - /// Asks the layout thread whether any Web fonts have yet to load (if true, loads are pending; - /// false otherwise). - GetWebFontLoadState(IpcSender<bool>), - - /// Creates a new layout thread. - /// - /// This basically exists to keep the script-layout dependency one-way. - CreateLayoutThread(LayoutThreadInit), - - /// Set the final Url. - SetFinalUrl(ServoUrl), - /// Tells layout about the new scrolling offsets of each scrollable stacking context. SetScrollStates(Vec<ScrollState>), /// Tells layout that script has added some paint worklet modules. RegisterPaint(Atom, Vec<Atom>, Box<dyn Painter>), - - /// Send to layout the precise time when the navigation started. - SetNavigationStart(u64), } #[derive(Debug, PartialEq)] @@ -218,21 +185,6 @@ pub struct ScriptReflow { pub animations: DocumentAnimationSet, } -pub struct LayoutThreadInit { - pub id: PipelineId, - pub url: ServoUrl, - pub is_parent: bool, - pub layout_pair: (Sender<Msg>, Receiver<Msg>), - pub pipeline_port: IpcReceiver<LayoutControlMsg>, - pub background_hang_monitor_register: Box<dyn BackgroundHangMonitorRegister>, - pub constellation_chan: IpcSender<ConstellationMsg>, - pub script_chan: IpcSender<ConstellationControlMsg>, - pub image_cache: Arc<dyn ImageCache>, - pub paint_time_metrics: PaintTimeMetrics, - pub layout_is_busy: Arc<AtomicBool>, - pub window_size: WindowSizeData, -} - /// A pending restyle. #[derive(Debug, MallocSizeOf)] pub struct PendingRestyle { |