servo: Merge #19599 - Revert canvas IPC changes (from jdm:revertcanvas); r=asajeffrey
authorJosh Matthews <josh@joshmatthews.net>
Mon, 18 Dec 2017 10:19:30 -0600
changeset 448460 6b1f9a0e13469a001e6ca2feda6a05153a4d9414
parent 448459 017630a4b3712b5763b5bf2a66af1ede585a8ddc
child 448461 ca4c587c313b6bcba5e11011bcedc632b29b2d31
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasajeffrey
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #19599 - Revert canvas IPC changes (from jdm:revertcanvas); r=asajeffrey https://github.com/servo/servo/pull/19547 is responsible for the surge of new intermittent timeouts in canvas-related tests. There's nothing wrong with the change, so I suspect an underlying problem in ipc-channel instead. Fixes #19592. #19593. Fixes #19594. Fixes #19597. Source-Repo: https://github.com/servo/servo Source-Revision: 37fe9f29573e669ea9dd86ed6d9de0e43b3f746d
servo/components/canvas/canvas_paint_thread.rs
servo/components/constellation/constellation.rs
servo/components/script/dom/canvasrenderingcontext2d.rs
servo/components/script_traits/script_msg.rs
--- a/servo/components/canvas/canvas_paint_thread.rs
+++ b/servo/components/canvas/canvas_paint_thread.rs
@@ -6,17 +6,17 @@ use azure::azure::AzFloat;
 use azure::azure_hl::{AntialiasMode, CapStyle, CompositionOp, JoinStyle};
 use azure::azure_hl::{BackendType, DrawOptions, DrawTarget, Pattern, StrokeOptions, SurfaceFormat};
 use azure::azure_hl::{Color, ColorPattern, DrawSurfaceOptions, Filter, PathBuilder};
 use azure::azure_hl::{ExtendMode, GradientStop, LinearGradientPattern, RadialGradientPattern};
 use azure::azure_hl::SurfacePattern;
 use canvas_traits::canvas::*;
 use cssparser::RGBA;
 use euclid::{Transform2D, Point2D, Vector2D, Rect, Size2D};
-use ipc_channel::ipc::{IpcSender, IpcReceiver};
+use ipc_channel::ipc::{self, IpcSender, IpcReceiver};
 use num_traits::ToPrimitive;
 use std::borrow::ToOwned;
 use std::mem;
 use std::sync::Arc;
 use std::thread;
 use webrender_api;
 
 impl<'a> CanvasPaintThread<'a> {
@@ -113,18 +113,19 @@ impl<'a> CanvasPaintThread<'a> {
             very_old_image_key: None,
         }
     }
 
     /// Creates a new `CanvasPaintThread` and returns an `IpcSender` to
     /// communicate with it.
     pub fn start(size: Size2D<i32>,
                  webrender_api_sender: webrender_api::RenderApiSender,
-                 antialias: bool,
-                 receiver: IpcReceiver<CanvasMsg>) {
+                 antialias: bool)
+                 -> IpcSender<CanvasMsg> {
+        let (sender, receiver) = ipc::channel::<CanvasMsg>().unwrap();
         let antialias = if antialias {
             AntialiasMode::Default
         } else {
             AntialiasMode::None
         };
         thread::Builder::new().name("CanvasThread".to_owned()).spawn(move || {
             let mut painter = CanvasPaintThread::new(size, webrender_api_sender, antialias);
             loop {
@@ -210,16 +211,18 @@ impl<'a> CanvasPaintThread<'a> {
                             FromLayoutMsg::SendData(chan) => {
                                 painter.send_data(chan)
                             }
                         }
                     }
                 }
             }
         }).expect("Thread spawning failed");
+
+        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/constellation/constellation.rs
+++ b/servo/components/constellation/constellation.rs
@@ -1230,19 +1230,19 @@ impl<Message, LTF, STF> Constellation<Me
                 }
             }
             FromScriptMsg::HeadParsed => {
                 debug!("constellation got head parsed message");
                 if source_is_top_level_pipeline {
                     self.embedder_proxy.send(EmbedderMsg::HeadParsed(source_top_ctx_id));
                 }
             }
