servo: Merge #10267 - Simplify channel usage in canvas paint threads (from Ms2ger:canvas-channels); r=jdm
authorMs2ger <Ms2ger@gmail.com>
Tue, 29 Mar 2016 19:38:24 +0500
changeset 338351 a4e5e327cf2f8b014fc5ee5d7837019802369ee0
parent 338350 c8ad31cc5d3bb28ddad00585402824bffd10b890
child 338352 a84ca5d8391644e7154ba4a1b0ffc8fa7e2f7d9b
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
servo: Merge #10267 - Simplify channel usage in canvas paint threads (from Ms2ger:canvas-channels); r=jdm Source-Repo: https://github.com/servo/servo Source-Revision: df808bed20a097719992f3c355bd164c4abc8913
servo/components/canvas/canvas_paint_thread.rs
servo/components/canvas/webgl_paint_thread.rs
--- a/servo/components/canvas/canvas_paint_thread.rs
+++ b/servo/components/canvas/canvas_paint_thread.rs
@@ -9,22 +9,20 @@ use azure::azure_hl::{ColorPattern, Draw
 use canvas_traits::*;
 use euclid::matrix2d::Matrix2D;
 use euclid::point::Point2D;
 use euclid::rect::Rect;
 use euclid::size::Size2D;
 use gfx_traits::color;
 use ipc_channel::ipc::IpcSharedMemory;
 use ipc_channel::ipc::{self, IpcSender};
-use ipc_channel::router::ROUTER;
 use num::ToPrimitive;
 use premultiplytable::PREMULTIPLY_TABLE;
 use std::borrow::ToOwned;
 use std::mem;
-use std::sync::mpsc::channel;
 use util::opts;
 use util::thread::spawn_named;
 use util::vec::byte_swap;
 use webrender_traits;
 
 impl<'a> CanvasPaintThread<'a> {
     /// It reads image data from the canvas
     /// canvas_size: The size of the canvas we're reading from
@@ -122,23 +120,21 @@ impl<'a> CanvasPaintThread<'a> {
 
     /// Creates a new `CanvasPaintThread` and returns the out-of-process sender and the in-process
     /// sender for it.
     pub fn start(size: Size2D<i32>,
                  webrender_api_sender: Option<webrender_traits::RenderApiSender>)
                  -> IpcSender<CanvasMsg> {
         // TODO(pcwalton): Ask the pipeline to create this for us instead of spawning it directly.
         // This will be needed for multiprocess Servo.
-        let (out_of_process_chan, out_of_process_port) = ipc::channel::<CanvasMsg>().unwrap();
-        let (in_process_chan, in_process_port) = channel();
-        ROUTER.route_ipc_receiver_to_mpsc_sender(out_of_process_port, in_process_chan);
+        let (sender, receiver) = ipc::channel::<CanvasMsg>().unwrap();
         spawn_named("CanvasThread".to_owned(), move || {
             let mut painter = CanvasPaintThread::new(size, webrender_api_sender);
             loop {
-                let msg = in_process_port.recv();
+                let msg = receiver.recv();
                 match msg.unwrap() {
                     CanvasMsg::Canvas2d(message) => {
                         match message {
                             Canvas2dMsg::FillRect(ref rect) => painter.fill_rect(rect),
                             Canvas2dMsg::StrokeRect(ref rect) => painter.stroke_rect(rect),
                             Canvas2dMsg::ClearRect(ref rect) => painter.clear_rect(rect),
                             Canvas2dMsg::BeginPath => painter.begin_path(),
                             Canvas2dMsg::ClosePath => painter.close_path(),
@@ -204,17 +200,17 @@ impl<'a> CanvasPaintThread<'a> {
                             }
                         }
                     }
                     CanvasMsg::WebGL(_) => panic!("Wrong message sent to Canvas2D thread"),
                 }
             }
         });
 
-        out_of_process_chan
+        sender
     }
 
     fn save_context_state(&mut self) {
         self.saved_states.push(self.state.clone());
     }
 
     fn restore_context_state(&mut self) {
         if let Some(state) = self.saved_states.pop() {
--- a/servo/components/canvas/webgl_paint_thread.rs
+++ b/servo/components/canvas/webgl_paint_thread.rs
@@ -1,17 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 use canvas_traits::{CanvasCommonMsg, CanvasMsg, CanvasPixelData, CanvasData, CanvasWebGLMsg, FromLayoutMsg};
 use euclid::size::Size2D;
 use gleam::gl;
 use ipc_channel::ipc::{self, IpcSender, IpcSharedMemory};
-use ipc_channel::router::ROUTER;
 use offscreen_gl_context::{ColorAttachmentType, GLContext, GLContextAttributes, NativeGLContext};
 use std::borrow::ToOwned;
 use std::sync::mpsc::channel;
 use util::thread::spawn_named;
 use util::vec::byte_swap;
 use webrender_traits;
 
 enum WebGLPaintTaskData {
@@ -56,32 +55,32 @@ impl WebGLPaintThread {
     }
 
     /// Creates a new `WebGLPaintThread` and returns the out-of-process sender and the in-process
     /// sender for it.
     pub fn start(size: Size2D<i32>,
                  attrs: GLContextAttributes,
                  webrender_api_sender: Option<webrender_traits::RenderApiSender>)
                  -> Result<IpcSender<CanvasMsg>, String> {
-        let (in_process_chan, in_process_port) = channel();
+        let (sender, receiver) = ipc::channel::<CanvasMsg>().unwrap();
         let (result_chan, result_port) = channel();
         spawn_named("WebGLThread".to_owned(), move || {
             let mut painter = match WebGLPaintThread::new(size, attrs, webrender_api_sender) {
                 Ok(thread) => {
                     result_chan.send(Ok(())).unwrap();
                     thread
                 },
                 Err(e) => {
                     result_chan.send(Err(e)).unwrap();
                     return
                 }
             };
             painter.init();
             loop {
-                match in_process_port.recv().unwrap() {
+                match receiver.recv().unwrap() {
                     CanvasMsg::WebGL(message) => painter.handle_webgl_message(message),
                     CanvasMsg::Common(message) => {
                         match message {
                             CanvasCommonMsg::Close => break,
                             // TODO(emilio): handle error nicely
                             CanvasCommonMsg::Recreate(size) => painter.recreate(size).unwrap(),
                         }
                     },
@@ -91,21 +90,18 @@ impl WebGLPaintThread {
                                 painter.send_data(chan),
                         }
                     }
                     CanvasMsg::Canvas2d(_) => panic!("Wrong message sent to WebGLThread"),
                 }
             }
         });
 
-        result_port.recv().unwrap().map(|_| {
-             let (out_of_process_chan, out_of_process_port) = ipc::channel::<CanvasMsg>().unwrap();
-             ROUTER.route_ipc_receiver_to_mpsc_sender(out_of_process_port, in_process_chan);
-             out_of_process_chan
-        })
+        try!(result_port.recv().unwrap());
+        Ok(sender)
     }
 
     fn send_data(&mut self, chan: IpcSender<CanvasData>) {
         match self.data {
             WebGLPaintTaskData::Servo(_) => {
                 let width = self.size.width as usize;
                 let height = self.size.height as usize;