#![allow(clippy::missing_panics_doc)]
use crate::ffi;
use std::ffi::c_void;
use std::fmt;
#[link(name = "CoreVideo", kind = "framework")]
extern "C" {
fn CVMetalTextureCacheGetTypeID() -> usize;
}
pub struct CVMetalTextureCache(*mut c_void);
impl CVMetalTextureCache {
#[must_use]
pub fn system_default() -> Option<Self> {
let ptr = unsafe { ffi::cv_metal_texture_cache_create_system_default() };
Self::from_raw(ptr)
}
#[must_use]
pub fn from_raw(ptr: *mut c_void) -> Option<Self> {
if ptr.is_null() {
None
} else {
Some(Self(ptr))
}
}
#[must_use]
pub const fn as_ptr(&self) -> *mut c_void {
self.0
}
#[must_use]
pub fn type_id() -> usize {
unsafe { CVMetalTextureCacheGetTypeID() }
}
pub fn flush(&self) {
unsafe { ffi::cv_metal_texture_cache_flush(self.0) };
}
}
impl Clone for CVMetalTextureCache {
fn clone(&self) -> Self {
let retained = unsafe { ffi::cf_type_retain(self.0) };
Self(retained)
}
}
impl Drop for CVMetalTextureCache {
fn drop(&mut self) {
unsafe { ffi::cf_type_release(self.0) };
}
}
impl PartialEq for CVMetalTextureCache {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl Eq for CVMetalTextureCache {}
impl std::hash::Hash for CVMetalTextureCache {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
unsafe { ffi::cf_type_hash(self.0) }.hash(state);
}
}
impl fmt::Debug for CVMetalTextureCache {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("CVMetalTextureCache")
.field("ptr", &self.0)
.field("type_id", &Self::type_id())
.finish()
}
}