From 6eca38aea3178e99f2f97dda5e4d257244a01fad Mon Sep 17 00:00:00 2001 From: glowe Date: Tue, 22 Oct 2019 19:28:03 -0400 Subject: [PATCH] Make angle and disable-vsync embedder options The angle and disable-vsync options were declared as global options but only used in the Glutin embedding for desktop builds. Moving them to the Glutin embedding code makes them easier to update. Partially fixes #23009 --- Cargo.lock | 2 ++ components/config/opts.rs | 36 +++++--------------------- ports/glutin/Cargo.toml | 1 + ports/glutin/main2.rs | 39 +++++++++++++++++++++-------- ports/libmlservo/Cargo.toml | 1 + ports/libsimpleservo/api/src/lib.rs | 2 +- 6 files changed, 40 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f791057f5c..15c435e6eba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2673,6 +2673,7 @@ dependencies = [ name = "libmlservo" version = "0.0.1" dependencies = [ + "getopts", "libc", "libservo", "log", @@ -4406,6 +4407,7 @@ dependencies = [ "cc", "clipboard", "euclid", + "getopts", "gleam 0.6.18", "glutin", "image", diff --git a/components/config/opts.rs b/components/config/opts.rs index ffc557c0a46..2e2cb20a45f 100644 --- a/components/config/opts.rs +++ b/components/config/opts.rs @@ -7,7 +7,7 @@ use crate::prefs::{self, PrefValue}; use euclid::Size2D; -use getopts::Options; +use getopts::{Matches, Options}; use servo_geometry::DeviceIndependentPixel; use servo_url::ServoUrl; use std::borrow::Cow; @@ -78,9 +78,6 @@ pub struct Opts { pub headless: bool, - /// 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, @@ -187,9 +184,6 @@ pub struct Opts { /// Do not use native titlebar pub no_native_titlebar: bool, - /// Enable vsync in the compositor - pub enable_vsync: bool, - /// True to show webrender profiling stats on screen. pub webrender_stats: bool, @@ -314,9 +308,6 @@ pub struct DebugOptions { /// Load web fonts synchronously to avoid non-deterministic network-driven reflows. pub load_webfonts_synchronously: bool, - /// Disable vsync in the compositor - pub disable_vsync: bool, - /// Show webrender profiling stats on screen. pub webrender_stats: bool, @@ -368,7 +359,6 @@ impl DebugOptions { "replace-surrogates" => self.replace_surrogates = true, "gc-profile" => self.gc_profile = true, "load-webfonts-synchronously" => self.load_webfonts_synchronously = true, - "disable-vsync" => self.disable_vsync = true, "wr-stats" => self.webrender_stats = true, "wr-record" => self.webrender_record = true, "wr-no-batch" => self.webrender_disable_batch = true, @@ -462,10 +452,6 @@ fn print_debug_usage(app: &str) -> ! { "load-webfonts-synchronously", "Load web fonts synchronously to avoid non-deterministic network-driven reflows", ); - print_option( - "disable-vsync", - "Disable vsync mode in the compositor to allow profiling at more than monitor refresh rate", - ); print_option("wr-stats", "Show WebRender profiler on screen."); print_option("msaa", "Use multisample antialiasing in WebRender."); print_option("full-backtraces", "Print full backtraces for all errors"); @@ -564,7 +550,6 @@ pub fn default_opts() -> Opts { gc_profile: false, load_webfonts_synchronously: false, headless: false, - angle: false, hard_fail: true, bubble_inline_sizes_separately: false, show_debug_fragment_borders: false, @@ -595,7 +580,6 @@ pub fn default_opts() -> Opts { convert_mouse_to_touch: false, exit_after_load: false, no_native_titlebar: false, - enable_vsync: true, webrender_stats: false, use_msaa: false, config_dir: None, @@ -613,10 +597,9 @@ pub fn default_opts() -> Opts { } } -pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { +pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingResult { let (app_name, args) = args.split_first().unwrap(); - let mut opts = Options::new(); opts.optflag("c", "cpu", "CPU painting"); opts.optflag("g", "gpu", "GPU painting"); opts.optopt("o", "output", "Output file", "output.png"); @@ -673,11 +656,6 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { "", ); opts.optflag("z", "headless", "Headless mode"); - opts.optflag( - "", - "angle", - "Use ANGLE to create a GL context (Windows-only)", - ); opts.optflag( "f", "hard-fail", @@ -793,7 +771,7 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { // some dummy options for now. if let Some(content_process) = opt_match.opt_str("content-process") { MULTIPROCESS.store(true, Ordering::SeqCst); - return ArgumentParsingResult::ContentProcess(content_process); + return ArgumentParsingResult::ContentProcess(opt_match, content_process); } let mut debug_options = DebugOptions::default(); @@ -1010,7 +988,6 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { gc_profile: debug_options.gc_profile, load_webfonts_synchronously: debug_options.load_webfonts_synchronously, headless: opt_match.opt_present("z"), - angle: opt_match.opt_present("angle"), hard_fail: opt_match.opt_present("f") && !opt_match.opt_present("F"), bubble_inline_sizes_separately: bubble_inline_sizes_separately, profile_script_events: debug_options.profile_script_events, @@ -1041,7 +1018,6 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { convert_mouse_to_touch: debug_options.convert_mouse_to_touch, exit_after_load: opt_match.opt_present("x"), no_native_titlebar: do_not_use_native_titlebar, - enable_vsync: !debug_options.disable_vsync, webrender_stats: debug_options.webrender_stats, use_msaa: debug_options.use_msaa, config_dir: opt_match.opt_str("config-dir").map(Into::into), @@ -1074,12 +1050,12 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { set_pref!(layout.threads, layout_threads as i64); } - ArgumentParsingResult::ChromeProcess + return ArgumentParsingResult::ChromeProcess(opt_match); } pub enum ArgumentParsingResult { - ChromeProcess, - ContentProcess(String), + ChromeProcess(Matches), + ContentProcess(Matches, String), } // Make Opts available globally. This saves having to clone and pass diff --git a/ports/glutin/Cargo.toml b/ports/glutin/Cargo.toml index a9f786e7f54..3b490d73e30 100644 --- a/ports/glutin/Cargo.toml +++ b/ports/glutin/Cargo.toml @@ -49,6 +49,7 @@ vslatestinstalled = ["libservo/vslatestinstalled"] backtrace = "0.3" clipboard = "0.5" euclid = "0.20" +getopts = "0.2.11" gleam = "0.6" glutin = "0.21.0" keyboard-types = "0.4.3" diff --git a/ports/glutin/main2.rs b/ports/glutin/main2.rs index 733a16036e6..e0224e64daa 100644 --- a/ports/glutin/main2.rs +++ b/ports/glutin/main2.rs @@ -24,6 +24,7 @@ mod window_trait; use app::App; use backtrace::Backtrace; +use getopts::Options; use servo::config::opts::{self, ArgumentParsingResult}; use servo::config::servo_version; use std::env; @@ -76,16 +77,32 @@ pub fn main() { // Parse the command line options and store them globally let args: Vec = env::args().collect(); - let opts_result = opts::from_cmdline_args(&args); + let mut opts = Options::new(); + opts.optflag( + "", + "angle", + "Use ANGLE to create a GL context (Windows-only)", + ); + opts.optflag( + "", + "disable-vsync", + "Disable vsync mode in the compositor to allow profiling at more than monitor refresh rate", + ); - let content_process_token = if let ArgumentParsingResult::ContentProcess(token) = opts_result { - Some(token) - } else { - if opts::get().is_running_problem_test && env::var("RUST_LOG").is_err() { - env::set_var("RUST_LOG", "compositing::constellation"); - } - - None + let opts_matches; + let content_process_token; + match opts::from_cmdline_args(opts, &args) { + ArgumentParsingResult::ContentProcess(matches, token) => { + opts_matches = matches; + content_process_token = Some(token); + if opts::get().is_running_problem_test && env::var("RUST_LOG").is_err() { + env::set_var("RUST_LOG", "compositing::constellation"); + } + }, + ArgumentParsingResult::ChromeProcess(matches) => { + opts_matches = matches; + content_process_token = None; + }, }; // TODO: once log-panics is released, can this be replaced by @@ -128,7 +145,9 @@ pub fn main() { process::exit(0); } - App::run(opts::get().angle, opts::get().enable_vsync); + let angle = opts_matches.opt_present("angle"); + let enable_vsync = !opts_matches.opt_present("disable-vsync"); + App::run(angle, enable_vsync); platform::deinit() } diff --git a/ports/libmlservo/Cargo.toml b/ports/libmlservo/Cargo.toml index 4c4ef0e8b1b..4809675761c 100644 --- a/ports/libmlservo/Cargo.toml +++ b/ports/libmlservo/Cargo.toml @@ -25,6 +25,7 @@ simpleservo = { path = "../libsimpleservo/api", features = ["no_static_freetype" rust-webvr = { version = "0.16", features = ["magicleap"] } webxr-api = { git = "https://github.com/servo/webxr", features = ["ipc"] } webxr = { git = "https://github.com/servo/webxr", features = ["ipc", "magicleap"] } +getopts = "0.2.11" libc = "0.2" log = "0.4" servo-egl = "0.2" diff --git a/ports/libsimpleservo/api/src/lib.rs b/ports/libsimpleservo/api/src/lib.rs index 8f4d314932b..97d22dba867 100644 --- a/ports/libsimpleservo/api/src/lib.rs +++ b/ports/libsimpleservo/api/src/lib.rs @@ -171,7 +171,7 @@ pub fn init( gfx.subpixel_text_antialiasing.enabled, init_opts.enable_subpixel_text_antialiasing ); - opts::from_cmdline_args(&args); + opts::from_cmdline_args(Options::new(), &args); } let embedder_url = init_opts.url.as_ref().and_then(|s| ServoUrl::parse(s).ok());