objc2_core_video/generated/
CVMetalBufferCache.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9use objc2_core_foundation::*;
10#[cfg(feature = "objc2-metal")]
11#[cfg(not(target_os = "watchos"))]
12use objc2_metal::*;
13
14use crate::*;
15
16extern "C" {
17    /// [Apple's documentation](https://developer.apple.com/documentation/corevideo/kcvmetalbuffercachemaximumbufferagekey?language=objc)
18    pub static kCVMetalBufferCacheMaximumBufferAgeKey: &'static CFString;
19}
20
21/// [Apple's documentation](https://developer.apple.com/documentation/corevideo/cvmetalbuffercache?language=objc)
22#[doc(alias = "CVMetalBufferCacheRef")]
23#[repr(C)]
24pub struct CVMetalBufferCache {
25    inner: [u8; 0],
26    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
27}
28
29cf_type!(
30    unsafe impl CVMetalBufferCache {}
31);
32#[cfg(feature = "objc2")]
33cf_objc2_type!(
34    unsafe impl RefEncode<"__CVMetalBufferCache"> for CVMetalBufferCache {}
35);
36
37unsafe impl ConcreteType for CVMetalBufferCache {
38    #[doc(alias = "CVMetalBufferCacheGetTypeID")]
39    #[inline]
40    fn type_id() -> CFTypeID {
41        extern "C-unwind" {
42            fn CVMetalBufferCacheGetTypeID() -> CFTypeID;
43        }
44        unsafe { CVMetalBufferCacheGetTypeID() }
45    }
46}
47
48impl CVMetalBufferCache {
49    /// Creates a new Buffer Cache.
50    ///
51    /// Parameter `allocator`: The CFAllocatorRef to use for allocating the cache.  May be NULL.
52    ///
53    /// Parameter `cacheAttributes`: A CFDictionaryRef containing the attributes of the cache itself. May be NULL.
54    ///
55    /// Parameter `metalDevice`: The Metal device for which the buffer objects will be created.
56    ///
57    /// Parameter `cacheOut`: The newly created buffer cache will be placed here
58    ///
59    /// Returns: Returns kCVReturnSuccess on success
60    ///
61    /// # Safety
62    ///
63    /// - `cache_attributes` generics must be of the correct type.
64    /// - `cache_out` must be a valid pointer.
65    #[doc(alias = "CVMetalBufferCacheCreate")]
66    #[cfg(all(feature = "CVReturn", feature = "objc2", feature = "objc2-metal"))]
67    #[cfg(not(target_os = "watchos"))]
68    #[inline]
69    pub unsafe fn create(
70        allocator: Option<&CFAllocator>,
71        cache_attributes: Option<&CFDictionary>,
72        metal_device: &ProtocolObject<dyn MTLDevice>,
73        cache_out: NonNull<*mut CVMetalBufferCache>,
74    ) -> CVReturn {
75        extern "C-unwind" {
76            fn CVMetalBufferCacheCreate(
77                allocator: Option<&CFAllocator>,
78                cache_attributes: Option<&CFDictionary>,
79                metal_device: &ProtocolObject<dyn MTLDevice>,
80                cache_out: NonNull<*mut CVMetalBufferCache>,
81            ) -> CVReturn;
82        }
83        unsafe { CVMetalBufferCacheCreate(allocator, cache_attributes, metal_device, cache_out) }
84    }
85
86    /// Creates a CVMetalBuffer object from an existing CVImageBuffer
87    ///
88    /// Parameter `allocator`: The CFAllocatorRef to use for allocating the CVMetalBuffer object. May be NULL.
89    ///
90    /// Parameter `bufferCache`: The buffer cache object that will manage the buffer.
91    ///
92    /// Parameter `buffer`: The CVImageBuffer that you want to create a CVMetalBuffer from.
93    ///
94    /// Parameter `bufferOut`: The newly created buffer object will be placed here.
95    ///
96    /// Returns: Returns kCVReturnSuccess on success
97    ///
98    /// Creates or returns a cached CVMetalBuffer object mapped to the CVImageBuffer.
99    /// This creates a live binding between the CVImageBuffer and underlying CVMetalBuffer buffer object.
100    ///
101    /// IMPORTANT NOTE: Clients should retain CVMetalBuffer objects until they are done using the images in them.
102    /// Retaining a CVMetalBuffer is your way to indicate that you're still using the image in the buffer, and that it should not be recycled yet.
103    ///
104    /// # Safety
105    ///
106    /// `buffer_out` must be a valid pointer.
107    #[doc(alias = "CVMetalBufferCacheCreateBufferFromImage")]
108    #[cfg(all(
109        feature = "CVBuffer",
110        feature = "CVImageBuffer",
111        feature = "CVMetalBuffer",
112        feature = "CVReturn"
113    ))]
114    #[inline]
115    pub unsafe fn create_buffer_from_image(
116        allocator: Option<&CFAllocator>,
117        buffer_cache: &CVMetalBufferCache,
118        image_buffer: &CVImageBuffer,
119        buffer_out: NonNull<*mut CVMetalBuffer>,
120    ) -> CVReturn {
121        extern "C-unwind" {
122            fn CVMetalBufferCacheCreateBufferFromImage(
123                allocator: Option<&CFAllocator>,
124                buffer_cache: &CVMetalBufferCache,
125                image_buffer: &CVImageBuffer,
126                buffer_out: NonNull<*mut CVMetalBuffer>,
127            ) -> CVReturn;
128        }
129        unsafe {
130            CVMetalBufferCacheCreateBufferFromImage(
131                allocator,
132                buffer_cache,
133                image_buffer,
134                buffer_out,
135            )
136        }
137    }
138
139    /// Performs internal housekeeping/recycling operations
140    ///
141    /// This call must be made periodically to give the buffer cache a chance to do internal housekeeping operations.
142    ///
143    /// Parameter `bufferCache`: The buffer cache object to flush
144    ///
145    /// Parameter `options`: Currently unused, set to 0.
146    #[doc(alias = "CVMetalBufferCacheFlush")]
147    #[cfg(feature = "CVBase")]
148    #[inline]
149    pub fn flush(&self, options: CVOptionFlags) {
150        extern "C-unwind" {
151            fn CVMetalBufferCacheFlush(buffer_cache: &CVMetalBufferCache, options: CVOptionFlags);
152        }
153        unsafe { CVMetalBufferCacheFlush(self, options) }
154    }
155}
156
157extern "C-unwind" {
158    #[cfg(all(feature = "CVReturn", feature = "objc2", feature = "objc2-metal"))]
159    #[cfg(not(target_os = "watchos"))]
160    #[deprecated = "renamed to `CVMetalBufferCache::create`"]
161    pub fn CVMetalBufferCacheCreate(
162        allocator: Option<&CFAllocator>,
163        cache_attributes: Option<&CFDictionary>,
164        metal_device: &ProtocolObject<dyn MTLDevice>,
165        cache_out: NonNull<*mut CVMetalBufferCache>,
166    ) -> CVReturn;
167}
168
169extern "C-unwind" {
170    #[cfg(all(
171        feature = "CVBuffer",
172        feature = "CVImageBuffer",
173        feature = "CVMetalBuffer",
174        feature = "CVReturn"
175    ))]
176    #[deprecated = "renamed to `CVMetalBufferCache::create_buffer_from_image`"]
177    pub fn CVMetalBufferCacheCreateBufferFromImage(
178        allocator: Option<&CFAllocator>,
179        buffer_cache: &CVMetalBufferCache,
180        image_buffer: &CVImageBuffer,
181        buffer_out: NonNull<*mut CVMetalBuffer>,
182    ) -> CVReturn;
183}
184
185#[cfg(feature = "CVBase")]
186#[deprecated = "renamed to `CVMetalBufferCache::flush`"]
187#[inline]
188pub extern "C-unwind" fn CVMetalBufferCacheFlush(
189    buffer_cache: &CVMetalBufferCache,
190    options: CVOptionFlags,
191) {
192    extern "C-unwind" {
193        fn CVMetalBufferCacheFlush(buffer_cache: &CVMetalBufferCache, options: CVOptionFlags);
194    }
195    unsafe { CVMetalBufferCacheFlush(buffer_cache, options) }
196}