From e4741a7720e9c668cc2b2ed440951b8ce3700ad6 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Wed, 10 Jul 2024 23:38:44 +0200 Subject: [PATCH] Make wrappers separate --- .../objc2-metal/examples/triangle.rs | 2 +- framework-crates/objc2-metal/src/device.rs | 24 ++++++++++++------- framework-crates/objc2-metal/src/lib.rs | 2 +- .../tests/runs_with_core_graphics.rs | 8 ++++--- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/framework-crates/objc2-metal/examples/triangle.rs b/framework-crates/objc2-metal/examples/triangle.rs index 20dd9beaa..43d95e9f8 100644 --- a/framework-crates/objc2-metal/examples/triangle.rs +++ b/framework-crates/objc2-metal/examples/triangle.rs @@ -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 diff --git a/framework-crates/objc2-metal/src/device.rs b/framework-crates/objc2-metal/src/device.rs index a9eeec92a..00f8ad796 100644 --- a/framework-crates/objc2-metal/src/device.rs +++ b/framework-crates/objc2-metal/src/device.rs @@ -3,14 +3,22 @@ use objc2_foundation::NSArray; use crate::MTLDevice; -pub trait MTLDeviceExt: MTLDevice { - fn system_default() -> Option>> { - unsafe { Id::from_raw(crate::MTLCreateSystemDefaultDevice()) } - } +// pub trait MTLDeviceExt: MTLDevice { +// fn system_default() -> Option>> { +// unsafe { Id::from_raw(crate::MTLCreateSystemDefaultDevice()) } +// } - fn all() -> Id>> { - unsafe { Id::new_nonnull(crate::MTLCopyAllDevices()) } - } +// fn all() -> Id>> { +// unsafe { Id::new_nonnull(crate::MTLCopyAllDevices()) } +// } +// } + +// impl MTLDeviceExt for P {} + +pub fn mtl_device_system_default() -> Option>> { + unsafe { Id::from_raw(crate::MTLCreateSystemDefaultDevice()) } } -impl MTLDeviceExt for P {} +pub fn mtl_device_all() -> Id>> { + unsafe { Id::new_nonnull(crate::MTLCopyAllDevices()) } +} diff --git a/framework-crates/objc2-metal/src/lib.rs b/framework-crates/objc2-metal/src/lib.rs index 7cbec515f..5bea1d628 100644 --- a/framework-crates/objc2-metal/src/lib.rs +++ b/framework-crates/objc2-metal/src/lib.rs @@ -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")] diff --git a/framework-crates/objc2-metal/tests/runs_with_core_graphics.rs b/framework-crates/objc2-metal/tests/runs_with_core_graphics.rs index d09df68dd..b639c40e0 100644 --- a/framework-crates/objc2-metal/tests/runs_with_core_graphics.rs +++ b/framework-crates/objc2-metal/tests/runs_with_core_graphics.rs @@ -1,5 +1,5 @@ #![cfg(feature = "MTLDevice")] -use objc2_metal::MTLDevice; +use objc2_metal::mtl_device_system_default; #[link(name = "CoreGraphics", kind = "framework")] extern "C" {} @@ -7,11 +7,13 @@ 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(); }