objc2_core_video/generated/
CVMetalTextureCache.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/kcvmetaltexturecachemaximumtextureagekey?language=objc)
18    pub static kCVMetalTextureCacheMaximumTextureAgeKey: &'static CFString;
19}
20
21/// CoreVideo Metal Texture Cache
22///
23/// See also [Apple's documentation](https://developer.apple.com/documentation/corevideo/cvmetaltexturecache?language=objc)
24#[doc(alias = "CVMetalTextureCacheRef")]
25#[repr(C)]
26pub struct CVMetalTextureCache {
27    inner: [u8; 0],
28    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
29}
30
31cf_type!(
32    unsafe impl CVMetalTextureCache {}
33);
34#[cfg(feature = "objc2")]
35cf_objc2_type!(
36    unsafe impl RefEncode<"__CVMetalTextureCache"> for CVMetalTextureCache {}
37);
38
39unsafe impl ConcreteType for CVMetalTextureCache {
40    #[doc(alias = "CVMetalTextureCacheGetTypeID")]
41    #[inline]
42    fn type_id() -> CFTypeID {
43        extern "C-unwind" {
44            fn CVMetalTextureCacheGetTypeID() -> CFTypeID;
45        }
46        unsafe { CVMetalTextureCacheGetTypeID() }
47    }
48}
49
50impl CVMetalTextureCache {
51    /// Creates a new Texture Cache.
52    ///
53    /// Parameter `allocator`: The CFAllocatorRef to use for allocating the cache.  May be NULL.
54    ///
55    /// Parameter `cacheAttributes`: A CFDictionaryRef containing the attributes of the cache itself.   May be NULL.
56    ///
57    /// Parameter `metalDevice`: The Metal device for which the texture objects will be created.
58    ///
59    /// Parameter `textureAttributes`: A CFDictionaryRef containing the attributes to be used for creating the CVMetalTexture objects.  May be NULL.
60    ///
61    /// Parameter `cacheOut`: The newly created texture cache will be placed here
62    ///
63    /// Returns: Returns kCVReturnSuccess on success
64    ///
65    /// # Safety
66    ///
67    /// - `cache_attributes` generics must be of the correct type.
68    /// - `texture_attributes` generics must be of the correct type.
69    /// - `cache_out` must be a valid pointer.
70    #[doc(alias = "CVMetalTextureCacheCreate")]
71    #[cfg(all(feature = "CVReturn", feature = "objc2", feature = "objc2-metal"))]
72    #[cfg(not(target_os = "watchos"))]
73    #[inline]
74    pub unsafe fn create(
75        allocator: Option<&CFAllocator>,
76        cache_attributes: Option<&CFDictionary>,
77        metal_device: &ProtocolObject<dyn MTLDevice>,
78        texture_attributes: Option<&CFDictionary>,
79        cache_out: NonNull<*mut CVMetalTextureCache>,
80    ) -> CVReturn {
81        extern "C-unwind" {
82            fn CVMetalTextureCacheCreate(
83                allocator: Option<&CFAllocator>,
84                cache_attributes: Option<&CFDictionary>,
85                metal_device: &ProtocolObject<dyn MTLDevice>,
86                texture_attributes: Option<&CFDictionary>,
87                cache_out: NonNull<*mut CVMetalTextureCache>,
88            ) -> CVReturn;
89        }
90        unsafe {
91            CVMetalTextureCacheCreate(
92                allocator,
93                cache_attributes,
94                metal_device,
95                texture_attributes,
96                cache_out,
97            )
98        }
99    }
100
101    /// Creates a CVMetalTexture object from an existing CVImageBuffer
102    ///
103    /// Parameter `allocator`: The CFAllocatorRef to use for allocating the CVMetalTexture object.  May be NULL.
104    ///
105    /// Parameter `textureCache`: The texture cache object that will manage the texture.
106    ///
107    /// Parameter `sourceImage`: The CVImageBuffer that you want to create a CVMetalTexture from.
108    ///
109    /// Parameter `textureAttributes`: A CFDictionaryRef containing attributes to be used for creating the CVMetalTexture objects.  May be NULL.
110    ///
111    /// Parameter `pixelFormat`: Specifies the Metal pixel format.
112    ///
113    /// Parameter `width`: Specifies the width of the texture image.
114    ///
115    /// Parameter `height`: Specifies the height of the texture image.
116    ///
117    /// Parameter `planeIndex`: Specifies the plane of the CVImageBuffer to map bind.  Ignored for non-planar CVImageBuffers.
118    ///
119    /// Parameter `textureOut`: The newly created texture object will be placed here.
120    ///
121    /// Returns: Returns kCVReturnSuccess on success
122    ///
123    /// Creates or returns a cached CVMetalTexture texture object mapped to the CVImageBuffer and
124    /// associated params.  This creates a live binding between the CVImageBuffer and underlying
125    /// CVMetalTexture texture object.
126    ///
127    /// IMPORTANT NOTE: Clients should retain CVMetalTexture objects until they are done using the images in them.
128    /// Retaining a CVMetalTexture is your way to indicate that you're still using the image in the buffer, and that it should not be recycled yet.
129    ///
130    /// Note that CoreVideo does not explicitly declare any pixel format types to be Metal compatible.  The assumption
131    /// is that if the CVPixelBufferMetalCompatibilityKey has been specified, all buffers will be Metal compatible
132    /// (IOSurface backed), and thus it is the developer's responsibility to choose an appropriate Metal pixel format
133    /// for the CVPixelBuffers.
134    ///
135    /// Here are some example mappings:
136    ///
137    /// Mapping a BGRA buffer:
138    /// CVMetalTextureCacheCreateTextureFromImage(kCFAllocatorDefault, textureCache, pixelBuffer, NULL, MTLPixelFormatBGRA8Unorm, width, height, 0,
139    /// &outTexture
140    /// );
141    ///
142    /// Mapping the luma plane of a 420v buffer:
143    /// CVMetalTextureCacheCreateTextureFromImage(kCFAllocatorDefault, textureCache, pixelBuffer, NULL, MTLPixelFormatR8Unorm, width, height, 0,
144    /// &outTexture
145    /// );
146    ///
147    /// Mapping the chroma plane of a 420v buffer as a source texture:
148    /// CVMetalTextureCacheCreateTextureFromImage(kCFAllocatorDefault, textureCache, pixelBuffer, NULL, MTLPixelFormatRG8Unorm width/2, height/2, 1,
149    /// &outTexture
150    /// );
151    ///
152    /// Mapping a yuvs buffer as a source texture (note: yuvs/f and 2vuy are unpacked and resampled -- not colorspace converted)
153    /// CVMetalTextureCacheCreateTextureFromImage(kCFAllocatorDefault, textureCache, pixelBuffer, NULL, MTLPixelFormatGBGR422, width, height, 1,
154    /// &outTexture
155    /// );
156    ///
157    /// # Safety
158    ///
159    /// - `texture_attributes` generics must be of the correct type.
160    /// - `texture_out` must be a valid pointer.
161    #[doc(alias = "CVMetalTextureCacheCreateTextureFromImage")]
162    #[cfg(all(
163        feature = "CVBuffer",
164        feature = "CVImageBuffer",
165        feature = "CVMetalTexture",
166        feature = "CVReturn",
167        feature = "objc2-metal"
168    ))]
169    #[cfg(not(target_os = "watchos"))]
170    #[inline]
171    pub unsafe fn create_texture_from_image(
172        allocator: Option<&CFAllocator>,
173        texture_cache: &CVMetalTextureCache,
174        source_image: &CVImageBuffer,
175        texture_attributes: Option<&CFDictionary>,
176        pixel_format: MTLPixelFormat,
177        width: usize,
178        height: usize,
179        plane_index: usize,
180        texture_out: NonNull<*mut CVMetalTexture>,
181    ) -> CVReturn {
182        extern "C-unwind" {
183            fn CVMetalTextureCacheCreateTextureFromImage(
184                allocator: Option<&CFAllocator>,
185                texture_cache: &CVMetalTextureCache,
186                source_image: &CVImageBuffer,
187                texture_attributes: Option<&CFDictionary>,
188                pixel_format: MTLPixelFormat,
189                width: usize,
190                height: usize,
191                plane_index: usize,
192                texture_out: NonNull<*mut CVMetalTexture>,
193            ) -> CVReturn;
194        }
195        unsafe {
196            CVMetalTextureCacheCreateTextureFromImage(
197                allocator,
198                texture_cache,
199                source_image,
200                texture_attributes,
201                pixel_format,
202                width,
203                height,
204                plane_index,
205                texture_out,
206            )
207        }
208    }
209
210    /// Performs internal housekeeping/recycling operations
211    ///
212    /// This call must be made periodically to give the texture cache a chance to do internal housekeeping operations.
213    ///
214    /// Parameter `textureCache`: The texture cache object to flush
215    ///
216    /// Parameter `options`: Currently unused, set to 0.
217    #[doc(alias = "CVMetalTextureCacheFlush")]
218    #[cfg(feature = "CVBase")]
219    #[inline]
220    pub fn flush(&self, options: CVOptionFlags) {
221        extern "C-unwind" {
222            fn CVMetalTextureCacheFlush(
223                texture_cache: &CVMetalTextureCache,
224                options: CVOptionFlags,
225            );
226        }
227        unsafe { CVMetalTextureCacheFlush(self, options) }
228    }
229}
230
231extern "C-unwind" {
232    #[cfg(all(feature = "CVReturn", feature = "objc2", feature = "objc2-metal"))]
233    #[cfg(not(target_os = "watchos"))]
234    #[deprecated = "renamed to `CVMetalTextureCache::create`"]
235    pub fn CVMetalTextureCacheCreate(
236        allocator: Option<&CFAllocator>,
237        cache_attributes: Option<&CFDictionary>,
238        metal_device: &ProtocolObject<dyn MTLDevice>,
239        texture_attributes: Option<&CFDictionary>,
240        cache_out: NonNull<*mut CVMetalTextureCache>,
241    ) -> CVReturn;
242}
243
244extern "C-unwind" {
245    #[cfg(all(
246        feature = "CVBuffer",
247        feature = "CVImageBuffer",
248        feature = "CVMetalTexture",
249        feature = "CVReturn",
250        feature = "objc2-metal"
251    ))]
252    #[cfg(not(target_os = "watchos"))]
253    #[deprecated = "renamed to `CVMetalTextureCache::create_texture_from_image`"]
254    pub fn CVMetalTextureCacheCreateTextureFromImage(
255        allocator: Option<&CFAllocator>,
256        texture_cache: &CVMetalTextureCache,
257        source_image: &CVImageBuffer,
258        texture_attributes: Option<&CFDictionary>,
259        pixel_format: MTLPixelFormat,
260        width: usize,
261        height: usize,
262        plane_index: usize,
263        texture_out: NonNull<*mut CVMetalTexture>,
264    ) -> CVReturn;
265}
266
267#[cfg(feature = "CVBase")]
268#[deprecated = "renamed to `CVMetalTextureCache::flush`"]
269#[inline]
270pub extern "C-unwind" fn CVMetalTextureCacheFlush(
271    texture_cache: &CVMetalTextureCache,
272    options: CVOptionFlags,
273) {
274    extern "C-unwind" {
275        fn CVMetalTextureCacheFlush(texture_cache: &CVMetalTextureCache, options: CVOptionFlags);
276    }
277    unsafe { CVMetalTextureCacheFlush(texture_cache, options) }
278}