-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support protocol.MTLDevice.methods."newTextureWithDescriptor:iosurface:plane:" #643
Comments
Indeed, it is intentionally skipped because we don't expose The proper solution needs support for CoreFoundation, for now you can do something like: #[repr(transparent)]
struct IOSurfaceRefWrapper(io_surface::IOSurfaceRef);
// SAFETY: `IOSurfaceRefWrapper` is `#[repr(transparent)]` over
// `IOSurfaceRef`, which is a typedef to `struct __IOSurface *`.
unsafe impl Encode for IOSurfaceRefWrapper {
const ENCODING: Encoding = Encoding::Pointer(&Encoding::Struct("__IOSurface", &[]));
}
pub fn new_with_descriptor_surface_plane(
device: &ProtocolObject<dyn MTLDevice>,
descriptor: &MTLTextureDescriptor,
surface: io_surface::IOSurfaceRef,
plane: NSUInteger,
) -> Retained<ProtocolObject<dyn MTLTexture>> {
let surface = IOSurfaceRefWrapper(surface);
msg_send_id![device, newTextureWithDescriptor: descriptor, iosurface: surface, plane: plane]
} This approach is somewhat documented in here. |
Update: We now have fairly good support for CoreFoundation, and by extension So I've now un-skipped the |
@madsmtm May I ask how it is possible to create an let surface = IOSurface::new(); The created surface is a I need it for functions such as pub fn IOSurfaceLock(
buffer: &IOSurfaceRef,
options: IOSurfaceLockOptions,
seed: *mut u32,
) -> libc::kern_return_t; Thanks. |
It should be possible, since the Objective-C |
For now, you can do something like: use objc2_core_foundation::CFRetained;
use objc2::rc::Retained;
use objc2_io_surface::{IOSurfaceRef, IOSurface};
let iosurface = IOSurface::new();
let iosurface_ref: CFRetained<IOSurfaceRef> = unsafe { CFRetained::from_raw(NonNull::new(Retained::into_raw(iosurface)).unwrap().cast()) }; |
Thanks for your reply. I noticed there are methods (e.g, I would also like to make suggestion for a function similar to Right now, I have to do the following: let keys: &[&IOSurfacePropertyKey; 2] = &[
IOSurfacePropertyKeyWidth,
IOSurfacePropertyKeyHeight,
// ...
];
let values: &[&AnyObject; 2] = &[
&*NSNumber::new_u32(width),
&*NSNumber::new_u32(height),
// ...
];
let properties = NSDictionary::from_slices(keys, values);
IOSurface::initWithProperties(IOSurface::alloc(), &*properties).unwrap() Maybe there could be a method to do the allocation? |
Adding more methods to
I'm not sure what you mean by this? |
Could there be a method added to For example: fn from_properties(
properties: &NSDictionary<IOSurfacePropertyKey, AnyObject>,
) -> Option<Retained<Self>> {
unsafe { Self::initWithProperties(Self::alloc(), properties) }
} |
Ah, I understand now. I'm fairly reluctant to add such simple helpers, as it obscures what's actually happening (you now have to look at the method definition to know that it's calling the Objective-C method Instead, I'd rather mark IOSurface::alloc().initWithProperties(properties) |
Ok, that seems better. Thank you |
The newTextureWithDescriptor:iosurface:plane: is not supported. It is necessary for
gfx-rs/wgpu#5641 to be used by gecko see Bug 1910043.
The text was updated successfully, but these errors were encountered: