From bc1850240f3590404281f53f41e0fb640527aacb Mon Sep 17 00:00:00 2001 From: Josh Leverette Date: Sun, 10 Jan 2016 13:26:15 -0600 Subject: [PATCH 1/2] Refactor WebGLPaintTask to prevent creating extra IPC channels #9228 --- components/canvas/webgl_paint_thread.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/components/canvas/webgl_paint_thread.rs b/components/canvas/webgl_paint_thread.rs index 7558bc765cc..7e353dc3c4b 100644 --- a/components/canvas/webgl_paint_thread.rs +++ b/components/canvas/webgl_paint_thread.rs @@ -187,10 +187,8 @@ impl WebGLPaintThread { /// sender for it. pub fn start(size: Size2D, attrs: GLContextAttributes) -> Result<(IpcSender, Sender), &'static str> { - let (out_of_process_chan, out_of_process_port) = ipc::channel::().unwrap(); let (in_process_chan, in_process_port) = channel(); let (result_chan, result_port) = channel(); - ROUTER.route_ipc_receiver_to_mpsc_sender(out_of_process_port, in_process_chan.clone()); spawn_named("WebGLThread".to_owned(), move || { let mut painter = match WebGLPaintThread::new(size, attrs) { Ok(thread) => { @@ -230,7 +228,15 @@ impl WebGLPaintThread { } }); - result_port.recv().unwrap().map(|_| (out_of_process_chan, in_process_chan)) + match result_port.recv() { + Ok(_) => { + let (out_of_process_chan, out_of_process_port) = ipc::channel::().unwrap(); + ROUTER.route_ipc_receiver_to_mpsc_sender(out_of_process_port, in_process_chan.clone()); + + Ok((out_of_process_chan, in_process_chan)) + }, + Err(_) => Err("Could not create WebGLPaintThread.") + } } #[inline] From 1bde88395cd69ef68040982f3ee61204e50914dd Mon Sep 17 00:00:00 2001 From: Josh Leverette Date: Mon, 11 Jan 2016 23:35:38 -0600 Subject: [PATCH 2/2] modified to use `map` instead of `match`. --- components/canvas/webgl_paint_thread.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/components/canvas/webgl_paint_thread.rs b/components/canvas/webgl_paint_thread.rs index 7e353dc3c4b..084ce49d491 100644 --- a/components/canvas/webgl_paint_thread.rs +++ b/components/canvas/webgl_paint_thread.rs @@ -228,15 +228,11 @@ impl WebGLPaintThread { } }); - match result_port.recv() { - Ok(_) => { - let (out_of_process_chan, out_of_process_port) = ipc::channel::().unwrap(); - ROUTER.route_ipc_receiver_to_mpsc_sender(out_of_process_port, in_process_chan.clone()); - - Ok((out_of_process_chan, in_process_chan)) - }, - Err(_) => Err("Could not create WebGLPaintThread.") - } + result_port.recv().unwrap().map(|_| { + let (out_of_process_chan, out_of_process_port) = ipc::channel::().unwrap(); + ROUTER.route_ipc_receiver_to_mpsc_sender(out_of_process_port, in_process_chan.clone()); + (out_of_process_chan, in_process_chan) + }) } #[inline]