Clean up arguments passed to and stored in LayoutThread

This commit is contained in:
Martin Robinson 2023-05-01 13:36:56 +02:00
parent dc192172ad
commit 040816b78d
4 changed files with 46 additions and 191 deletions

View file

@ -607,16 +607,7 @@ impl UnprivilegedPipelineContent {
self.webrender_api_sender, self.webrender_api_sender,
paint_time_metrics, paint_time_metrics,
layout_thread_busy_flag.clone(), layout_thread_busy_flag.clone(),
self.opts.debug.load_webfonts_synchronously,
self.window_size, self.window_size,
self.opts.debug.dump_display_list,
self.opts.debug.dump_display_list_json,
self.opts.debug.dump_style_tree,
self.opts.debug.dump_rule_tree,
self.opts.debug.relayout_event,
self.opts.nonincremental_layout,
self.opts.debug.trace_layout,
self.opts.debug.dump_flow_tree,
); );
if wait_for_completion { if wait_for_completion {

View file

@ -86,7 +86,7 @@ use script_traits::{Painter, WebrenderIpcSender};
use script_traits::{ScrollState, UntrustedNodeAddress, WindowSizeData}; use script_traits::{ScrollState, UntrustedNodeAddress, WindowSizeData};
use servo_arc::Arc as ServoArc; use servo_arc::Arc as ServoArc;
use servo_atoms::Atom; use servo_atoms::Atom;
use servo_config::opts; use servo_config::opts::{self, DebugOptions};
use servo_url::{ImmutableOrigin, ServoUrl}; use servo_url::{ImmutableOrigin, ServoUrl};
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
@ -221,34 +221,12 @@ pub struct LayoutThread {
/// Flag that indicates if LayoutThread is busy handling a request. /// Flag that indicates if LayoutThread is busy handling a request.
busy: Arc<AtomicBool>, busy: Arc<AtomicBool>,
/// Load web fonts synchronously to avoid non-deterministic network-driven reflows. /// Debug options, copied from configuration to this `LayoutThread` in order
load_webfonts_synchronously: bool, /// to avoid having to constantly access the thread-safe global options.
debug: DebugOptions,
/// Dumps the display list form after a layout.
dump_display_list: bool,
/// Dumps the display list in JSON form after a layout.
dump_display_list_json: bool,
/// Dumps the DOM after restyle.
dump_style_tree: bool,
/// Dumps the flow tree after a layout.
dump_rule_tree: bool,
/// Emits notifications when there is a relayout.
relayout_event: bool,
/// True to turn off incremental layout. /// True to turn off incremental layout.
nonincremental_layout: bool, nonincremental_layout: bool,
/// True if each step of layout is traced to an external JSON file
/// for debugging purposes. Setting this implies sequential layout
/// and paint.
trace_layout: bool,
/// Dumps the flow tree after a layout.
dump_flow_tree: bool,
} }
impl LayoutThreadFactory for LayoutThread { impl LayoutThreadFactory for LayoutThread {
@ -272,16 +250,7 @@ impl LayoutThreadFactory for LayoutThread {
webrender_api_sender: WebrenderIpcSender, webrender_api_sender: WebrenderIpcSender,
paint_time_metrics: PaintTimeMetrics, paint_time_metrics: PaintTimeMetrics,
busy: Arc<AtomicBool>, busy: Arc<AtomicBool>,
load_webfonts_synchronously: bool,
window_size: WindowSizeData, window_size: WindowSizeData,
dump_display_list: bool,
dump_display_list_json: bool,
dump_style_tree: bool,
dump_rule_tree: bool,
relayout_event: bool,
nonincremental_layout: bool,
trace_layout: bool,
dump_flow_tree: bool,
) { ) {
thread::Builder::new() thread::Builder::new()
.name(format!("Layout{}", id)) .name(format!("Layout{}", id))
@ -320,16 +289,7 @@ impl LayoutThreadFactory for LayoutThread {
webrender_api_sender, webrender_api_sender,
paint_time_metrics, paint_time_metrics,
busy, busy,
load_webfonts_synchronously,
window_size, window_size,
dump_display_list,
dump_display_list_json,
dump_style_tree,
dump_rule_tree,
relayout_event,
nonincremental_layout,
trace_layout,
dump_flow_tree,
); );
let reporter_name = format!("layout-reporter-{}", id); let reporter_name = format!("layout-reporter-{}", id);
@ -489,16 +449,7 @@ impl LayoutThread {
webrender_api: WebrenderIpcSender, webrender_api: WebrenderIpcSender,
paint_time_metrics: PaintTimeMetrics, paint_time_metrics: PaintTimeMetrics,
busy: Arc<AtomicBool>, busy: Arc<AtomicBool>,
load_webfonts_synchronously: bool,
window_size: WindowSizeData, window_size: WindowSizeData,
dump_display_list: bool,
dump_display_list_json: bool,
dump_style_tree: bool,
dump_rule_tree: bool,
relayout_event: bool,
nonincremental_layout: bool,
trace_layout: bool,
dump_flow_tree: bool,
) -> LayoutThread { ) -> LayoutThread {
// Let webrender know about this pipeline by sending an empty display list. // Let webrender know about this pipeline by sending an empty display list.
webrender_api.send_initial_transaction(id.to_webrender()); webrender_api.send_initial_transaction(id.to_webrender());
@ -519,22 +470,22 @@ impl LayoutThread {
ROUTER.route_ipc_receiver_to_new_crossbeam_receiver(ipc_font_cache_receiver); ROUTER.route_ipc_receiver_to_new_crossbeam_receiver(ipc_font_cache_receiver);
LayoutThread { LayoutThread {
id: id, id,
top_level_browsing_context_id: top_level_browsing_context_id, top_level_browsing_context_id: top_level_browsing_context_id,
url: url, url,
is_iframe: is_iframe, is_iframe,
port: port, port,
pipeline_port: pipeline_receiver, pipeline_port: pipeline_receiver,
script_chan: script_chan, script_chan,
background_hang_monitor, background_hang_monitor,
constellation_chan: constellation_chan.clone(), constellation_chan: constellation_chan.clone(),
time_profiler_chan: time_profiler_chan, time_profiler_chan,
mem_profiler_chan: mem_profiler_chan, mem_profiler_chan,
registered_painters: RegisteredPaintersImpl(Default::default()), registered_painters: RegisteredPaintersImpl(Default::default()),
image_cache: image_cache, image_cache,
font_cache_thread: font_cache_thread, font_cache_thread,
first_reflow: Cell::new(true), first_reflow: Cell::new(true),
font_cache_receiver: font_cache_receiver, font_cache_receiver,
font_cache_sender: ipc_font_cache_sender, font_cache_sender: ipc_font_cache_sender,
parallel_flag: true, parallel_flag: true,
generation: Cell::new(0), generation: Cell::new(0),
@ -546,7 +497,7 @@ impl LayoutThread {
webrender_api, webrender_api,
stylist: Stylist::new(device, QuirksMode::NoQuirks), stylist: Stylist::new(device, QuirksMode::NoQuirks),
rw_data: Arc::new(Mutex::new(LayoutThreadData { rw_data: Arc::new(Mutex::new(LayoutThreadData {
constellation_chan: constellation_chan, constellation_chan,
display_list: None, display_list: None,
indexable_text: IndexableText::default(), indexable_text: IndexableText::default(),
content_box_response: None, content_box_response: None,
@ -564,19 +515,12 @@ impl LayoutThread {
inner_window_dimensions_response: None, inner_window_dimensions_response: None,
})), })),
webrender_image_cache: Arc::new(RwLock::new(FnvHashMap::default())), webrender_image_cache: Arc::new(RwLock::new(FnvHashMap::default())),
paint_time_metrics: paint_time_metrics, paint_time_metrics,
layout_query_waiting_time: Histogram::new(), layout_query_waiting_time: Histogram::new(),
last_iframe_sizes: Default::default(), last_iframe_sizes: Default::default(),
busy, busy,
load_webfonts_synchronously, debug: opts::get().debug.clone(),
dump_display_list, nonincremental_layout: opts::get().nonincremental_layout,
dump_display_list_json,
dump_style_tree,
dump_rule_tree,
relayout_event,
nonincremental_layout,
trace_layout,
dump_flow_tree,
} }
} }
@ -855,16 +799,7 @@ impl LayoutThread {
self.webrender_api.clone(), self.webrender_api.clone(),
info.paint_time_metrics, info.paint_time_metrics,
info.layout_is_busy, info.layout_is_busy,
self.load_webfonts_synchronously,
info.window_size, info.window_size,
self.dump_display_list,
self.dump_display_list_json,
self.dump_style_tree,
self.dump_rule_tree,
self.relayout_event,
self.nonincremental_layout,
self.trace_layout,
self.dump_flow_tree,
); );
} }
@ -917,7 +852,7 @@ impl LayoutThread {
&self.font_cache_thread, &self.font_cache_thread,
&self.font_cache_sender, &self.font_cache_sender,
&self.outstanding_web_fonts, &self.outstanding_web_fonts,
self.load_webfonts_synchronously, self.debug.load_webfonts_synchronously,
); );
} }
} }
@ -1124,10 +1059,10 @@ impl LayoutThread {
let display_list = rw_data.display_list.as_mut().unwrap(); let display_list = rw_data.display_list.as_mut().unwrap();
if self.dump_display_list { if self.debug.dump_display_list {
display_list.print(); display_list.print();
} }
if self.dump_display_list_json { if self.debug.dump_display_list_json {
println!("{}", serde_json::to_string_pretty(&display_list).unwrap()); println!("{}", serde_json::to_string_pretty(&display_list).unwrap());
} }
@ -1467,14 +1402,14 @@ impl LayoutThread {
layout_context = traversal.destroy(); layout_context = traversal.destroy();
if self.dump_style_tree { if self.debug.dump_style_tree {
println!( println!(
"{:?}", "{:?}",
ShowSubtreeDataAndPrimaryValues(root_element.as_node()) ShowSubtreeDataAndPrimaryValues(root_element.as_node())
); );
} }
if self.dump_rule_tree { if self.debug.dump_rule_tree {
layout_context layout_context
.style_context .style_context
.stylist .stylist
@ -1724,7 +1659,7 @@ impl LayoutThread {
}, },
); );
if self.trace_layout { if self.debug.trace_layout {
layout_debug::begin_trace(root_flow.clone()); layout_debug::begin_trace(root_flow.clone());
} }
@ -1821,11 +1756,11 @@ impl LayoutThread {
rw_data, rw_data,
); );
if self.trace_layout { if self.debug.trace_layout {
layout_debug::end_trace(self.generation.get()); layout_debug::end_trace(self.generation.get());
} }
if self.dump_flow_tree { if self.debug.dump_flow_tree {
root_flow.print("Post layout flow tree".to_owned()); root_flow.print("Post layout flow tree".to_owned());
} }

