diff --git a/cidre/src/cg/direct_display.rs b/cidre/src/cg/direct_display.rs index 2d2e8175..a29693ff 100644 --- a/cidre/src/cg/direct_display.rs +++ b/cidre/src/cg/direct_display.rs @@ -1,3 +1,6 @@ +#[cfg(feature = "mtl")] +use crate::{arc, mtl}; + pub type Id = u32; pub type RefreshRate = f64; @@ -9,9 +12,29 @@ pub fn main_display_id() -> Id { unsafe { CGMainDisplayID() } } -extern "C" { +#[doc(alias = "CGDirectDisplayCopyCurrentMetalDevice")] +#[cfg(all(target_os = "macos", feature = "mtl"))] +pub fn direct_display_current_mtl_device(display: Id) -> Option> { + unsafe { CGDirectDisplayCopyCurrentMetalDevice(display) } +} + +extern "C-unwind" { #[cfg(target_os = "macos")] fn CGMainDisplayID() -> Id; + + #[cfg(all(target_os = "macos", feature = "mtl"))] + fn CGDirectDisplayCopyCurrentMetalDevice(display: Id) -> Option>; +} + +#[cfg(test)] +mod tests { + use super::{direct_display_current_mtl_device, main_display_id}; + + #[test] + fn basics() { + let display = main_display_id(); + let _device = direct_display_current_mtl_device(display).expect("Failed to get device"); + } } // typedef uint32_t CGDirectDisplayID; diff --git a/cidre/src/mtl/function_constant_values.rs b/cidre/src/mtl/function_constant_values.rs index 383a45b8..b068be3f 100644 --- a/cidre/src/mtl/function_constant_values.rs +++ b/cidre/src/mtl/function_constant_values.rs @@ -15,12 +15,12 @@ impl FnConstValues { pub fn set_value_at(&mut self, val: *const c_void, type_: mtl::DType, at_index: ns::UInteger); pub fn set_bool_at(&mut self, val: bool, at_index: usize) { - debug_assert!(at_index < u16::MAX as _); + debug_assert!(at_index <= u16::MAX as _); self.set_value_at(&val as *const bool as *const _, mtl::DType::Bool, at_index); } pub fn set_u8_at(&mut self, val: u8, at_index: usize) { - debug_assert!(at_index < u16::MAX as _); + debug_assert!(at_index <= u16::MAX as _); self.set_value_at(&val as *const u8 as *const _, mtl::DType::U8, at_index); }