Script: removed a few opts::get()

This commit is contained in:
oneturkmen 2019-06-07 23:38:01 -06:00
parent 57205318c5
commit 42569280e2
17 changed files with 238 additions and 45 deletions

View file

@ -135,8 +135,8 @@ use script_traits::{ScriptToConstellationChan, TimerEvent, TimerSchedulerMsg};
use script_traits::{TimerSource, TouchEventType, TouchId, UntrustedNodeAddress, WheelDelta};
use script_traits::{UpdatePipelineIdReason, WindowSizeData, WindowSizeType};
use servo_atoms::Atom;
use servo_config::opts;
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
use std::borrow::Cow;
use std::cell::Cell;
use std::cell::RefCell;
use std::collections::{hash_map, HashMap, HashSet};
@ -644,6 +644,36 @@ pub struct ScriptThread {
/// FIXME(victor):
webrender_api_sender: RenderApiSender,
/// Periodically print out on which events script threads spend their processing time.
profile_script_events: bool,
/// Print Progressive Web Metrics to console.
print_pwm: bool,
/// Emits notifications when there is a relayout.
relayout_event: bool,
/// True if it is safe to write to the image.
prepare_for_screenshot: bool,
/// Unminify Javascript.
unminify_js: bool,
/// Where to load userscripts from, if any. An empty string will load from
/// the resources/user-agent-js directory, and if the option isn't passed userscripts
/// won't be loaded
userscripts_path: Option<String>,
/// True if headless mode.
headless: bool,
/// Replace unpaired surrogates in DOM strings with U+FFFD.
/// See <https://github.com/servo/servo/issues/6564>
replace_surrogates: bool,
/// An optional string allowing the user agent to be set for testing.
user_agent: Cow<'static, str>,
}
/// In the event of thread panic, all data on the stack runs its destructor. However, there
@ -681,6 +711,15 @@ impl ScriptThreadFactory for ScriptThread {
fn create(
state: InitialScriptState,
load_data: LoadData,
profile_script_events: bool,
print_pwm: bool,
relayout_event: bool,
prepare_for_screenshot: bool,
unminify_js: bool,
userscripts_path: Option<String>,
headless: bool,
replace_surrogates: bool,
user_agent: Cow<'static, str>,
) -> (Sender<message::Msg>, Receiver<message::Msg>) {
let (script_chan, script_port) = unbounded();
@ -703,7 +742,20 @@ impl ScriptThreadFactory for ScriptThread {
let window_size = state.window_size;
let layout_is_busy = state.layout_is_busy.clone();
let script_thread = ScriptThread::new(state, script_port, script_chan.clone());
let script_thread = ScriptThread::new(
state,
script_port,
script_chan.clone(),
profile_script_events,
print_pwm,
relayout_event,
prepare_for_screenshot,
unminify_js,
userscripts_path,
headless,
replace_surrogates,
user_agent,
);
SCRIPT_THREAD_ROOT.with(|root| {
root.set(Some(&script_thread as *const _));
@ -963,6 +1015,8 @@ impl ScriptThread {
to_constellation_sender: script_thread.script_sender.clone(),
scheduler_chan: script_thread.scheduler_chan.clone(),
image_cache: script_thread.image_cache.clone(),
is_headless: script_thread.headless,
user_agent: script_thread.user_agent.clone(),
};
Rc::new(WorkletThreadPool::spawn(init))
})
@ -1056,6 +1110,15 @@ impl ScriptThread {
state: InitialScriptState,
port: Receiver<MainThreadScriptMsg>,
chan: Sender<MainThreadScriptMsg>,
profile_script_events: bool,
print_pwm: bool,
relayout_event: bool,
prepare_for_screenshot: bool,
unminify_js: bool,
userscripts_path: Option<String>,
headless: bool,
replace_surrogates: bool,
user_agent: Cow<'static, str>,
) -> ScriptThread {
let runtime = new_rt_and_cx();
let cx = runtime.cx();
@ -1159,6 +1222,18 @@ impl ScriptThread {
webrender_document: state.webrender_document,
webrender_api_sender: state.webrender_api_sender,
profile_script_events,
print_pwm,
relayout_event,
prepare_for_screenshot,
unminify_js,
userscripts_path,
headless,
replace_surrogates,
user_agent,
}
}
@ -1537,7 +1612,7 @@ impl ScriptThread {
{
self.notify_activity_to_hang_monitor(&category);
let start = precise_time_ns();
let value = if opts::get().profile_script_events {
let value = if self.profile_script_events {
let profiler_cat = match category {
ScriptThreadEventCategory::AttachLayout => ProfilerCategory::ScriptAttachLayout,
ScriptThreadEventCategory::ConstellationMsg => {
@ -1586,7 +1661,7 @@ impl ScriptThread {
for (doc_id, doc) in self.documents.borrow().iter() {
if let Some(pipeline_id) = pipeline_id {
if pipeline_id == doc_id && end - start > MAX_TASK_NS {
if opts::get().print_pwm {
if self.print_pwm {
println!(
"Task took longer than max allowed ({:?}) {:?}",
category,
@ -2897,6 +2972,13 @@ impl ScriptThread {
self.webrender_document,
self.webrender_api_sender.clone(),
incomplete.layout_is_busy,
self.relayout_event,
self.prepare_for_screenshot,
self.unminify_js,
self.userscripts_path.clone(),
self.headless,
self.replace_surrogates,
self.user_agent.clone(),
);
// Initialize the browsing context for the window.