use crate::ffi::*;
use std::ffi::c_void;
pub struct Texture {
raw: ObjcId,
}
impl Texture {
pub(crate) fn from_raw(raw: ObjcId) -> Self {
Texture { raw }
}
pub fn width(&self) -> usize {
unsafe { msg0_usize(self.raw, SEL_width()) }
}
pub fn height(&self) -> usize {
unsafe { msg0_usize(self.raw, SEL_height()) }
}
#[mutants::skip] pub fn depth(&self) -> usize {
unsafe { msg0_usize(self.raw, SEL_depth()) }
}
pub fn pixel_format(&self) -> usize {
unsafe { msg0_usize(self.raw, SEL_pixelFormat()) }
}
pub unsafe fn replace_region(
&self,
region: MTLRegion,
mipmap_level: usize,
data: *const c_void,
bytes_per_row: usize,
) {
type F =
unsafe extern "C" fn(ObjcId, ObjcSel, MTLRegion, NSUInteger, *const c_void, NSUInteger);
let f: F = std::mem::transmute(objc_msgSend as *const c_void);
f(
self.raw,
SEL_replaceRegion(),
region,
mipmap_level,
data,
bytes_per_row,
);
}
pub unsafe fn get_bytes(
&self,
data: *mut c_void,
bytes_per_row: usize,
region: MTLRegion,
mipmap_level: usize,
) {
type F =
unsafe extern "C" fn(ObjcId, ObjcSel, *mut c_void, NSUInteger, MTLRegion, NSUInteger);
let f: F = std::mem::transmute(objc_msgSend as *const c_void);
f(
self.raw,
SEL_getBytes(),
data,
bytes_per_row,
region,
mipmap_level,
);
}
pub fn as_raw(&self) -> ObjcId {
self.raw
}
}
impl Drop for Texture {
#[mutants::skip] fn drop(&mut self) {
unsafe { release(self.raw) };
}
}