diff --git a/Cargo.lock b/Cargo.lock index 90825fcbf14..33f00cb6951 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -679,6 +679,7 @@ dependencies = [ "script_traits 0.0.1", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "servo_config 0.0.1", + "servo_geometry 0.0.1", "servo_rand 0.0.1", "servo_remutex 0.0.1", "servo_url 0.0.1", diff --git a/components/config/opts.rs b/components/config/opts.rs index f5ff22070e5..9267c7ef7b4 100644 --- a/components/config/opts.rs +++ b/components/config/opts.rs @@ -80,6 +80,7 @@ pub struct Opts { /// Use ANGLE to create the GL context (Windows-only). pub angle: bool, + /// True to exit on thread failure instead of displaying about:failure. pub hard_fail: bool, /// True if we should bubble intrinsic widths sequentially (`-b`). If this is true, then diff --git a/components/constellation/Cargo.toml b/components/constellation/Cargo.toml index fc2021d3af3..b01c6f0cd90 100644 --- a/components/constellation/Cargo.toml +++ b/components/constellation/Cargo.toml @@ -43,6 +43,7 @@ script_traits = {path = "../script_traits"} serde = "1.0" style_traits = {path = "../style_traits"} servo_config = {path = "../config"} +servo_geometry = {path = "../geometry"} servo_rand = {path = "../rand"} servo_remutex = {path = "../remutex"} servo_url = {path = "../url"} diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 11967e10038..f5139c110ca 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -153,6 +153,7 @@ use script_traits::{LayoutMsg as FromLayoutMsg, ScriptMsg as FromScriptMsg, Scri use script_traits::{SWManagerMsg, ScopeThings, UpdatePipelineIdReason, WebDriverCommandMsg}; use serde::{Deserialize, Serialize}; use servo_config::{opts, pref}; +use servo_geometry::DeviceIndependentPixel; use servo_rand::{random, Rng, SeedableRng, ServoRng}; use servo_remutex::ReentrantMutex; use servo_url::{Host, ImmutableOrigin, ServoUrl}; @@ -379,6 +380,17 @@ pub struct Constellation { /// Bitmask which indicates which combination of mouse buttons are /// currently being pressed. pressed_mouse_buttons: u16, + + is_running_problem_test: bool, + + /// If True, exits on thread failure instead of displaying about:failure + hard_fail: bool, + + /// If set with --disable-canvas-aa, disable antialiasing on the HTML + /// canvas element. + /// Like --disable-text-aa, this is useful for reftests where pixel perfect + /// results are required. + enable_canvas_antialiasing: bool, } /// State needed to construct a constellation. @@ -599,6 +611,13 @@ where /// Create a new constellation thread. pub fn start( state: InitialConstellationState, + initial_window_size: TypedSize2D, + device_pixels_per_px: Option, + random_pipeline_closure_probability: Option, + random_pipeline_closure_seed: Option, + is_running_problem_test: bool, + hard_fail: bool, + enable_canvas_antialiasing: bool, ) -> (Sender, IpcSender) { let (compositor_sender, compositor_receiver) = unbounded(); @@ -685,11 +704,8 @@ where time_profiler_chan: state.time_profiler_chan, mem_profiler_chan: state.mem_profiler_chan, window_size: WindowSizeData { - initial_viewport: opts::get().initial_window_size.to_f32() * - TypedScale::new(1.0), - device_pixel_ratio: TypedScale::new( - opts::get().device_pixels_per_px.unwrap_or(1.0), - ), + initial_viewport: initial_window_size.to_f32() * TypedScale::new(1.0), + device_pixel_ratio: TypedScale::new(device_pixels_per_px.unwrap_or(1.0)), }, phantom: PhantomData, clipboard_ctx: match ClipboardContext::new() { @@ -706,22 +722,21 @@ where webrender_api_sender: state.webrender_api_sender, shutting_down: false, handled_warnings: VecDeque::new(), - random_pipeline_closure: opts::get().random_pipeline_closure_probability.map( - |prob| { - let seed = opts::get() - .random_pipeline_closure_seed - .unwrap_or_else(random); - let rng = ServoRng::from_seed(&[seed]); - warn!("Randomly closing pipelines."); - info!("Using seed {} for random pipeline closure.", seed); - (rng, prob) - }, - ), + random_pipeline_closure: random_pipeline_closure_probability.map(|prob| { + let seed = random_pipeline_closure_seed.unwrap_or_else(random); + let rng = ServoRng::from_seed(&[seed]); + warn!("Randomly closing pipelines."); + info!("Using seed {} for random pipeline closure.", seed); + (rng, prob) + }), webgl_threads: state.webgl_threads, webvr_chan: state.webvr_chan, canvas_chan: CanvasPaintThread::start(), pending_approval_navigations: HashMap::new(), pressed_mouse_buttons: 0, + is_running_problem_test, + hard_fail, + enable_canvas_antialiasing, }; constellation.run(); @@ -1165,13 +1180,13 @@ where FromCompositorMsg::IsReadyToSaveImage(pipeline_states) => { let is_ready = self.handle_is_ready_to_save_image(pipeline_states); debug!("Ready to save image {:?}.", is_ready); - if opts::get().is_running_problem_test { + if self.is_running_problem_test { println!("got ready to save image query, result is {:?}", is_ready); } let is_ready = is_ready == ReadyToSave::Ready; self.compositor_proxy .send(ToCompositorMsg::IsReadyToSaveImageReply(is_ready)); - if opts::get().is_running_problem_test { + if self.is_running_problem_test { println!("sent response"); } }, @@ -1694,7 +1709,7 @@ where reason: String, backtrace: Option, ) { - if opts::get().hard_fail { + if self.hard_fail { // It's quite difficult to make Servo exit cleanly if some threads have failed. // Hard fail exists for test runners so we crash and that's good enough. println!("Pipeline failed in hard-fail mode. Crashing!"); @@ -3155,7 +3170,7 @@ where canvas_id_sender, size, webrender_api, - opts::get().enable_canvas_antialiasing, + self.enable_canvas_antialiasing, )) { return warn!("Create canvas paint thread failed ({})", e); } diff --git a/components/constellation/pipeline.rs b/components/constellation/pipeline.rs index 2113a275e21..e1ee7af6685 100644 --- a/components/constellation/pipeline.rs +++ b/components/constellation/pipeline.rs @@ -646,7 +646,7 @@ impl UnprivilegedPipelineContent { .expect("Failed to create IPC one-shot server."); // If there is a sandbox, use the `gaol` API to create the child process. - if opts::get().sandbox { + if self.opts.sandbox { let mut command = sandbox::Command::me().expect("Failed to get current sandbox."); self.setup_common(&mut command, token); diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 5d4f0641db7..c9f9bf5c5e5 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -617,6 +617,9 @@ fn create_constellation( window_gl: Rc, webvr_services: Option, ) -> (Sender, SWManagerSenders) { + // Global configuration options, parsed from the command line. + let opts = opts::get(); + let bluetooth_thread: IpcSender = BluetoothThreadFactory::new(embedder_proxy.clone()); @@ -651,7 +654,7 @@ fn create_constellation( }; // GLContext factory used to create WebGL Contexts - let gl_factory = if opts::get().should_use_osmesa() { + let gl_factory = if opts.should_use_osmesa() { GLContextFactory::current_osmesa_handle() } else { GLContextFactory::current_native_handle(&compositor_proxy) @@ -697,7 +700,16 @@ fn create_constellation( script_layout_interface::message::Msg, layout_thread::LayoutThread, script::script_thread::ScriptThread, - >::start(initial_state); + >::start( + initial_state, + opts.initial_window_size, + opts.device_pixels_per_px, + opts.random_pipeline_closure_probability, + opts.random_pipeline_closure_seed, + opts.is_running_problem_test, + opts.hard_fail, + opts.enable_canvas_antialiasing, + ); if let Some(webvr_constellation_sender) = webvr_constellation_sender { // Set constellation channel used by WebVR thread to broadcast events