Expose CA surface creation

This commit is contained in:
Dzmitry Malyshau 2021-03-03 15:43:55 -05:00
parent 199e7e5f3b
commit f7e1304c38
2 changed files with 28 additions and 5 deletions

View File

@ -302,7 +302,7 @@ thread_local! {
/// ///
/// Note: there can only be one non-borrowed `Token` alive on a thread /// Note: there can only be one non-borrowed `Token` alive on a thread
/// at a time, which is enforced by `ACTIVE_TOKEN`. /// at a time, which is enforced by `ACTIVE_TOKEN`.
pub struct Token<'a, T: 'a> { pub(crate) struct Token<'a, T: 'a> {
level: PhantomData<&'a T>, level: PhantomData<&'a T>,
} }
@ -446,6 +446,7 @@ pub(crate) struct FutureId<'a, I: TypedId, T> {
} }
impl<I: TypedId + Copy, T> FutureId<'_, I, T> { impl<I: TypedId + Copy, T> FutureId<'_, I, T> {
#[cfg(feature = "trace")]
pub fn id(&self) -> I { pub fn id(&self) -> I {
self.id self.id
} }
@ -472,14 +473,14 @@ impl<T: Resource, I: TypedId + Copy, F: IdentityHandlerFactory<I>> Registry<T, I
} }
} }
pub fn read<'a, A: Access<T>>( pub(crate) fn read<'a, A: Access<T>>(
&'a self, &'a self,
_token: &'a mut Token<A>, _token: &'a mut Token<A>,
) -> (RwLockReadGuard<'a, Storage<T, I>>, Token<'a, T>) { ) -> (RwLockReadGuard<'a, Storage<T, I>>, Token<'a, T>) {
(self.data.read(), Token::new()) (self.data.read(), Token::new())
} }
pub fn write<'a, A: Access<T>>( pub(crate) fn write<'a, A: Access<T>>(
&'a self, &'a self,
_token: &'a mut Token<A>, _token: &'a mut Token<A>,
) -> (RwLockWriteGuard<'a, Storage<T, I>>, Token<'a, T>) { ) -> (RwLockWriteGuard<'a, Storage<T, I>>, Token<'a, T>) {
@ -508,7 +509,7 @@ impl<T: Resource, I: TypedId + Copy, F: IdentityHandlerFactory<I>> Registry<T, I
} }
//TODO: consider remove this once everything uses `prepare` //TODO: consider remove this once everything uses `prepare`
pub fn register_error<A: Access<T>>( pub(crate) fn register_error<A: Access<T>>(
&self, &self,
id_in: <F::Filter as IdentityHandler<I>>::Input, id_in: <F::Filter as IdentityHandler<I>>::Input,
label: &str, label: &str,
@ -525,7 +526,7 @@ impl<T: Resource, I: TypedId + Copy, F: IdentityHandlerFactory<I>> Registry<T, I
value value
} }
pub fn unregister<'a, A: Access<T>>( pub(crate) fn unregister<'a, A: Access<T>>(
&self, &self,
id: I, id: I,
_token: &'a mut Token<A>, _token: &'a mut Token<A>,

View File

@ -631,6 +631,28 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
id.0 id.0
} }
#[cfg(metal)]
pub fn instance_create_surface_metal(
&self,
layer: *mut std::ffi::c_void,
id_in: Input<G, SurfaceId>,
) -> SurfaceId {
span!(_guard, INFO, "Instance::instance_create_surface_metal");
let surface =
Surface {
#[cfg(feature = "vulkan-portability")]
vulkan: None, //TODO: create_surface_from_layer ?
metal: self.instance.metal.as_ref().map(|inst| {
inst.create_surface_from_layer(unsafe { std::mem::transmute(layer) })
}),
};
let mut token = Token::root();
let id = self.surfaces.register_identity(id_in, surface, &mut token);
id.0
}
pub fn surface_drop(&self, id: SurfaceId) { pub fn surface_drop(&self, id: SurfaceId) {
span!(_guard, INFO, "Surface::drop"); span!(_guard, INFO, "Surface::drop");
let mut token = Token::root(); let mut token = Token::root();