mirror of
https://github.com/servo/servo.git
synced 2025-08-02 12:10:29 +01:00
No more headless compositor. Just the normal one.
This changes headless operation to strictly be a runtime option, rather than a compile-time one. Note that the old headless version still relied on a display server to support WebGL, while it now requires one all the time. Fixes #8573
This commit is contained in:
parent
f2f05869d6
commit
c9cb4839e4
25 changed files with 119 additions and 474 deletions
|
@ -60,9 +60,7 @@ git = "https://github.com/servo/webrender_traits"
|
|||
git = "https://github.com/servo/webrender"
|
||||
|
||||
[features]
|
||||
default = ["glutin_app", "window", "webdriver"]
|
||||
window = ["glutin_app/window"]
|
||||
headless = ["glutin_app/headless"]
|
||||
default = ["glutin_app", "webdriver"]
|
||||
webdriver = ["webdriver_server"]
|
||||
energy-profiling = ["profile_traits/energy-profiling"]
|
||||
|
||||
|
|
|
@ -79,7 +79,6 @@ use profile::mem as profile_mem;
|
|||
use profile::time as profile_time;
|
||||
use profile_traits::mem;
|
||||
use profile_traits::time;
|
||||
use std::borrow::Borrow;
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::Sender;
|
||||
use util::opts;
|
||||
|
@ -103,7 +102,7 @@ pub struct Browser {
|
|||
}
|
||||
|
||||
impl Browser {
|
||||
pub fn new<Window>(window: Option<Rc<Window>>) -> Browser
|
||||
pub fn new<Window>(window: Rc<Window>) -> Browser
|
||||
where Window: WindowMethods + 'static {
|
||||
// Global configuration options, parsed from the command line.
|
||||
let opts = opts::get();
|
||||
|
@ -115,14 +114,8 @@ impl Browser {
|
|||
// messages to client may need to pump a platform-specific event loop
|
||||
// to deliver the message.
|
||||
let (compositor_proxy, compositor_receiver) =
|
||||
WindowMethods::create_compositor_channel(&window);
|
||||
let supports_clipboard = match window {
|
||||
Some(ref win_rc) => {
|
||||
let win: &Window = win_rc.borrow();
|
||||
win.supports_clipboard()
|
||||
}
|
||||
None => false
|
||||
};
|
||||
window.create_compositor_channel();
|
||||
let supports_clipboard = window.supports_clipboard();
|
||||
let time_profiler_chan = profile_time::Profiler::create(opts.time_profiler_period);
|
||||
let mem_profiler_chan = profile_mem::Profiler::create(opts.mem_profiler_period);
|
||||
let devtools_chan = opts.devtools_port.map(|port| {
|
||||
|
@ -134,9 +127,7 @@ impl Browser {
|
|||
resource_path.push("shaders");
|
||||
|
||||
// TODO(gw): Duplicates device_pixels_per_screen_px from compositor. Tidy up!
|
||||
let hidpi_factor = window.as_ref()
|
||||
.map(|window| window.hidpi_factor().get())
|
||||
.unwrap_or(1.0);
|
||||
let hidpi_factor = window.hidpi_factor().get();
|
||||
let device_pixel_ratio = match opts.device_pixels_per_px {
|
||||
Some(device_pixels_per_px) => device_pixels_per_px,
|
||||
None => match opts.output_file {
|
||||
|
|
|
@ -32,21 +32,11 @@ extern crate offscreen_gl_context;
|
|||
// The Servo engine
|
||||
extern crate servo;
|
||||
|
||||
use gleam::gl;
|
||||
use offscreen_gl_context::{GLContext, NativeGLContext};
|
||||
use servo::Browser;
|
||||
use servo::compositing::windowing::WindowEvent;
|
||||
use servo::util::opts::{self, ArgumentParsingResult};
|
||||
use std::rc::Rc;
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
fn load_gl_when_headless() {
|
||||
gl::load_with(|addr| GLContext::<NativeGLContext>::get_proc_address(addr) as *const _);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
fn load_gl_when_headless() {}
|
||||
|
||||
fn main() {
|
||||
// Parse the command line options and store them globally
|
||||
let opts_result = opts::from_cmdline_args(&*args());
|
||||
|
@ -69,14 +59,7 @@ fn main() {
|
|||
return servo::run_content_process(token)
|
||||
}
|
||||
|
||||
let window = if opts::get().headless {
|
||||
// Load gl functions even when in headless mode,
|
||||
// to avoid crashing with WebGL
|
||||
load_gl_when_headless();
|
||||
None
|
||||
} else {
|
||||
Some(app::create_window(None))
|
||||
};
|
||||
let window = app::create_window(None);
|
||||
|
||||
// Our wrapper around `Browser` that also implements some
|
||||
// callbacks required by the glutin window implementation.
|
||||
|
@ -84,45 +67,32 @@ fn main() {
|
|||
browser: Browser::new(window.clone()),
|
||||
};
|
||||
|
||||
maybe_register_glutin_resize_handler(&window, &mut browser);
|
||||
register_glutin_resize_handler(&window, &mut browser);
|
||||
|
||||
browser.browser.handle_events(vec![WindowEvent::InitializeCompositing]);
|
||||
|
||||
// Feed events from the window to the browser until the browser
|
||||
// says to stop.
|
||||
loop {
|
||||
let should_continue = match window {
|
||||
None => browser.browser.handle_events(Vec::new()),
|
||||
Some(ref window) => browser.browser.handle_events(window.wait_events()),
|
||||
};
|
||||
let should_continue = browser.browser.handle_events(window.wait_events());
|
||||
if !should_continue {
|
||||
break
|
||||
}
|
||||
};
|
||||
|
||||
maybe_unregister_glutin_resize_handler(&window);
|
||||
unregister_glutin_resize_handler(&window);
|
||||
}
|
||||
|
||||
fn maybe_register_glutin_resize_handler(window: &Option<Rc<app::window::Window>>,
|
||||
fn register_glutin_resize_handler(window: &Rc<app::window::Window>,
|
||||
browser: &mut BrowserWrapper) {
|
||||
match *window {
|
||||
None => {}
|
||||
Some(ref window) => {
|
||||
unsafe {
|
||||
window.set_nested_event_loop_listener(browser);
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
window.set_nested_event_loop_listener(browser);
|
||||
}
|
||||
}
|
||||
|
||||
fn maybe_unregister_glutin_resize_handler(window: &Option<Rc<app::window::Window>>) {
|
||||
match *window {
|
||||
None => {}
|
||||
Some(ref window) => {
|
||||
unsafe {
|
||||
window.remove_nested_event_loop_listener();
|
||||
}
|
||||
}
|
||||
fn unregister_glutin_resize_handler(window: &Rc<app::window::Window>) {
|
||||
unsafe {
|
||||
window.remove_nested_event_loop_listener();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue