From fb48ff51c323e8de6bf15cda437e72eeae138a43 Mon Sep 17 00:00:00 2001 From: Andrea Nardi Date: Wed, 22 Jul 2020 21:41:17 +0200 Subject: [PATCH] [rs] made fields of direct::Context private --- wgpu/src/backend/direct.rs | 38 +++++++++++++++++++++++++++++++++++++- wgpu/src/lib.rs | 24 +++--------------------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 9ab0fbe455..dba59ca61e 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -12,7 +12,43 @@ use smallvec::SmallVec; use std::{ffi::CString, fmt, marker::PhantomData, ops::Range, ptr, slice}; use typed_arena::Arena; -pub struct Context(pub wgc::hub::Global); +pub struct Context(wgc::hub::Global); + +impl Context { + pub fn adapter_get_info(&self, id: wgc::id::AdapterId) -> wgc::instance::AdapterInfo { + let global = &self.0; + wgc::gfx_select!(id => global.adapter_get_info(id)) + } + + pub fn enumerate_adapters(&self, backends: wgt::BackendBit) -> Vec { + self.0 + .enumerate_adapters(wgc::instance::AdapterInputs::Mask(backends, |_| { + PhantomData + })) + } + + #[cfg(any(target_os = "ios", target_os = "macos"))] + pub unsafe fn create_surface_from_core_animation_layer( + &self, + layer: *mut std::ffi::c_void, + ) -> crate::Surface { + let surface = wgc::instance::Surface { + #[cfg(feature = "vulkan-portability")] + vulkan: None, //TODO: create_surface_from_layer ? + metal: self.0.instance.metal.as_ref().map(|inst| { + inst.create_surface_from_layer(layer as *mut _, cfg!(debug_assertions)) + }), + }; + + crate::Surface { + id: self.0.surfaces.register_identity( + PhantomData, + surface, + &mut wgc::hub::Token::root(), + ), + } + } +} impl fmt::Debug for Context { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index a2f00a5671..ebe6a50921 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -1020,10 +1020,7 @@ impl Instance { pub fn enumerate_adapters(&self, backends: BackendBit) -> impl Iterator { let context = Arc::clone(&self.context); self.context - .0 - .enumerate_adapters(wgc::instance::AdapterInputs::Mask(backends, |_| { - PhantomData - })) + .enumerate_adapters(backends) .into_iter() .map(move |id| crate::Adapter { id, @@ -1070,21 +1067,7 @@ impl Instance { &self, layer: *mut std::ffi::c_void, ) -> Surface { - let surface = wgc::instance::Surface { - #[cfg(feature = "vulkan-portability")] - vulkan: None, //TODO: create_surface_from_layer ? - metal: self.context.0.instance.metal.as_ref().map(|inst| { - inst.create_surface_from_layer(layer as *mut _, cfg!(debug_assertions)) - }), - }; - - crate::Surface { - id: self.context.0.surfaces.register_identity( - PhantomData, - surface, - &mut wgc::hub::Token::root(), - ), - } + self.context.create_surface_from_core_animation_layer(layer) } } @@ -1146,8 +1129,7 @@ impl Adapter { /// Get info about the adapter itself. #[cfg(not(target_arch = "wasm32"))] pub fn get_info(&self) -> AdapterInfo { - let global = &self.context.0; - wgc::gfx_select!(self.id => global.adapter_get_info(self.id)) + self.context.adapter_get_info(self.id) } }