-            FromScriptMsg::CreateCanvasPaintThread(size, receiver) => {
+            FromScriptMsg::CreateCanvasPaintThread(size, sender) => {
                 debug!("constellation got create-canvas-paint-thread message");
-                self.handle_create_canvas_paint_thread_msg(&size, receiver)
+                self.handle_create_canvas_paint_thread_msg(&size, sender)
             }
             FromScriptMsg::NodeStatus(message) => {
                 debug!("constellation got NodeStatus message");
                 self.embedder_proxy.send(EmbedderMsg::Status(source_top_ctx_id, message));
             }
             FromScriptMsg::SetDocumentState(state) => {
                 debug!("constellation got SetDocumentState message");
                 self.document_states.insert(source_pipeline_id, state);
@@ -2259,22 +2259,23 @@ impl<Message, LTF, STF> Constellation<Me
                 self.handle_send_error(parent_pipeline_id, e);
             }
         }
     }
 
     fn handle_create_canvas_paint_thread_msg(
             &mut self,
             size: &Size2D<i32>,
-            receiver: IpcReceiver<CanvasMsg>) {
+            response_sender: IpcSender<IpcSender<CanvasMsg>>) {
         let webrender_api = self.webrender_api_sender.clone();
-        CanvasPaintThread::start(*size,
-                                 webrender_api,
-                                 opts::get().enable_canvas_antialiasing,
-                                 receiver);
+        let sender = CanvasPaintThread::start(*size, webrender_api,
+                                              opts::get().enable_canvas_antialiasing);
+        if let Err(e) = response_sender.send(sender) {
+            warn!("Create canvas paint thread response failed ({})", e);
+        }
     }
 
     fn handle_webdriver_msg(&mut self, msg: WebDriverCommandMsg) {
         // Find the script channel for the given parent pipeline,
         // and pass the event to that script thread.
         match msg {
             WebDriverCommandMsg::GetWindowSize(_, reply) => {
                let _ = reply.send(self.window_size);
--- a/servo/components/script/dom/canvasrenderingcontext2d.rs
+++ b/servo/components/script/dom/canvasrenderingcontext2d.rs
@@ -124,20 +124,21 @@ impl CanvasContextState {
 impl CanvasRenderingContext2D {
     pub fn new_inherited(global: &GlobalScope,
                          canvas: Option<&HTMLCanvasElement>,
                          image_cache: Arc<ImageCache>,
                          base_url: ServoUrl,
                          size: Size2D<i32>)
                          -> CanvasRenderingContext2D {
         debug!("Creating new canvas rendering context.");
-        let (ipc_renderer, receiver) = ipc::channel::<CanvasMsg>().unwrap();
+        let (sender, receiver) = ipc::channel().unwrap();
         let script_to_constellation_chan = global.script_to_constellation_chan();
         debug!("Asking constellation to create new canvas thread.");
-        script_to_constellation_chan.send(ScriptMsg::CreateCanvasPaintThread(size, receiver)).unwrap();
+        script_to_constellation_chan.send(ScriptMsg::CreateCanvasPaintThread(size, sender)).unwrap();
+        let ipc_renderer = receiver.recv().unwrap();
         debug!("Done.");
         CanvasRenderingContext2D {
             reflector_: Reflector::new(),
             ipc_renderer: ipc_renderer,
             canvas: canvas.map(Dom::from_ref),
             image_cache: image_cache,
             missing_image_urls: DomRefCell::new(Vec::new()),
             base_url: base_url,
--- a/servo/components/script_traits/script_msg.rs
+++ b/servo/components/script_traits/script_msg.rs
@@ -74,17 +74,17 @@ pub enum ScriptMsg {
     InitiateNavigateRequest(RequestInit, /* cancellation_chan */ IpcReceiver<()>),
     /// Broadcast a storage event to every same-origin pipeline.
     /// The strings are key, old value and new value.
     BroadcastStorageEvent(StorageType, ServoUrl, Option<String>, Option<String>, Option<String>),
     /// Indicates whether this pipeline is currently running animations.
     ChangeRunningAnimationsState(AnimationState),
     /// Requests that a new 2D canvas thread be created. (This is done in the constellation because
     /// 2D canvases may use the GPU and we don't want to give untrusted content access to the GPU.)
-    CreateCanvasPaintThread(Size2D<i32>, IpcReceiver<CanvasMsg>),
+    CreateCanvasPaintThread(Size2D<i32>, IpcSender<IpcSender<CanvasMsg>>),
     /// Notifies the constellation that this frame has received focus.
     Focus,
     /// Forward an event that was sent to the parent window.
     ForwardEvent(PipelineId, CompositorEvent),
     /// Requests that the constellation retrieve the current contents of the clipboard
     GetClipboardContents(IpcSender<String>),
     /// Get the browsing context id for a given pipeline.
     GetBrowsingContextId(PipelineId, IpcSender<Option<BrowsingContextId>>),