Skip to content

Commit

Permalink
add CGDirectDisplayCopyCurrentMetalDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Nov 12, 2024
1 parent 217a185 commit 28312b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
25 changes: 24 additions & 1 deletion cidre/src/cg/direct_display.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(feature = "mtl")]
use crate::{arc, mtl};

pub type Id = u32;

pub type RefreshRate = f64;
Expand All @@ -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<arc::R<mtl::Device>> {
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<arc::R<mtl::Device>>;
}

#[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;
Expand Down
4 changes: 2 additions & 2 deletions cidre/src/mtl/function_constant_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 28312b3

Please # to comment.