-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metal: Reexpose static fns on
MTLDevice
- Loading branch information
Showing
5 changed files
with
27 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
// use crate::MTLDevice; | ||
// | ||
// pub trait MTLDeviceExtension { | ||
// pub fn system_default() -> Option<Self> { | ||
// MTLCreateSystemDefaultDevice() | ||
// } | ||
// | ||
// pub fn all() -> Retained<NSArray<Self>> { | ||
// #[cfg(target_os = "macos")] | ||
// MTLCopyAllDevices() | ||
// #[cfg(not(target_os = "macos"))] | ||
// NSArray::from(MTLCreateSystemDefaultDevice()) | ||
// } | ||
// } | ||
// | ||
// impl<P: MTLDevice> MTLDeviceExtension for P {} | ||
use objc2::{rc::Id, runtime::ProtocolObject}; | ||
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()) } | ||
} | ||
} | ||
|
||
impl<P: MTLDevice> MTLDeviceExt for P {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
framework-crates/objc2-metal/tests/runs_with_core_graphics.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
#![cfg(feature = "MTLDevice")] | ||
use objc2::rc::Retained; | ||
use objc2_metal::MTLCreateSystemDefaultDevice; | ||
use objc2_metal::MTLDevice; | ||
|
||
#[link(name = "CoreGraphics", kind = "framework")] | ||
extern "C" {} | ||
|
||
#[test] | ||
#[ignore = "doesn't work in CI"] | ||
fn test_create_default() { | ||
let _ = unsafe { Retained::from_raw(MTLCreateSystemDefaultDevice()).unwrap() }; | ||
let _ = MTLDevice::system_default(); | ||
} | ||
|
||
#[test] | ||
#[cfg(target_os = "macos")] | ||
fn get_all() { | ||
let _ = unsafe { Retained::from_raw(objc2_metal::MTLCopyAllDevices().as_ptr()).unwrap() }; | ||
let _ = MTLDevice::all(); | ||
} |