diff options
author | 2021-05-19 07:14:26 -0700 | |
---|---|---|
committer | 2021-05-19 07:14:26 -0700 | |
commit | ae484429d30a3360893d030a17e52caa4164a052 (patch) | |
tree | 4bfe30d3b46c7e30170e0b495d9a4dd1a2a1825f /wgpu/src/window | |
parent | cf6af4c2560f5996bc533402ac3e4289c0c94702 (diff) | |
parent | 3918257883dba3cf260bd9764cb7b34101c435e6 (diff) | |
download | iced-ae484429d30a3360893d030a17e52caa4164a052.tar.gz iced-ae484429d30a3360893d030a17e52caa4164a052.tar.bz2 iced-ae484429d30a3360893d030a17e52caa4164a052.zip |
Merge branch 'hecrj:master' into upgrade-wgpu
Diffstat (limited to 'wgpu/src/window')
-rw-r--r-- | wgpu/src/window/compositor.rs | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index 6ff499af..9b65596f 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -21,9 +21,16 @@ impl Compositor { /// Requests a new [`Compositor`] with the given [`Settings`]. /// /// Returns `None` if no compatible graphics adapter could be found. - pub async fn request(settings: Settings) -> Option<Self> { + pub async fn request<W: HasRawWindowHandle>( + settings: Settings, + compatible_window: Option<&W>, + ) -> Option<Self> { let instance = wgpu::Instance::new(settings.internal_backend); + #[allow(unsafe_code)] + let compatible_surface = compatible_window + .map(|window| unsafe { instance.create_surface(window) }); + let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { power_preference: if settings.antialiasing.is_none() { @@ -31,7 +38,7 @@ impl Compositor { } else { wgpu::PowerPreference::HighPerformance }, - compatible_surface: None, + compatible_surface: compatible_surface.as_ref(), }) .await?; @@ -77,9 +84,15 @@ impl iced_graphics::window::Compositor for Compositor { type Surface = wgpu::Surface; type SwapChain = wgpu::SwapChain; - fn new(settings: Self::Settings) -> Result<(Self, Renderer), Error> { - let compositor = futures::executor::block_on(Self::request(settings)) - .ok_or(Error::AdapterNotFound)?; + fn new<W: HasRawWindowHandle>( + settings: Self::Settings, + compatible_window: Option<&W>, + ) -> Result<(Self, Renderer), Error> { + let compositor = futures::executor::block_on(Self::request( + settings, + compatible_window, + )) + .ok_or(Error::AdapterNotFound)?; let backend = compositor.create_backend(); |