use super::connection::Connection;
use crate::Error;
use objc2::{rc::Retained, runtime::ProtocolObject};
use objc2_metal::{MTLCopyAllDevices, MTLDevice};
use std::marker::PhantomData;
#[derive(Clone, Debug)]
pub struct Adapter {
pub(crate) is_low_power: bool,
}
#[derive(Clone)]
pub struct Device {
adapter: Adapter,
phantom: PhantomData<*mut ()>,
}
#[derive(Clone)]
pub struct NativeDevice(pub Retained<ProtocolObject<dyn MTLDevice>>);
impl Device {
#[inline]
pub(crate) fn new(adapter: Adapter) -> Result<Device, Error> {
Ok(Device {
adapter,
phantom: PhantomData,
})
}
pub fn native_device(&self) -> NativeDevice {
NativeDevice(
MTLCopyAllDevices()
.into_iter()
.find(|device| device.isLowPower() == self.adapter.is_low_power)
.expect("No Metal device found!"),
)
}
#[inline]
pub fn connection(&self) -> Connection {
Connection
}
#[inline]
pub fn adapter(&self) -> Adapter {
self.adapter.clone()
}
}