use crate::{arc, define_cls, define_obj_type, mtl, ns, objc};
#[doc(alias = "MTLCaptureDestination")]
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
#[repr(isize)]
pub enum CaptureDst {
DeveloperTools = 1,
GpuTraceDocument,
}
define_obj_type!(pub CaptureDesc(ns::Id), MTL_CAPTURE_DESCRIPTOR);
impl CaptureDesc {
#[objc::msg_send(captureObject)]
pub fn capture_obj(&self) -> Option<arc::R<ns::Id>>;
#[objc::msg_send(setCaptureObject:)]
pub fn set_capture_obj(&mut self, val: &ns::Id);
#[objc::msg_send(destination)]
pub fn dst(&self) -> CaptureDst;
#[objc::msg_send(setDestination:)]
pub fn set_dst(&self, val: CaptureDst);
#[objc::msg_send(outputURL)]
pub fn output_url(&self) -> Option<arc::R<ns::Url>>;
#[objc::msg_send(setOutputURL:)]
pub fn set_output_url(&mut self, val: Option<&ns::Url>);
}
define_obj_type!(pub CaptureManager(ns::Id));
impl CaptureManager {
define_cls!(MTL_CAPTURE_MANAGER);
}
impl CaptureManager {
#[objc::msg_send(sharedCaptureManager)]
pub fn shared() -> arc::R<Self>;
#[objc::msg_send(startCaptureWithDescriptor:error:)]
pub unsafe fn start_with_descriptor_err<'ar>(
&mut self,
desc: &CaptureDesc,
error: *mut Option<&'ar ns::Error>,
) -> bool;
#[inline]
pub fn start(&mut self, desc: &CaptureDesc) -> ns::Result {
ns::if_false(|err| unsafe { self.start_with_descriptor_err(desc, err) })
}
#[objc::msg_send(stopCapture)]
pub fn stop(&mut self);
#[objc::msg_send(isCapturing)]
pub fn is_capturing(&self) -> bool;
#[objc::msg_send(supportsDestination:)]
pub fn supports_dst(&self, val: CaptureDst) -> bool;
#[objc::msg_send(newCaptureScopeWithDevice:)]
pub fn new_capture_scope_with_device(&self, device: &mtl::Device) -> arc::R<mtl::CaptureScope>;
#[objc::msg_send(newCaptureScopeWithCommandQueue:)]
pub fn new_capture_scope_with_cmd_queue(
&self,
cmd_queue: &mtl::CmdQueue,
) -> arc::R<mtl::CaptureScope>;
#[objc::msg_send(defaultCaptureScope)]
pub fn default_capture_scope(&self) -> Option<arc::R<mtl::CaptureScope>>;
}
#[link(name = "mtl", kind = "static")]
unsafe extern "C" {
static MTL_CAPTURE_DESCRIPTOR: &'static objc::Class<CaptureDesc>;
static MTL_CAPTURE_MANAGER: &'static objc::Class<CaptureManager>;
}
#[cfg(test)]
mod tests {
use crate::{mtl, ns};
#[test]
fn basics() {
let mut desc = mtl::CaptureDesc::new();
desc.set_capture_obj(ns::str!(c"invalid obj"));
let mut manager = mtl::CaptureManager::shared();
manager.start(&desc).expect_err("invalid");
}
}