From 3e57c112606f6b5a15ed12d12d105c15cd86f087 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 5 May 2020 09:40:03 -0400 Subject: [PATCH] Refactor create_surface a bit --- wgpu-core/src/instance.rs | 73 +++++++++++---------------------------- 1 file changed, 20 insertions(+), 53 deletions(-) diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index d4c25c252b..a9223ec0f4 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -223,66 +223,33 @@ impl Global { handle: &impl raw_window_handle::HasRawWindowHandle, id_in: Input, ) -> SurfaceId { - unsafe { - #[cfg(target_os = "ios")] - let surface = Surface { - #[cfg(feature = "gfx-backend-vulkan")] - vulkan: None, + let surface = unsafe { + Surface { + #[cfg(any( + windows, + all(unix, not(any(target_os = "ios", target_os = "macos"))), + feature = "gfx-backend-vulkan", + ))] + vulkan: self + .instance + .vulkan + .as_ref() + .and_then(|inst| inst.create_surface(handle).ok()), + #[cfg(any(target_os = "ios", target_os = "macos"))] metal: self.instance.metal.create_surface(handle).unwrap(), - }; - #[cfg(target_os = "macos")] - let surface = Surface { - #[cfg(feature = "gfx-backend-vulkan")] - vulkan: self - .instance - .vulkan - .as_ref() - .map(|inst| inst.create_surface(handle)), - metal: self.instance.metal.create_surface(handle).unwrap(), - }; - #[cfg(all( - unix, - not(target_os = "android"), - not(target_os = "ios"), - not(target_os = "macos") - ))] - let surface = Surface { - vulkan: self - .instance - .vulkan - .as_ref() - .map(|inst| inst.create_surface(handle).ok()) - .flatten(), - }; - #[cfg(target_os = "android")] - let surface = Surface { - vulkan: self - .instance - .vulkan - .as_ref() - .map(|inst| inst.create_surface(handle).ok()) - .flatten(), - }; - #[cfg(windows)] - let surface = Surface { - vulkan: self - .instance - .vulkan - .as_ref() - .map(|inst| inst.create_surface(handle).ok()) - .flatten(), + #[cfg(windows)] dx12: self .instance .dx12 .as_ref() - .map(|inst| inst.create_surface(handle).ok()) - .flatten(), + .and_then(|inst| inst.create_surface(handle).ok()), + #[cfg(windows)] dx11: self.instance.dx11.create_surface(handle).unwrap(), - }; + } + }; - let mut token = Token::root(); - self.surfaces.register_identity(id_in, surface, &mut token) - } + let mut token = Token::root(); + self.surfaces.register_identity(id_in, surface, &mut token) } pub fn enumerate_adapters(&self, inputs: AdapterInputs>) -> Vec {