Auto merge of #11313 - nox:channel-loop, r=mbrubeck

Hoist channel creation out of loop in handle_is_ready_to_save_image

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11313)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-05-21 08:32:30 -07:00
commit eeea481a12

View file

@ -1735,6 +1735,9 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF>
return ReadyToSave::PendingFrames; return ReadyToSave::PendingFrames;
} }
let (state_sender, state_receiver) = ipc::channel().expect("Failed to create IPC channel!");
let (epoch_sender, epoch_receiver) = ipc::channel().expect("Failed to create IPC channel!");
// Step through the current frame tree, checking that the script // Step through the current frame tree, checking that the script
// thread is idle, and that the current epoch of the layout thread // thread is idle, and that the current epoch of the layout thread
// matches what the compositor has painted. If all these conditions // matches what the compositor has painted. If all these conditions
@ -1757,12 +1760,11 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF>
// before we check whether the document is ready; otherwise, // before we check whether the document is ready; otherwise,
// there's a race condition where a webfont has finished loading, // there's a race condition where a webfont has finished loading,
// but hasn't yet notified the document. // but hasn't yet notified the document.
let (sender, receiver) = ipc::channel().expect("Failed to create IPC channel!"); let msg = LayoutControlMsg::GetWebFontLoadState(state_sender.clone());
let msg = LayoutControlMsg::GetWebFontLoadState(sender);
if let Err(e) = pipeline.layout_chan.0.send(msg) { if let Err(e) = pipeline.layout_chan.0.send(msg) {
warn!("Get web font failed ({})", e); warn!("Get web font failed ({})", e);
} }
if receiver.recv().unwrap_or(true) { if state_receiver.recv().unwrap_or(true) {
return ReadyToSave::WebFontNotLoaded; return ReadyToSave::WebFontNotLoaded;
} }
@ -1794,12 +1796,11 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF>
// epoch matches what the compositor has drawn. If they match // epoch matches what the compositor has drawn. If they match
// (and script is idle) then this pipeline won't change again // (and script is idle) then this pipeline won't change again
// and can be considered stable. // and can be considered stable.
let (sender, receiver) = ipc::channel().expect("Failed to create IPC channel!");
let LayoutControlChan(ref layout_chan) = pipeline.layout_chan; let LayoutControlChan(ref layout_chan) = pipeline.layout_chan;
if let Err(e) = layout_chan.send(LayoutControlMsg::GetCurrentEpoch(sender)) { if let Err(e) = layout_chan.send(LayoutControlMsg::GetCurrentEpoch(epoch_sender.clone())) {
warn!("Failed to send GetCurrentEpoch ({}).", e); warn!("Failed to send GetCurrentEpoch ({}).", e);
} }
match receiver.recv() { match epoch_receiver.recv() {
Err(e) => warn!("Failed to receive current epoch ({}).", e), Err(e) => warn!("Failed to receive current epoch ({}).", e),
Ok(layout_thread_epoch) => if layout_thread_epoch != *compositor_epoch { Ok(layout_thread_epoch) => if layout_thread_epoch != *compositor_epoch {
return ReadyToSave::EpochMismatch; return ReadyToSave::EpochMismatch;