Auto merge of #24859 - jdm:surfman-fallible, r=Manishearth

Don't panic if surfman initialization fails.

Since WebGL is only one component of the web platform, there's no reason that failing to initialize surfman for webgl support should take down the entire browser.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #24642 (in that the browser will now start up) and fix #24627
- [x] These changes do not require tests because tests for graphics acceleration? don't make me laugh.
This commit is contained in:
bors-servo 2019-11-26 16:43:57 -05:00 committed by GitHub
commit 42003a921b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -511,7 +511,7 @@ where
webrender_api_sender, webrender_api_sender,
webxr_main_thread.registry(), webxr_main_thread.registry(),
player_context, player_context,
Some(webgl_threads), webgl_threads,
webvr_chan, webvr_chan,
webvr_constellation_sender, webvr_constellation_sender,
glplayer_threads, glplayer_threads,
@ -1027,7 +1027,7 @@ fn create_webgl_threads<W>(
webxr_main_thread: &mut webxr::MainThreadRegistry, webxr_main_thread: &mut webxr::MainThreadRegistry,
external_image_handlers: &mut WebrenderExternalImageHandlers, external_image_handlers: &mut WebrenderExternalImageHandlers,
external_images: Arc<Mutex<WebrenderExternalImageRegistry>>, external_images: Arc<Mutex<WebrenderExternalImageRegistry>>,
) -> WebGLThreads ) -> Option<WebGLThreads>
where where
W: WindowMethods + 'static + ?Sized, W: WindowMethods + 'static + ?Sized,
{ {
@ -1037,18 +1037,33 @@ where
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
let (device, context) = unsafe { let (device, context) = unsafe {
if opts::get().headless { if opts::get().headless {
let (device, context) = SWDevice::from_current_context() let (device, context) = match SWDevice::from_current_context() {
.expect("Failed to create software graphics context!"); Ok(a) => a,
Err(e) => {
warn!("Failed to create software graphics context: {:?}", e);
return None;
},
};
(Device::Software(device), Context::Software(context)) (Device::Software(device), Context::Software(context))
} else { } else {
let (device, context) = HWDevice::from_current_context() let (device, context) = match HWDevice::from_current_context() {
.expect("Failed to create hardware graphics context!"); Ok(a) => a,
Err(e) => {
warn!("Failed to create hardware graphics context: {:?}", e);
return None;
},
};
(Device::Hardware(device), Context::Hardware(context)) (Device::Hardware(device), Context::Hardware(context))
} }
}; };
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
let (device, context) = let (device, context) = match unsafe { Device::from_current_context() } {
unsafe { Device::from_current_context().expect("Failed to create graphics context!") }; Ok(a) => a,
Err(e) => {
warn!("Failed to create graphics context: {:?}", e);
return None;
},
};
let gl_type = match window.gl().get_type() { let gl_type = match window.gl().get_type() {
gleam::gl::GlType::Gl => sparkle::gl::GlType::Gl, gleam::gl::GlType::Gl => sparkle::gl::GlType::Gl,
@ -1081,5 +1096,5 @@ where
webrender.set_output_image_handler(output_handler); webrender.set_output_image_handler(output_handler);
} }
webgl_threads Some(webgl_threads)
} }