Skip to content

Commit bf3248f

Browse files
author
bors-servo
committed
Auto merge of #8641 - notriddle:no_headless, r=glennw
No more headless compositor. Just the normal one. Fixes #8573 <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8641) <!-- Reviewable:end -->
2 parents 7716230 + 2d6163a commit bf3248f

File tree

25 files changed

+119
-474
lines changed

25 files changed

+119
-474
lines changed

components/compositing/compositor.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
525525

526526
(Msg::InitializeLayersForPipeline(pipeline_id, epoch, properties),
527527
ShutdownState::NotShuttingDown) => {
528+
debug!("initializing layers for pipeline: {:?}", pipeline_id);
528529
self.pipeline_details(pipeline_id).current_epoch = epoch;
529530

530531
self.collect_old_layers(pipeline_id, &properties);
@@ -542,7 +543,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
542543

543544
(Msg::GetNativeDisplay(chan),
544545
ShutdownState::NotShuttingDown) => {
545-
chan.send(Some(self.native_display.clone())).unwrap();
546+
chan.send(self.native_display.clone()).unwrap();
546547
}
547548

548549
(Msg::AssignPaintedBuffers(pipeline_id, epoch, replies, frame_tree_id),
@@ -641,7 +642,8 @@ impl<Window: WindowMethods> IOCompositor<Window> {
641642
reply.send(img).unwrap();
642643
}
643644

644-
(Msg::PaintThreadExited(pipeline_id), ShutdownState::NotShuttingDown) => {
645+
(Msg::PaintThreadExited(pipeline_id), _) => {
646+
debug!("compositor learned about paint thread exiting: {:?}", pipeline_id);
645647
self.remove_pipeline_root_layer(pipeline_id);
646648
}
647649

@@ -690,8 +692,11 @@ impl<Window: WindowMethods> IOCompositor<Window> {
690692
reports_chan.send(reports);
691693
}
692694

693-
(Msg::PipelineExited(pipeline_id), _) => {
695+
(Msg::PipelineExited(pipeline_id, sender), _) => {
696+
debug!("Compositor got pipeline exited: {:?}", pipeline_id);
694697
self.pending_subpages.remove(&pipeline_id);
698+
self.remove_pipeline_root_layer(pipeline_id);
699+
sender.send(()).unwrap();
695700
}
696701

697702
// When we are shutting_down, we need to avoid performing operations

components/compositing/compositor_thread.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use compositor::{self, CompositingReason};
99
use euclid::point::Point2D;
1010
use euclid::size::Size2D;
1111
use gfx_traits::{Epoch, FrameTreeId, LayerId, LayerProperties, PaintListener};
12-
use headless;
1312
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
1413
use layers::layers::{BufferRequest, LayerBufferSet};
1514
use layers::platform::surface::{NativeDisplay, NativeSurface};
@@ -98,6 +97,8 @@ pub fn run_script_listener_thread(compositor_proxy: Box<CompositorProxy + 'stati
9897
ScriptToCompositorMsg::TouchEventProcessed(result) => {
9998
compositor_proxy.send(Msg::TouchEventProcessed(result))
10099
}
100+
101+
ScriptToCompositorMsg::Exited => break,
101102
}
102103
}
103104
}
@@ -123,7 +124,7 @@ impl PaintListener for Box<CompositorProxy + 'static + Send> {
123124
// just return None in this case, since the paint thread
124125
// will exit shortly and never actually be requested
125126
// to paint buffers by the compositor.
126-
port.recv().unwrap_or(None)
127+
port.recv().ok()
127128
}
128129

129130
fn assign_painted_buffers(&mut self,
@@ -174,9 +175,7 @@ pub enum Msg {
174175
/// Requests the compositor's graphics metadata. Graphics metadata is what the painter needs
175176
/// to create surfaces that the compositor can see. On Linux this is the X display; on Mac this
176177
/// is the pixel format.
177-
///
178-
/// The headless compositor returns `None`.
179-
GetNativeDisplay(Sender<Option<NativeDisplay>>),
178+
GetNativeDisplay(Sender<NativeDisplay>),
180179

181180
/// Tells the compositor to create or update the layers for a pipeline if necessary
182181
/// (i.e. if no layer with that ID exists).
@@ -233,7 +232,11 @@ pub enum Msg {
233232
/// Resize the window to size
234233
ResizeTo(Size2D<u32>),
235234
/// A pipeline was shut down.
236-
PipelineExited(PipelineId),
235+
// This message acts as a synchronization point between the constellation,
236+
// when it shuts down a pipeline, to the compositor; when the compositor
237+
// sends a reply on the IpcSender, the constellation knows it's safe to
238+
// tear down the other threads associated with this pipeline.
239+
PipelineExited(PipelineId, IpcSender<()>),
237240
}
238241

239242
impl Debug for Msg {
@@ -276,20 +279,12 @@ impl Debug for Msg {
276279
pub struct CompositorThread;
277280

278281
impl CompositorThread {
279-
pub fn create<Window>(window: Option<Rc<Window>>,
282+
pub fn create<Window>(window: Rc<Window>,
280283
state: InitialCompositorState)
281284
-> Box<CompositorEventListener + 'static>
282285
where Window: WindowMethods + 'static {
283-
match window {
284-
Some(window) => {
285-
box compositor::IOCompositor::create(window, state)
286-
as Box<CompositorEventListener>
287-
}
288-
None => {
289-
box headless::NullCompositor::create(state)
290-
as Box<CompositorEventListener>
291-
}
292-
}
286+
box compositor::IOCompositor::create(window, state)
287+
as Box<CompositorEventListener>
293288
}
294289
}
295290

components/compositing/constellation.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,13 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF>
633633
}
634634
// Update pipeline url after redirections
635635
Request::Script(FromScriptMsg::SetFinalUrl(pipeline_id, final_url)) => {
636-
debug!("constellation got set final url message");
637-
self.mut_pipeline(pipeline_id).url = final_url;
636+
// The script may have finished loading after we already started shutting down.
637+
if let Some(ref mut pipeline) = self.pipelines.get_mut(&pipeline_id) {
638+
debug!("constellation got set final url message");
639+
pipeline.url = final_url;
640+
} else {
641+
debug!("constellation got set final url message for dead pipeline");
642+
}
638643
}
639644
Request::Script(FromScriptMsg::MozBrowserEvent(pipeline_id,
640645
subpage_id,
@@ -678,9 +683,12 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF>
678683
}
679684
}
680685
}
681-
Request::Script(FromScriptMsg::RemoveIFrame(pipeline_id)) => {
686+
Request::Script(FromScriptMsg::RemoveIFrame(pipeline_id, sender)) => {
682687
debug!("constellation got remove iframe message");
683688
self.handle_remove_iframe_msg(pipeline_id);
689+
if let Some(sender) = sender {
690+
sender.send(()).unwrap();
691+
}
684692
}
685693
Request::Script(FromScriptMsg::NewFavicon(url)) => {
686694
debug!("constellation got new favicon message");

components/compositing/headless.rs

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

components/compositing/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ mod compositor_layer;
6767
pub mod compositor_thread;
6868
pub mod constellation;
6969
mod delayed_composition;
70-
mod headless;
7170
pub mod pipeline;
7271
#[cfg(not(target_os = "windows"))]
7372
pub mod sandboxing;

components/compositing/pipeline.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ use script_traits::{LayoutControlMsg, LayoutMsg, NewLayoutInfo, ScriptMsg};
2828
use script_traits::{ScriptToCompositorMsg, ScriptThreadFactory, TimerEventRequest};
2929
use std::mem;
3030
use std::sync::mpsc::{Receiver, Sender, channel};
31-
use std::thread;
3231
use url::Url;
3332
use util;
3433
use util::geometry::{PagePx, ViewportPx};
3534
use util::ipc::OptionalIpcSender;
3635
use util::opts::{self, Opts};
3736
use util::prefs;
37+
use util::thread;
3838
use webrender_traits;
3939

4040
/// A uniquely-identifiable pipeline of script thread, layout thread, and paint thread.
@@ -290,6 +290,13 @@ impl Pipeline {
290290
pub fn exit(&self) {
291291
debug!("pipeline {:?} exiting", self.id);
292292

293+
// The compositor wants to know when pipelines shut down too.
294+
// It may still have messages to process from these other threads
295+
// before they can be safely shut down.
296+
let (sender, receiver) = ipc::channel().unwrap();
297+
self.compositor_proxy.send(CompositorMsg::PipelineExited(self.id, sender));
298+
receiver.recv().unwrap();
299+
293300
// Script thread handles shutting down layout, and layout handles shutting down the painter.
294301
// For now, if the script thread has failed, we give up on clean shutdown.
295302
if self.script_chan
@@ -300,9 +307,6 @@ impl Pipeline {
300307
let _ = self.paint_shutdown_port.recv();
301308
let _ = self.layout_shutdown_port.recv();
302309
}
303-
304-
// The compositor wants to know when pipelines shut down too.
305-
self.compositor_proxy.send(CompositorMsg::PipelineExited(self.id))
306310
}
307311

308312
pub fn freeze(&self) {
@@ -472,7 +476,7 @@ impl PrivilegedPipelineContent {
472476
let compositor_proxy_for_script_listener_thread =
473477
self.compositor_proxy.clone_compositor_proxy();
474478
let script_to_compositor_port = self.script_to_compositor_port;
475-
thread::spawn(move || {
479+
thread::spawn_named("CompositorScriptListener".to_owned(), move || {
476480
compositor_thread::run_script_listener_thread(
477481
compositor_proxy_for_script_listener_thread,
478482
script_to_compositor_port)

components/compositing/windowing.rs

Lines changed: 1 addition & 2 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 style_traits::cursor::Cursor;
2019
use url::Url;
2120
use util::geometry::ScreenPx;
@@ -142,7 +141,7 @@ pub trait WindowMethods {
142141
///
143142
/// This is part of the windowing system because its implementation often involves OS-specific
144143
/// magic to wake the up window's event loop.
145-
fn create_compositor_channel(_: &Option<Rc<Self>>)
144+
fn create_compositor_channel(&self)
146145
-> (Box<CompositorProxy + Send>, Box<CompositorReceiver>);
147146

148147
/// Requests that the window system prepare a composite. Typically this will involve making

components/gfx/paint_thread.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ pub enum Msg {
344344
pub enum LayoutToPaintMsg {
345345
PaintInit(Epoch, Arc<DisplayList>),
346346
CanvasLayer(LayerId, IpcSender<CanvasMsg>),
347-
Exit(IpcSender<()>),
347+
Exit,
348348
}
349349

350350
pub enum ChromeToPaintMsg {
@@ -516,21 +516,20 @@ impl<C> PaintThread<C> where C: PaintListener + Send + 'static {
516516
// FIXME(njn): should eventually measure the paint thread.
517517
channel.send(Vec::new())
518518
}
519-
Msg::FromLayout(LayoutToPaintMsg::Exit(ref response_channel)) => {
519+
Msg::FromLayout(LayoutToPaintMsg::Exit) => {
520520
// Ask the compositor to remove any layers it is holding for this paint thread.
521521
// FIXME(mrobinson): This can probably move back to the constellation now.
522+
debug!("PaintThread: Exiting.");
522523
self.compositor.notify_paint_thread_exiting(self.id);
523524

524-
debug!("PaintThread: Exiting.");
525-
let _ = response_channel.send(());
526525
break;
527526
}
528527
Msg::FromChrome(ChromeToPaintMsg::Exit) => {
529528
// Ask the compositor to remove any layers it is holding for this paint thread.
530529
// FIXME(mrobinson): This can probably move back to the constellation now.
530+
debug!("PaintThread: Exiting.");
531531
self.compositor.notify_paint_thread_exiting(self.id);
532532

533-
debug!("PaintThread: Exiting.");
534533
break;
535534
}
536535
}

0 commit comments

Comments
 (0)