Skip to content

Commit

Permalink
Make angle and disable-vsync embedder options
Browse files Browse the repository at this point in the history
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
  • Loading branch information
glowe committed Oct 26, 2019
1 parent 24b8408 commit 6eca38a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 42 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.

36 changes: 6 additions & 30 deletions components/config/opts.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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");
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ports/glutin/Cargo.toml
Expand Up @@ -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"
Expand Down
41 changes: 30 additions & 11 deletions ports/glutin/main2.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -76,16 +77,32 @@ pub fn main() {

// Parse the command line options and store them globally
let args: Vec<String> = env::args().collect();
let opts_result = opts::from_cmdline_args(&args);

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 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 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
Expand Down Expand Up @@ -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()
}
1 change: 1 addition & 0 deletions ports/libmlservo/Cargo.toml
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion ports/libsimpleservo/api/src/lib.rs
Expand Up @@ -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());
Expand Down

0 comments on commit 6eca38a

Please sign in to comment.