Skip to content

Commit e4857ef

Browse files
committed
No more headless compositor. Just the normal one.
Fixes #8573
1 parent 8b6bfb6 commit e4857ef

9 files changed

Lines changed: 38 additions & 229 deletions

File tree

components/compositing/compositor.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,10 @@ enum CompositeTarget {
280280
WindowAndPng,
281281

282282
/// Compose to a PNG, write it to disk, and then exit the browser (used for reftests)
283-
PngFile
283+
PngFile,
284+
285+
/// Nothing (used for script tests)
286+
None,
284287
}
285288

286289
fn initialize_png(width: usize, height: usize) -> (Vec<gl::GLuint>, Vec<gl::GLuint>) {
@@ -326,7 +329,8 @@ impl<Window: WindowMethods> IOCompositor<Window> {
326329
let hidpi_factor = window.hidpi_factor();
327330
let composite_target = match opts::get().output_file {
328331
Some(_) => CompositeTarget::PngFile,
329-
None => CompositeTarget::Window
332+
None if opts::get().headless => CompositeTarget::None,
333+
None => CompositeTarget::Window,
330334
};
331335
let native_display = window.native_display();
332336
IOCompositor {
@@ -1464,10 +1468,10 @@ impl<Window: WindowMethods> IOCompositor<Window> {
14641468
fn device_pixels_per_screen_px(&self) -> ScaleFactor<ScreenPx, DevicePixel, f32> {
14651469
match opts::get().device_pixels_per_px {
14661470
Some(device_pixels_per_px) => ScaleFactor::new(device_pixels_per_px),
1467-
None => match opts::get().output_file {
1468-
Some(_) => ScaleFactor::new(1.0),
1469-
None => self.hidpi_factor
1470-
}
1471+
None if opts::get().output_file.is_some() || opts::get().headless => {
1472+
ScaleFactor::new(1.0)
1473+
},
1474+
None => self.hidpi_factor,
14711475
}
14721476
}
14731477

@@ -1802,11 +1806,14 @@ impl<Window: WindowMethods> IOCompositor<Window> {
18021806
}
18031807
}
18041808
}
1809+
CompositeTarget::None => (),
18051810
}
18061811

18071812
let (framebuffer_ids, texture_ids) = match target {
1808-
CompositeTarget::Window => (vec!(), vec!()),
1809-
_ => initialize_png(width, height)
1813+
CompositeTarget::Window | CompositeTarget::None => (vec!(), vec!()),
1814+
CompositeTarget::WindowAndPng | CompositeTarget::PngFile => {
1815+
initialize_png(width, height)
1816+
}
18101817
};
18111818

18121819
profile(ProfilerCategory::Compositing, None, self.time_profiler_chan.clone(), || {
@@ -1854,7 +1861,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
18541861
});
18551862

18561863
let rv = match target {
1857-
CompositeTarget::Window => None,
1864+
CompositeTarget::Window | CompositeTarget::None => None,
18581865
CompositeTarget::WindowAndPng => {
18591866
let img = self.draw_img(framebuffer_ids, texture_ids, width, height);
18601867
Some(Image {

components/compositing/compositor_task.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use compositor;
88
use euclid::point::Point2D;
99
use euclid::size::Size2D;
10-
use headless;
1110
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
1211
use layers::layers::{BufferRequest, LayerBufferSet};
1312
use layers::platform::surface::{NativeDisplay, NativeSurface};
@@ -265,20 +264,12 @@ impl Debug for Msg {
265264
pub struct CompositorTask;
266265

267266
impl CompositorTask {
268-
pub fn create<Window>(window: Option<Rc<Window>>,
267+
pub fn create<Window>(window: Rc<Window>,
269268
state: InitialCompositorState)
270269
-> Box<CompositorEventListener + 'static>
271270
where Window: WindowMethods + 'static {
272-
match window {
273-
Some(window) => {
274-
box compositor::IOCompositor::create(window, state)
275-
as Box<CompositorEventListener>
276-
}
277-
None => {
278-
box headless::NullCompositor::create(state)
279-
as Box<CompositorEventListener>
280-
}
281-
}
271+
box compositor::IOCompositor::create(window, state)
272+
as Box<CompositorEventListener>
282273
}
283274
}
284275

components/compositing/headless.rs

Lines changed: 0 additions & 146 deletions
This file was deleted.

components/compositing/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ pub use constellation::Constellation;
5959

6060
mod compositor;
6161
mod compositor_layer;
62-
mod headless;
6362
mod scrolling;
6463
mod surface_map;
6564
mod timer_scheduler;

components/compositing/windowing.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use msg::constellation_msg::{Key, KeyModifiers, KeyState};
1515
use net_traits::net_error_list::NetError;
1616
use script_traits::{MouseButton, TouchEventType, TouchId};
1717
use std::fmt::{Debug, Error, Formatter};
18-
use std::rc::Rc;
1918
use url::Url;
2019
use util::cursor::Cursor;
2120
use util::geometry::ScreenPx;
@@ -143,8 +142,7 @@ pub trait WindowMethods {
143142
///
144143
/// This is part of the windowing system because its implementation often involves OS-specific
145144
/// magic to wake the up window's event loop.
146-
fn create_compositor_channel(_: &Option<Rc<Self>>)
147-
-> (Box<CompositorProxy + Send>, Box<CompositorReceiver>);
145+
fn create_compositor_channel(&self) -> (Box<CompositorProxy + Send>, Box<CompositorReceiver>);
148146

149147
/// Requests that the window system prepare a composite. Typically this will involve making
150148
/// some type of platform-specific graphics context current. Returns true if the composite may

components/servo/lib.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ use profile::mem as profile_mem;
7878
use profile::time as profile_time;
7979
use profile_traits::mem;
8080
use profile_traits::time;
81-
use std::borrow::Borrow;
8281
use std::rc::Rc;
8382
use std::sync::mpsc::Sender;
8483
use util::opts;
@@ -121,7 +120,7 @@ pub struct Browser {
121120
/// loop to pump messages between the embedding application and
122121
/// various browser components.
123122
impl Browser {
124-
pub fn new<Window>(window: Option<Rc<Window>>) -> Browser
123+
pub fn new<Window>(window: Rc<Window>) -> Browser
125124
where Window: WindowMethods + 'static {
126125
// Global configuration options, parsed from the command line.
127126
let opts = opts::get();
@@ -133,14 +132,8 @@ impl Browser {
133132
// messages to client may need to pump a platform-specific event loop
134133
// to deliver the message.
135134
let (compositor_proxy, compositor_receiver) =
136-
WindowMethods::create_compositor_channel(&window);
137-
let supports_clipboard = match window {
138-
Some(ref win_rc) => {
139-
let win: &Window = win_rc.borrow();
140-
win.supports_clipboard()
141-
}
142-
None => false
143-
};
135+
window.create_compositor_channel();
136+
let supports_clipboard = window.supports_clipboard();
144137
let time_profiler_chan = profile_time::Profiler::create(opts.time_profiler_period);
145138
let mem_profiler_chan = profile_mem::Profiler::create(opts.mem_profiler_period);
146139
let devtools_chan = opts.devtools_port.map(|port| {

components/servo/main.rs

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,12 @@ extern crate time;
3434
extern crate gleam;
3535
extern crate offscreen_gl_context;
3636

37-
use gleam::gl;
38-
use offscreen_gl_context::GLContext;
3937
use servo::Browser;
4038
use servo::compositing::windowing::WindowEvent;
4139
use servo::net_traits::hosts;
4240
use servo::util::opts::{self, ArgumentParsingResult};
4341
use std::rc::Rc;
4442

45-
#[cfg(not(target_os = "android"))]
46-
fn load_gl_when_headless() {
47-
gl::load_with(|addr| GLContext::get_proc_address(addr) as *const _);
48-
}
49-
50-
#[cfg(target_os = "android")]
51-
fn load_gl_when_headless() {}
52-
5343
fn main() {
5444
// Parse the command line options and store them globally
5545
let opts_result = opts::from_cmdline_args(&*args());
@@ -75,60 +65,40 @@ fn main() {
7565
return servo::run_content_process(token)
7666
}
7767

78-
let window = if opts::get().headless {
79-
// Load gl functions even when in headless mode,
80-
// to avoid crashing with webgl
81-
load_gl_when_headless();
82-
None
83-
} else {
84-
Some(app::create_window(None))
85-
};
68+
let window = app::create_window(None);
8669

8770
// Our wrapper around `Browser` that also implements some
8871
// callbacks required by the glutin window implementation.
8972
let mut browser = BrowserWrapper {
9073
browser: Browser::new(window.clone()),
9174
};
9275

93-
maybe_register_glutin_resize_handler(&window, &mut browser);
76+
register_glutin_resize_handler(&window, &mut browser);
9477

9578
browser.browser.handle_events(vec![WindowEvent::InitializeCompositing]);
9679

9780
// Feed events from the window to the browser until the browser
9881
// says to stop.
9982
loop {
100-
let should_continue = match window {
101-
None => browser.browser.handle_events(Vec::new()),
102-
Some(ref window) => browser.browser.handle_events(window.wait_events()),
103-
};
83+
let should_continue = browser.browser.handle_events(window.wait_events());
10484
if !should_continue {
10585
break
10686
}
10787
};
10888

109-
maybe_unregister_glutin_resize_handler(&window);
89+
unregister_glutin_resize_handler(&window);
11090
}
11191

112-
fn maybe_register_glutin_resize_handler(window: &Option<Rc<app::window::Window>>,
92+
fn register_glutin_resize_handler(window: &Rc<app::window::Window>,
11393
browser: &mut BrowserWrapper) {
114-
match *window {
115-
None => {}
116-
Some(ref window) => {
117-
unsafe {
118-
window.set_nested_event_loop_listener(browser);
119-
}
120-
}
94+
unsafe {
95+
window.set_nested_event_loop_listener(browser);
12196
}
12297
}
12398

124-
fn maybe_unregister_glutin_resize_handler(window: &Option<Rc<app::window::Window>>) {
125-
match *window {
126-
None => {}
127-
Some(ref window) => {
128-
unsafe {
129-
window.remove_nested_event_loop_listener();
130-
}
131-
}
99+
fn unregister_glutin_resize_handler(window: &Rc<app::window::Window>) {
100+
unsafe {
101+
window.remove_nested_event_loop_listener();
132102
}
133103
}
134104

0 commit comments

Comments
 (0)