servoshell: Move headless setting to ServoShellPreferences (#35377)

This is only used in servoshell, even though it was plumbed through
script previously. It's just about how the `RenderingContext` is set up,
which is something managed entirely outside of servo itself.

In addition, make the name of `servo_shell_preferences` in `app.rs` more
consistent with the rest of the codebase.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-02-07 21:04:31 +01:00 committed by GitHub
parent 1ba5d0e093
commit e227e0913b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 20 additions and 48 deletions

View file

@ -44,7 +44,7 @@ use crate::prefs::ServoShellPreferences;
pub struct App {
opts: Opts,
preferences: Preferences,
servo_shell_preferences: ServoShellPreferences,
servoshell_preferences: ServoShellPreferences,
suspended: Cell<bool>,
windows: HashMap<WindowId, Rc<dyn WindowPortsMethods>>,
minibrowser: Option<Minibrowser>,
@ -88,7 +88,7 @@ impl App {
App {
opts,
preferences,
servo_shell_preferences,
servoshell_preferences: servo_shell_preferences,
suspended: Cell::new(false),
windows: HashMap::new(),
minibrowser: None,
@ -103,7 +103,7 @@ impl App {
/// Initialize Application once event loop start running.
pub fn init(&mut self, event_loop: Option<&ActiveEventLoop>) {
// Create rendering context
let rendering_context = if self.opts.headless {
let rendering_context = if self.servoshell_preferences.headless {
let connection = Connection::new().expect("Failed to create connection");
let adapter = connection
.create_software_adapter()
@ -128,10 +128,11 @@ impl App {
.expect("Failed to create WR surfman")
};
let window = if self.opts.headless {
let headless = self.servoshell_preferences.headless;
let window = if headless {
headless_window::Window::new(
self.opts.initial_window_size,
self.servo_shell_preferences.device_pixel_ratio_override,
self.servoshell_preferences.device_pixel_ratio_override,
self.opts.screen_size_override,
)
} else {
@ -140,8 +141,8 @@ impl App {
&rendering_context,
self.opts.initial_window_size,
event_loop.unwrap(),
self.servo_shell_preferences.no_native_titlebar,
self.servo_shell_preferences.device_pixel_ratio_override,
self.servoshell_preferences.no_native_titlebar,
self.servoshell_preferences.device_pixel_ratio_override,
))
};
@ -158,7 +159,7 @@ impl App {
self.suspended.set(false);
let (_, window) = self.windows.iter().next().unwrap();
let xr_discovery = if pref!(dom_webxr_openxr_enabled) && !self.opts.headless {
let xr_discovery = if pref!(dom_webxr_openxr_enabled) && !headless {
#[cfg(target_os = "windows")]
let openxr = {
let app_info = AppInfo::new("Servoshell", 0, "Servo", 0);
@ -168,7 +169,7 @@ impl App {
let openxr = None;
openxr
} else if pref!(dom_webxr_glwindow_enabled) && !self.opts.headless {
} else if pref!(dom_webxr_glwindow_enabled) && !headless {
let window = window.new_glwindow(event_loop.unwrap());
Some(XrDiscovery::GlWindow(GlWindowDiscovery::new(window)))
} else {
@ -202,16 +203,12 @@ impl App {
Rc::new(rendering_context),
embedder,
Rc::new(UpcastedWindow(window.clone())),
self.servo_shell_preferences.user_agent.clone(),
self.servoshell_preferences.user_agent.clone(),
composite_target,
);
servo.setup_logging();
let running_state = Rc::new(RunningAppState::new(
servo,
window.clone(),
self.opts.headless,
));
let running_state = Rc::new(RunningAppState::new(servo, window.clone(), headless));
running_state.new_toplevel_webview(self.initial_url.clone().into_url());
if let Some(ref mut minibrowser) = self.minibrowser {
@ -332,7 +329,7 @@ impl App {
minibrowser.update_location_dirty(false);
let Some(url) = location_bar_input_to_url(
&location.clone(),
&self.servo_shell_preferences.searchpage,
&self.servoshell_preferences.searchpage,
) else {
warn!("failed to parse location");
break;

View file

@ -28,7 +28,7 @@ pub fn main() {
};
let clean_shutdown = servoshell_preferences.clean_shutdown;
let event_loop = EventsLoop::new(opts.headless, opts.output_file.is_some())
let event_loop = EventsLoop::new(servoshell_preferences.headless, opts.output_file.is_some())
.expect("Failed to create events loop");
{

View file

@ -34,6 +34,9 @@ pub(crate) struct ServoShellPreferences {
/// URL string of the search engine page with '%s' standing in for the search term.
/// For example <https://duckduckgo.com/html/?q=%s>.
pub searchpage: String,
/// Whether or not to run servoshell in headless mode. While running in headless
/// mode, image output is supported.
pub headless: bool,
}
impl Default for ServoShellPreferences {
@ -46,6 +49,7 @@ impl Default for ServoShellPreferences {
homepage: "https://servo.org".into(),
no_native_titlebar: true,
searchpage: "https://duckduckgo.com/html/?q=%s".into(),
headless: false,
}
}
}
@ -539,11 +543,11 @@ pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsing
no_native_titlebar,
device_pixel_ratio_override,
clean_shutdown: opt_match.opt_present("clean-shutdown"),
headless: opt_match.opt_present("z"),
..Default::default()
};
let headless = opt_match.opt_present("z");
if headless && preferences.media_glvideo_enabled {
if servoshell_preferences.headless && preferences.media_glvideo_enabled {
warn!("GL video rendering is not supported on headless windows.");
preferences.media_glvideo_enabled = false;
}
@ -558,7 +562,6 @@ pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsing
userscripts: opt_match.opt_default("userscripts", ""),
user_stylesheets,
output_file,
headless,
hard_fail: opt_match.opt_present("f") && !opt_match.opt_present("F"),
webdriver_port,
initial_window_size,