Skip to content

Commit

Permalink
Make wrappers separate
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Jul 10, 2024
1 parent edb6ddf commit e4741a7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion framework-crates/objc2-metal/examples/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ declare_class!(
};

// get the default device
let device = MTLDevice::system_default().expect("Failed to get default system device.");
let device = mtl_device_system_default().expect("Failed to get default system device.");

// create the command queue
let command_queue = device
Expand Down
24 changes: 16 additions & 8 deletions framework-crates/objc2-metal/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ use objc2_foundation::NSArray;

use crate::MTLDevice;

pub trait MTLDeviceExt: MTLDevice {
fn system_default() -> Option<Id<ProtocolObject<dyn MTLDevice>>> {
unsafe { Id::from_raw(crate::MTLCreateSystemDefaultDevice()) }
}
// pub trait MTLDeviceExt: MTLDevice {
// fn system_default() -> Option<Id<ProtocolObject<dyn MTLDevice>>> {
// unsafe { Id::from_raw(crate::MTLCreateSystemDefaultDevice()) }
// }

fn all() -> Id<NSArray<ProtocolObject<dyn MTLDevice>>> {
unsafe { Id::new_nonnull(crate::MTLCopyAllDevices()) }
}
// fn all() -> Id<NSArray<ProtocolObject<dyn MTLDevice>>> {
// unsafe { Id::new_nonnull(crate::MTLCopyAllDevices()) }
// }
// }

// impl<P: MTLDevice> MTLDeviceExt for P {}

pub fn mtl_device_system_default() -> Option<Id<ProtocolObject<dyn MTLDevice>>> {
unsafe { Id::from_raw(crate::MTLCreateSystemDefaultDevice()) }
}

impl<P: MTLDevice> MTLDeviceExt for P {}
pub fn mtl_device_all() -> Id<NSArray<ProtocolObject<dyn MTLDevice>>> {
unsafe { Id::new_nonnull(crate::MTLCopyAllDevices()) }
}
2 changes: 1 addition & 1 deletion framework-crates/objc2-metal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//!
//! [apple-doc]: https://developer.apple.com/documentation/xcode/validating-your-apps-metal-api-usage/.
//!
//! Note: To use [`MTLDevice::system_default()`] you need to link to
//! Note: To use [`mtl_device_system_default()`] you need to link to
//! `CoreGraphics`, this can be done by using `objc2-app-kit`, or by doing:
//! ```rust
//! #[link(name = "CoreGraphics", kind = "framework")]
Expand Down
8 changes: 5 additions & 3 deletions framework-crates/objc2-metal/tests/runs_with_core_graphics.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#![cfg(feature = "MTLDevice")]
use objc2_metal::MTLDevice;
use objc2_metal::mtl_device_system_default;

#[link(name = "CoreGraphics", kind = "framework")]
extern "C" {}

#[test]
#[ignore = "doesn't work in CI"]
fn test_create_default() {
let _ = MTLDevice::system_default();
let _ = mtl_device_system_default();
}

#[test]
#[cfg(target_os = "macos")]
fn get_all() {
let _ = MTLDevice::all();
use objc2_metal::mtl_device_all;

let _ = mtl_device_all();
}

0 comments on commit e4741a7

Please sign in to comment.