auto merge of #2489 : zwarich/servo/render-chan-newtype, r=jdm

Also, derive Clone rather than implementing it manually.
This commit is contained in:
bors-servo 2014-05-27 08:55:25 -04:00
commit 606cadbe4c
3 changed files with 10 additions and 21 deletions

View file

@ -73,34 +73,23 @@ pub fn BufferRequest(screen_rect: Rect<uint>, page_rect: Rect<f32>) -> BufferReq
}
}
// FIXME(#2005, pcwalton): This should be a newtype struct.
pub struct RenderChan {
pub chan: Sender<Msg>,
}
impl Clone for RenderChan {
fn clone(&self) -> RenderChan {
RenderChan {
chan: self.chan.clone(),
}
}
}
#[deriving(Clone)]
pub struct RenderChan(Sender<Msg>);
impl RenderChan {
pub fn new() -> (Receiver<Msg>, RenderChan) {
let (chan, port) = channel();
let render_chan = RenderChan {
chan: chan,
};
(port, render_chan)
(port, RenderChan(chan))
}
pub fn send(&self, msg: Msg) {
assert!(self.send_opt(msg).is_ok(), "RenderChan.send: render port closed")
let &RenderChan(ref chan) = self;
assert!(chan.send_opt(msg).is_ok(), "RenderChan.send: render port closed")
}
pub fn send_opt(&self, msg: Msg) -> Result<(), Msg> {
self.chan.send_opt(msg)
let &RenderChan(ref chan) = self;
chan.send_opt(msg)
}
}

View file

@ -397,7 +397,7 @@ impl Constellation {
fn force_pipeline_exit(old_pipeline: &Rc<Pipeline>) {
let ScriptChan(ref old_script) = old_pipeline.script_chan;
old_script.send_opt(ExitPipelineMsg(old_pipeline.id));
old_pipeline.render_chan.chan.send_opt(render_task::ExitMsg(None));
old_pipeline.render_chan.send_opt(render_task::ExitMsg(None));
let LayoutChan(ref old_layout) = old_pipeline.layout_chan;
old_layout.send_opt(layout_interface::ExitNowMsg);
}

View file

@ -197,12 +197,12 @@ impl Pipeline {
}
pub fn grant_paint_permission(&self) {
self.render_chan.chan.send_opt(PaintPermissionGranted);
self.render_chan.send_opt(PaintPermissionGranted);
}
pub fn revoke_paint_permission(&self) {
debug!("pipeline revoking render channel paint permission");
self.render_chan.chan.send_opt(PaintPermissionRevoked);
self.render_chan.send_opt(PaintPermissionRevoked);
}
pub fn exit(&self) {