apple_cf/cv/
metal_texture_cache.rs1#![allow(clippy::missing_panics_doc)]
4
5use crate::ffi;
14use std::ffi::c_void;
15use std::fmt;
16
17#[link(name = "CoreVideo", kind = "framework")]
18extern "C" {
19 fn CVMetalTextureCacheGetTypeID() -> usize;
20}
21
22pub struct CVMetalTextureCache(*mut c_void);
24
25impl CVMetalTextureCache {
26 #[must_use]
28 pub fn system_default() -> Option<Self> {
29 let ptr = unsafe { ffi::cv_metal_texture_cache_create_system_default() };
30 Self::from_raw(ptr)
31 }
32
33 #[must_use]
34 pub fn from_raw(ptr: *mut c_void) -> Option<Self> {
35 if ptr.is_null() {
36 None
37 } else {
38 Some(Self(ptr))
39 }
40 }
41
42 #[must_use]
44 pub const fn as_ptr(&self) -> *mut c_void {
45 self.0
46 }
47
48 #[must_use]
50 pub fn type_id() -> usize {
51 unsafe { CVMetalTextureCacheGetTypeID() }
52 }
53
54 pub fn flush(&self) {
56 unsafe { ffi::cv_metal_texture_cache_flush(self.0) };
57 }
58}
59
60impl Clone for CVMetalTextureCache {
61 fn clone(&self) -> Self {
62 let retained = unsafe { ffi::cf_type_retain(self.0) };
63 Self(retained)
64 }
65}
66
67impl Drop for CVMetalTextureCache {
68 fn drop(&mut self) {
69 if !self.0.is_null() {
70 unsafe { ffi::cf_type_release(self.0) };
71 }
72 }
73}
74
75impl PartialEq for CVMetalTextureCache {
76 fn eq(&self, other: &Self) -> bool {
77 self.0 == other.0
78 }
79}
80
81impl Eq for CVMetalTextureCache {}
82
83impl std::hash::Hash for CVMetalTextureCache {
84 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
85 unsafe { ffi::cf_type_hash(self.0) }.hash(state);
86 }
87}
88
89impl fmt::Debug for CVMetalTextureCache {
90 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
91 f.debug_struct("CVMetalTextureCache")
92 .field("ptr", &self.0)
93 .field("type_id", &Self::type_id())
94 .finish()
95 }
96}