From 0d1dfb9c43a998046ef032e67fc25f98020022bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 8 Jan 2016 21:46:07 +0000 Subject: [PATCH] webgl: Create the paint task object in the thread This avoids problems like: https://github.com/servo/servo/issues/9006#issuecomment-170007845 --- components/canvas/webgl_paint_task.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/components/canvas/webgl_paint_task.rs b/components/canvas/webgl_paint_task.rs index a765f93a109..8bef975d41a 100644 --- a/components/canvas/webgl_paint_task.rs +++ b/components/canvas/webgl_paint_task.rs @@ -23,10 +23,6 @@ pub struct WebGLPaintTask { gl_context: GLContext, } -// This allows trying to create the PaintTask -// before creating the thread -unsafe impl Send for WebGLPaintTask {} - impl WebGLPaintTask { fn new(size: Size2D, attrs: GLContextAttributes) -> Result { let context = try!(GLContext::new(size, attrs, ColorAttachmentType::Texture, None)); @@ -193,9 +189,19 @@ impl WebGLPaintTask { -> 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()); - let mut painter = try!(WebGLPaintTask::new(size, attrs)); spawn_named("WebGLTask".to_owned(), move || { + let mut painter = match WebGLPaintTask::new(size, attrs) { + Ok(task) => { + result_chan.send(Ok(())).unwrap(); + task + }, + Err(e) => { + result_chan.send(Err(e)).unwrap(); + return + } + }; painter.init(); loop { match in_process_port.recv().unwrap() { @@ -224,7 +230,7 @@ impl WebGLPaintTask { } }); - Ok((out_of_process_chan, in_process_chan)) + result_port.recv().unwrap().map(|_| (out_of_process_chan, in_process_chan)) } #[inline]