View file

@ -71,7 +71,7 @@ use script_traits::{
}; };
use servo_arc::Arc as ServoArc; use servo_arc::Arc as ServoArc;
use servo_atoms::Atom; use servo_atoms::Atom;
use servo_config::opts; use servo_config::opts::{self, DebugOptions};
use servo_url::{ImmutableOrigin, ServoUrl}; use servo_url::{ImmutableOrigin, ServoUrl};
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::collections::HashMap; use std::collections::HashMap;
@ -200,30 +200,9 @@ pub struct LayoutThread {
/// Flag that indicates if LayoutThread is busy handling a request. /// Flag that indicates if LayoutThread is busy handling a request.
busy: Arc<AtomicBool>, busy: Arc<AtomicBool>,
/// Load web fonts synchronously to avoid non-deterministic network-driven reflows. /// Debug options, copied from configuration to this `LayoutThread` in order
load_webfonts_synchronously: bool, /// to avoid having to constantly access the thread-safe global options.
debug: DebugOptions,
/// Dumps the display list form after a layout.
dump_display_list: bool,
/// Dumps the display list in JSON form after a layout.
dump_display_list_json: bool,
/// Dumps the DOM after restyle.
dump_style_tree: bool,
/// Dumps the flow tree after a layout.
dump_rule_tree: bool,
/// Dumps the flow tree after a layout.
dump_flow_tree: bool,
/// Emits notifications when there is a relayout.
relayout_event: bool,
/// True if each step of layout is traced to an external JSON file
/// for debugging purposes.
trace_layout: bool,
} }
impl LayoutThreadFactory for LayoutThread { impl LayoutThreadFactory for LayoutThread {
@ -247,16 +226,7 @@ impl LayoutThreadFactory for LayoutThread {
webrender_api_sender: WebrenderIpcSender, webrender_api_sender: WebrenderIpcSender,
paint_time_metrics: PaintTimeMetrics, paint_time_metrics: PaintTimeMetrics,
busy: Arc<AtomicBool>, busy: Arc<AtomicBool>,
load_webfonts_synchronously: bool,
window_size: WindowSizeData, window_size: WindowSizeData,
dump_display_list: bool,
dump_display_list_json: bool,
dump_style_tree: bool,
dump_rule_tree: bool,
relayout_event: bool,
_nonincremental_layout: bool,
trace_layout: bool,
dump_flow_tree: bool,
) { ) {
thread::Builder::new() thread::Builder::new()
.name(format!("Layout{}", id)) .name(format!("Layout{}", id))
@ -295,15 +265,7 @@ impl LayoutThreadFactory for LayoutThread {
webrender_api_sender, webrender_api_sender,
paint_time_metrics, paint_time_metrics,
busy, busy,
load_webfonts_synchronously,
window_size, window_size,
relayout_event,
dump_display_list,
dump_display_list_json,
dump_style_tree,
dump_rule_tree,
dump_flow_tree,
trace_layout,
); );
let reporter_name = format!("layout-reporter-{}", id); let reporter_name = format!("layout-reporter-{}", id);
@ -463,15 +425,7 @@ impl LayoutThread {
webrender_api_sender: WebrenderIpcSender, webrender_api_sender: WebrenderIpcSender,
paint_time_metrics: PaintTimeMetrics, paint_time_metrics: PaintTimeMetrics,
busy: Arc<AtomicBool>, busy: Arc<AtomicBool>,
load_webfonts_synchronously: bool,
window_size: WindowSizeData, window_size: WindowSizeData,
relayout_event: bool,
dump_display_list: bool,
dump_display_list_json: bool,
dump_style_tree: bool,
dump_rule_tree: bool,
dump_flow_tree: bool,
trace_layout: bool,
) -> LayoutThread { ) -> LayoutThread {
// Let webrender know about this pipeline by sending an empty display list. // Let webrender know about this pipeline by sending an empty display list.
webrender_api_sender.send_initial_transaction(id.to_webrender()); webrender_api_sender.send_initial_transaction(id.to_webrender());
@ -494,22 +448,22 @@ impl LayoutThread {
ROUTER.route_ipc_receiver_to_new_crossbeam_receiver(ipc_font_cache_receiver); ROUTER.route_ipc_receiver_to_new_crossbeam_receiver(ipc_font_cache_receiver);
LayoutThread { LayoutThread {
id: id, id,
top_level_browsing_context_id: top_level_browsing_context_id, top_level_browsing_context_id: top_level_browsing_context_id,
url: url, url,
is_iframe: is_iframe, is_iframe,
port: port, port,
pipeline_port: pipeline_receiver, pipeline_port: pipeline_receiver,
constellation_chan, constellation_chan,
script_chan: script_chan.clone(), script_chan: script_chan.clone(),
background_hang_monitor, background_hang_monitor,
time_profiler_chan: time_profiler_chan, time_profiler_chan,
mem_profiler_chan: mem_profiler_chan, mem_profiler_chan,
registered_painters: RegisteredPaintersImpl(Default::default()), registered_painters: RegisteredPaintersImpl(Default::default()),
image_cache, image_cache,
font_cache_thread: font_cache_thread, font_cache_thread,
first_reflow: Cell::new(true), first_reflow: Cell::new(true),
font_cache_receiver: font_cache_receiver, font_cache_receiver,
font_cache_sender: ipc_font_cache_sender, font_cache_sender: ipc_font_cache_sender,
generation: Cell::new(0), generation: Cell::new(0),
outstanding_web_fonts: Arc::new(AtomicUsize::new(0)), outstanding_web_fonts: Arc::new(AtomicUsize::new(0)),
@ -540,14 +494,7 @@ impl LayoutThread {
paint_time_metrics: paint_time_metrics, paint_time_metrics: paint_time_metrics,
last_iframe_sizes: Default::default(), last_iframe_sizes: Default::default(),
busy, busy,
load_webfonts_synchronously, debug: opts::get().debug.clone(),
relayout_event,
dump_display_list,
dump_display_list_json,
dump_style_tree,
dump_rule_tree,
dump_flow_tree,
trace_layout,
} }
} }
@ -803,16 +750,7 @@ impl LayoutThread {
self.webrender_api.clone(), self.webrender_api.clone(),
info.paint_time_metrics, info.paint_time_metrics,
info.layout_is_busy, info.layout_is_busy,
self.load_webfonts_synchronously,
info.window_size, info.window_size,
self.dump_display_list,
self.dump_display_list_json,
self.dump_style_tree,
self.dump_rule_tree,
self.relayout_event,
true, // nonincremental_layout
self.trace_layout, // trace_layout
self.dump_flow_tree, // dump_flow_tree
); );
} }
@ -850,7 +788,7 @@ impl LayoutThread {
&self.font_cache_thread, &self.font_cache_thread,
&self.font_cache_sender, &self.font_cache_sender,
&self.outstanding_web_fonts, &self.outstanding_web_fonts,
self.load_webfonts_synchronously, self.debug.load_webfonts_synchronously,
); );
} }
} }
@ -1116,14 +1054,14 @@ impl LayoutThread {
unsafe { element.unset_snapshot_flags() } unsafe { element.unset_snapshot_flags() }
} }
if self.dump_style_tree { if self.debug.dump_style_tree {
println!( println!(
"{:?}", "{:?}",
style::dom::ShowSubtreeDataAndPrimaryValues(root_element.as_node()) style::dom::ShowSubtreeDataAndPrimaryValues(root_element.as_node())
); );
} }
if self.dump_rule_tree { if self.debug.dump_rule_tree {
layout_context layout_context
.style_context .style_context
.stylist .stylist
@ -1302,7 +1240,7 @@ impl LayoutThread {
&fragment_tree, &fragment_tree,
); );
if self.trace_layout { if self.debug.trace_layout {
if let Some(box_tree) = &*self.box_tree.borrow() { if let Some(box_tree) = &*self.box_tree.borrow() {
layout_debug::begin_trace(box_tree.clone(), fragment_tree.clone()); layout_debug::begin_trace(box_tree.clone(), fragment_tree.clone());
} }
@ -1330,13 +1268,13 @@ impl LayoutThread {
// the display list for printing the serialized version when `finalize()` is called. // the display list for printing the serialized version when `finalize()` is called.
// We need to call this before adding any display items so that they are printed // We need to call this before adding any display items so that they are printed
// during `finalize()`. // during `finalize()`.
if self.dump_display_list { if self.debug.dump_display_list {
display_list.wr.dump_serialized_display_list(); display_list.wr.dump_serialized_display_list();
} }
fragment_tree.build_display_list(&mut display_list); fragment_tree.build_display_list(&mut display_list);
if self.dump_flow_tree { if self.debug.dump_flow_tree {
fragment_tree.print(); fragment_tree.print();
} }
debug!("Layout done!"); debug!("Layout done!");
@ -1364,7 +1302,7 @@ impl LayoutThread {
self.update_iframe_sizes(display_list.iframe_sizes); self.update_iframe_sizes(display_list.iframe_sizes);
if self.trace_layout { if self.debug.trace_layout {
layout_debug::end_trace(self.generation.get()); layout_debug::end_trace(self.generation.get());
} }

View file

@ -46,15 +46,6 @@ pub trait LayoutThreadFactory {
webrender_api_sender: WebrenderIpcSender, webrender_api_sender: WebrenderIpcSender,
paint_time_metrics: PaintTimeMetrics, paint_time_metrics: PaintTimeMetrics,
busy: Arc<AtomicBool>, busy: Arc<AtomicBool>,
load_webfonts_synchronously: bool,
window_size: WindowSizeData, window_size: WindowSizeData,
dump_display_list: bool,
dump_display_list_json: bool,
dump_style_tree: bool,
dump_rule_tree: bool,
relayout_event: bool,
nonincremental_layout: bool,
trace_layout: bool,
dump_flow_tree: bool,
); );
} }