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 13, 2024
1 parent edb6ddf commit 2217830
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
7 changes: 4 additions & 3 deletions framework-crates/objc2-metal/examples/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ use objc2_foundation::{
ns_string, NSDate, NSNotification, NSObject, NSObjectProtocol, NSPoint, NSRect, NSSize,
};
use objc2_metal::{
MTLCommandBuffer, MTLCommandEncoder, MTLCommandQueue, MTLDevice, MTLLibrary, MTLPackedFloat3,
MTLPrimitiveType, MTLRenderCommandEncoder, MTLRenderPipelineDescriptor, MTLRenderPipelineState,
MTLCommandBuffer, MTLCommandEncoder, MTLCommandQueue, MTLCreateSystemDefaultDevice, MTLDevice,
MTLLibrary, MTLPackedFloat3, MTLPrimitiveType, MTLRenderCommandEncoder,
MTLRenderPipelineDescriptor, MTLRenderPipelineState,
};
use objc2_metal_kit::{MTKView, MTKViewDelegate};

Expand Down Expand Up @@ -105,7 +106,7 @@ declare_class!(
};

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

// create the command queue
let command_queue = device
Expand Down
14 changes: 5 additions & 9 deletions framework-crates/objc2-metal/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ 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()) }
}

fn all() -> Id<NSArray<ProtocolObject<dyn MTLDevice>>> {
unsafe { Id::new_nonnull(crate::MTLCopyAllDevices()) }
}
pub fn MTLCreateSystemDefaultDevice() -> Option<Id<ProtocolObject<dyn MTLDevice>>> {
unsafe { Id::from_raw(crate::generated::MTLCreateSystemDefaultDevice()) }
}

impl<P: MTLDevice> MTLDeviceExt for P {}
pub fn MTLCopyAllDevices() -> Id<NSArray<ProtocolObject<dyn MTLDevice>>> {
unsafe { Id::new_nonnull(crate::generated::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 [`MTLCreateSystemDefaultDevice()`] 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::MTLCreateSystemDefaultDevice;

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

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

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

let _ = MTLCopyAllDevices();
}

0 comments on commit 2217830

Please sign in to comment.