Skip to content

Commit

Permalink
Layout_thread: removed all possible opts::get()
Browse files Browse the repository at this point in the history
  • Loading branch information
oneturkmen committed Jun 4, 2019
1 parent 2ad3066 commit 810f5ab
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion components/config/opts.rs
Expand Up @@ -54,6 +54,7 @@ pub struct Opts {
/// and cause it to produce output on that interval (`-m`).
pub mem_profiler_period: Option<f64>,

/// True to turn off incremental layout.
pub nonincremental_layout: bool,

/// Where to load userscripts from, if any. An empty string will load from
Expand Down Expand Up @@ -111,7 +112,7 @@ pub struct Opts {
pub enable_canvas_antialiasing: bool,

/// True if each step of layout is traced to an external JSON file
/// for debugging purposes. Settings this implies sequential layout
/// for debugging purposes. Setting this implies sequential layout
/// and paint.
pub trace_layout: bool,

Expand Down
11 changes: 11 additions & 0 deletions components/constellation/pipeline.rs
Expand Up @@ -580,6 +580,17 @@ impl UnprivilegedPipelineContent {
self.webrender_document,
paint_time_metrics,
layout_thread_busy_flag.clone(),
self.opts.load_webfonts_synchronously,
self.opts.initial_window_size,
self.opts.device_pixels_per_px,
self.opts.dump_display_list,
self.opts.dump_display_list_json,
self.opts.dump_style_tree,
self.opts.dump_rule_tree,
self.opts.relayout_event,
self.opts.nonincremental_layout,
self.opts.trace_layout,
self.opts.dump_flow_tree,
);

if wait_for_completion {
Expand Down
121 changes: 107 additions & 14 deletions components/layout_thread/lib.rs
Expand Up @@ -89,7 +89,7 @@ use servo_arc::Arc as ServoArc;
use servo_atoms::Atom;
use servo_config::opts;
use servo_config::pref;
use servo_geometry::MaxRect;
use servo_geometry::{DeviceIndependentPixel, MaxRect};
use servo_url::ServoUrl;
use std::borrow::ToOwned;
use std::cell::{Cell, RefCell};
Expand Down Expand Up @@ -247,6 +247,42 @@ pub struct LayoutThread {

/// Flag that indicates if LayoutThread is busy handling a request.
busy: Arc<AtomicBool>,

/// Load web fonts synchronously to avoid non-deterministic network-driven reflows.
load_webfonts_synchronously: bool,

/// The initial request size of the window
initial_window_size: TypedSize2D<u32, DeviceIndependentPixel>,

/// The ratio of device pixels per px at the default scale.
/// If unspecified, will use the platform default setting.
device_pixels_per_px: Option<f32>,

/// 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.
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 {
Expand All @@ -272,6 +308,17 @@ impl LayoutThreadFactory for LayoutThread {
webrender_document: webrender_api::DocumentId,
paint_time_metrics: PaintTimeMetrics,
busy: Arc<AtomicBool>,
load_webfonts_synchronously: bool,
initial_window_size: TypedSize2D<u32, DeviceIndependentPixel>,
device_pixels_per_px: Option<f32>,
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()
.name(format!("LayoutThread {:?}", id))
Expand Down Expand Up @@ -310,6 +357,17 @@ impl LayoutThreadFactory for LayoutThread {
webrender_document,
paint_time_metrics,
busy,
load_webfonts_synchronously,
initial_window_size,
device_pixels_per_px,
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);
Expand Down Expand Up @@ -423,8 +481,9 @@ fn add_font_face_rules(
font_cache_thread: &FontCacheThread,
font_cache_sender: &IpcSender<()>,
outstanding_web_fonts_counter: &Arc<AtomicUsize>,
load_webfonts_synchronously: bool,
) {
if opts::get().load_webfonts_synchronously {
if load_webfonts_synchronously {
let (sender, receiver) = ipc::channel().unwrap();
stylesheet.effective_font_face_rules(&device, guard, |rule| {
if let Some(font_face) = rule.font_face() {
Expand Down Expand Up @@ -472,13 +531,24 @@ impl LayoutThread {
webrender_document: webrender_api::DocumentId,
paint_time_metrics: PaintTimeMetrics,
busy: Arc<AtomicBool>,
load_webfonts_synchronously: bool,
initial_window_size: TypedSize2D<u32, DeviceIndependentPixel>,
device_pixels_per_px: Option<f32>,
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 {
// The device pixel ratio is incorrect (it does not have the hidpi value),
// but it will be set correctly when the initial reflow takes place.
let device = Device::new(
MediaType::screen(),
opts::get().initial_window_size.to_f32() * TypedScale::new(1.0),
TypedScale::new(opts::get().device_pixels_per_px.unwrap_or(1.0)),
initial_window_size.to_f32() * TypedScale::new(1.0),
TypedScale::new(device_pixels_per_px.unwrap_or(1.0)),
);

// Create the channel on which new animations can be sent.
Expand Down Expand Up @@ -550,7 +620,18 @@ impl LayoutThread {
paint_time_metrics: paint_time_metrics,
layout_query_waiting_time: Histogram::new(),
last_iframe_sizes: Default::default(),
busy: busy,
busy,
load_webfonts_synchronously,
initial_window_size,
device_pixels_per_px,
dump_display_list,
dump_display_list_json,
dump_style_tree,
dump_rule_tree,
relayout_event,
nonincremental_layout,
trace_layout,
dump_flow_tree,
}
}

Expand Down Expand Up @@ -872,6 +953,17 @@ impl LayoutThread {
self.webrender_document,
info.paint_time_metrics,
info.layout_is_busy,
self.load_webfonts_synchronously,
self.initial_window_size,
self.device_pixels_per_px,
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,
);
}

Expand Down Expand Up @@ -927,6 +1019,7 @@ impl LayoutThread {
&self.font_cache_thread,
&self.font_cache_sender,
&self.outstanding_web_fonts,
self.load_webfonts_synchronously,
);
}
}
Expand Down Expand Up @@ -1126,10 +1219,10 @@ impl LayoutThread {
}
let display_list = (*rw_data.display_list.as_ref().unwrap()).clone();

if opts::get().dump_display_list {
if self.dump_display_list {
display_list.print();
}
if opts::get().dump_display_list_json {
if self.dump_display_list_json {
println!("{}", serde_json::to_string_pretty(&display_list).unwrap());
}

Expand Down Expand Up @@ -1460,11 +1553,11 @@ impl LayoutThread {

layout_context = traversal.destroy();

if opts::get().dump_style_tree {
if self.dump_style_tree {
println!("{:?}", ShowSubtreeDataAndPrimaryValues(element.as_node()));
}

if opts::get().dump_rule_tree {
if self.dump_rule_tree {
layout_context
.style_context
.stylist
Expand Down Expand Up @@ -1630,7 +1723,7 @@ impl LayoutThread {
}

fn tick_animations(&mut self, rw_data: &mut LayoutThreadData) {
if opts::get().relayout_event {
if self.relayout_event {
println!(
"**** pipeline={}\tForDisplay\tSpecial\tAnimationTick",
self.id
Expand Down Expand Up @@ -1724,15 +1817,15 @@ impl LayoutThread {
// that are needed in both incremental and non-incremental traversals.
let damage = FlowRef::deref_mut(root_flow).compute_layout_damage();

if opts::get().nonincremental_layout ||
if self.nonincremental_layout ||
damage.contains(SpecialRestyleDamage::REFLOW_ENTIRE_DOCUMENT)
{
FlowRef::deref_mut(root_flow).reflow_entire_document()
}
},
);

if opts::get().trace_layout {
if self.trace_layout {
layout_debug::begin_trace(root_flow.clone());
}

Expand Down Expand Up @@ -1827,11 +1920,11 @@ impl LayoutThread {
rw_data,
);

if opts::get().trace_layout {
if self.trace_layout {
layout_debug::end_trace(self.generation.get());
}

if opts::get().dump_flow_tree {
if self.dump_flow_tree {
root_flow.print("Post layout flow tree".to_owned());
}

Expand Down
2 changes: 2 additions & 0 deletions components/layout_traits/Cargo.toml
Expand Up @@ -12,6 +12,7 @@ path = "lib.rs"

[dependencies]
crossbeam-channel = "0.3"
euclid = "0.19"
gfx = {path = "../gfx"}
ipc-channel = "0.11"
metrics = {path = "../metrics"}
Expand All @@ -20,4 +21,5 @@ net_traits = {path = "../net_traits"}
profile_traits = {path = "../profile_traits"}
script_traits = {path = "../script_traits"}
servo_url = {path = "../url"}
servo_geometry = {path = "../geometry"}
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
13 changes: 13 additions & 0 deletions components/layout_traits/lib.rs
Expand Up @@ -10,6 +10,7 @@
// that these modules won't have to depend on layout.

use crossbeam_channel::{Receiver, Sender};
use euclid::TypedSize2D;
use gfx::font_cache_thread::FontCacheThread;
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use metrics::PaintTimeMetrics;
Expand All @@ -19,6 +20,7 @@ use net_traits::image_cache::ImageCache;
use profile_traits::{mem, time};
use script_traits::LayoutMsg as ConstellationMsg;
use script_traits::{ConstellationControlMsg, LayoutControlMsg};
use servo_geometry::DeviceIndependentPixel;
use servo_url::ServoUrl;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
Expand Down Expand Up @@ -46,5 +48,16 @@ pub trait LayoutThreadFactory {
webrender_document: webrender_api::DocumentId,
paint_time_metrics: PaintTimeMetrics,
busy: Arc<AtomicBool>,
load_webfonts_synchronously: bool,
initial_window_size: TypedSize2D<u32, DeviceIndependentPixel>,
device_pixels_per_px: Option<f32>,
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,
);
}

0 comments on commit 810f5ab

Please sign in to comment.