Auto merge of #6812 - ecoal95:webgl-fail, r=jdm

webgl: Make context creation fallible. Fixes #6806



<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6812)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-07-29 15:29:58 -06:00
commit b90fd5931d
3 changed files with 24 additions and 16 deletions

View file

@ -949,12 +949,17 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
&mut self, &mut self,
size: &Size2D<i32>, size: &Size2D<i32>,
attributes: GLContextAttributes, attributes: GLContextAttributes,
response_sender: IpcSender<(IpcSender<CanvasMsg>, usize)>) { response_sender: IpcSender<Result<(IpcSender<CanvasMsg>, usize), String>>) {
let id = self.webgl_paint_tasks.len(); let response = match WebGLPaintTask::start(*size, attributes) {
let (out_of_process_sender, in_process_sender) = Ok((out_of_process_sender, in_process_sender)) => {
WebGLPaintTask::start(*size, attributes).unwrap(); let id = self.webgl_paint_tasks.len();
self.webgl_paint_tasks.push(in_process_sender); self.webgl_paint_tasks.push(in_process_sender);
response_sender.send((out_of_process_sender, id)).unwrap() Ok((out_of_process_sender, id))
},
Err(msg) => Err(msg.to_owned()),
};
response_sender.send(response).unwrap()
} }
fn handle_webdriver_msg(&mut self, msg: WebDriverCommandMsg) { fn handle_webdriver_msg(&mut self, msg: WebDriverCommandMsg) {

View file

@ -268,7 +268,7 @@ pub enum Msg {
/// WebGL uses the GPU and we don't want to give untrusted content access to the GPU.) /// WebGL uses the GPU and we don't want to give untrusted content access to the GPU.)
CreateWebGLPaintTask(Size2D<i32>, CreateWebGLPaintTask(Size2D<i32>,
GLContextAttributes, GLContextAttributes,
IpcSender<(IpcSender<CanvasMsg>, usize)>), IpcSender<Result<(IpcSender<CanvasMsg>, usize), String>>),
} }
#[derive(Clone, Eq, PartialEq, Deserialize, Serialize)] #[derive(Clone, Eq, PartialEq, Deserialize, Serialize)]

View file

@ -64,20 +64,23 @@ impl WebGLRenderingContext {
canvas: &HTMLCanvasElement, canvas: &HTMLCanvasElement,
size: Size2D<i32>, size: Size2D<i32>,
attrs: GLContextAttributes) attrs: GLContextAttributes)
-> Result<WebGLRenderingContext, &'static str> { -> Result<WebGLRenderingContext, String> {
let (sender, receiver) = ipc::channel().unwrap(); let (sender, receiver) = ipc::channel().unwrap();
let constellation_chan = global.constellation_chan(); let constellation_chan = global.constellation_chan();
constellation_chan.0 constellation_chan.0
.send(ConstellationMsg::CreateWebGLPaintTask(size, attrs, sender)) .send(ConstellationMsg::CreateWebGLPaintTask(size, attrs, sender))
.unwrap(); .unwrap();
let (ipc_renderer, renderer_id) = receiver.recv().unwrap(); let result = receiver.recv().unwrap();
Ok(WebGLRenderingContext {
reflector_: Reflector::new(), result.map(|(ipc_renderer, renderer_id)| {
global: GlobalField::from_rooted(&global), WebGLRenderingContext {
renderer_id: renderer_id, reflector_: Reflector::new(),
ipc_renderer: ipc_renderer, global: GlobalField::from_rooted(&global),
last_error: Cell::new(None), renderer_id: renderer_id,
canvas: JS::from_ref(canvas), ipc_renderer: ipc_renderer,
last_error: Cell::new(None),
canvas: JS::from_ref(canvas),
}
}) })
} }