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#[repr(C)]
25pub struct CVMetalTextureCache {
26 inner: [u8; 0],
27 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
28}
29
30cf_type!(
31 #[encoding_name = "__CVMetalTextureCache"]
32 unsafe impl CVMetalTextureCache {}
33);
34
35unsafe impl ConcreteType for CVMetalTextureCache {
36 #[doc(alias = "CVMetalTextureCacheGetTypeID")]
37 #[inline]
38 fn type_id() -> CFTypeID {
39 extern "C-unwind" {
40 fn CVMetalTextureCacheGetTypeID() -> CFTypeID;
41 }
42 unsafe { CVMetalTextureCacheGetTypeID() }
43 }
44}
45
46extern "C-unwind" {
47 /// Creates a new Texture Cache.
48 ///
49 /// Parameter `allocator`: The CFAllocatorRef to use for allocating the cache. May be NULL.
50 ///
51 /// Parameter `cacheAttributes`: A CFDictionaryRef containing the attributes of the cache itself. May be NULL.
52 ///
53 /// Parameter `metalDevice`: The Metal device for which the texture objects will be created.
54 ///
55 /// Parameter `textureAttributes`: A CFDictionaryRef containing the attributes to be used for creating the CVMetalTexture objects. May be NULL.
56 ///
57 /// Parameter `cacheOut`: The newly created texture cache will be placed here
58 ///
59 /// Returns: Returns kCVReturnSuccess on success
60 #[cfg(all(feature = "CVReturn", feature = "objc2", feature = "objc2-metal"))]
61 #[cfg(not(target_os = "watchos"))]
62 pub fn CVMetalTextureCacheCreate(
63 allocator: Option<&CFAllocator>,
64 cache_attributes: Option<&CFDictionary>,
65 metal_device: &ProtocolObject<dyn MTLDevice>,
66 texture_attributes: Option<&CFDictionary>,
67 cache_out: NonNull<*mut CVMetalTextureCache>,
68 ) -> CVReturn;
69}
70
71extern "C-unwind" {
72 /// Creates a CVMetalTexture object from an existing CVImageBuffer
73 ///
74 /// Parameter `allocator`: The CFAllocatorRef to use for allocating the CVMetalTexture object. May be NULL.
75 ///
76 /// Parameter `textureCache`: The texture cache object that will manage the texture.
77 ///
78 /// Parameter `sourceImage`: The CVImageBuffer that you want to create a CVMetalTexture from.
79 ///
80 /// Parameter `textureAttributes`: A CFDictionaryRef containing attributes to be used for creating the CVMetalTexture objects. May be NULL.
81 ///
82 /// Parameter `pixelFormat`: Specifies the Metal pixel format.
83 ///
84 /// Parameter `width`: Specifies the width of the texture image.
85 ///
86 /// Parameter `height`: Specifies the height of the texture image.
87 ///
88 /// Parameter `planeIndex`: Specifies the plane of the CVImageBuffer to map bind. Ignored for non-planar CVImageBuffers.
89 ///
90 /// Parameter `textureOut`: The newly created texture object will be placed here.
91 ///
92 /// Returns: Returns kCVReturnSuccess on success
93 ///
94 /// Creates or returns a cached CVMetalTexture texture object mapped to the CVImageBuffer and
95 /// associated params. This creates a live binding between the CVImageBuffer and underlying
96 /// CVMetalTexture texture object.
97 ///
98 /// IMPORTANT NOTE: Clients should retain CVMetalTexture objects until they are done using the images in them.
99 /// 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.
100 ///
101 /// Note that CoreVideo does not explicitly declare any pixel format types to be Metal compatible. The assumption
102 /// is that if the CVPixelBufferMetalCompatibilityKey has been specified, all buffers will be Metal compatible
103 /// (IOSurface backed), and thus it is the developer's responsibility to choose an appropriate Metal pixel format
104 /// for the CVPixelBuffers.
105 ///
106 /// Here are some example mappings:
107 ///
108 /// Mapping a BGRA buffer:
109 /// CVMetalTextureCacheCreateTextureFromImage(kCFAllocatorDefault, textureCache, pixelBuffer, NULL, MTLPixelFormatBGRA8Unorm, width, height, 0,
110 /// &outTexture
111 /// );
112 ///
113 /// Mapping the luma plane of a 420v buffer:
114 /// CVMetalTextureCacheCreateTextureFromImage(kCFAllocatorDefault, textureCache, pixelBuffer, NULL, MTLPixelFormatR8Unorm, width, height, 0,
115 /// &outTexture
116 /// );
117 ///
118 /// Mapping the chroma plane of a 420v buffer as a source texture:
119 /// CVMetalTextureCacheCreateTextureFromImage(kCFAllocatorDefault, textureCache, pixelBuffer, NULL, MTLPixelFormatRG8Unorm width/2, height/2, 1,
120 /// &outTexture
121 /// );
122 ///
123 /// Mapping a yuvs buffer as a source texture (note: yuvs/f and 2vuy are unpacked and resampled -- not colorspace converted)
124 /// CVMetalTextureCacheCreateTextureFromImage(kCFAllocatorDefault, textureCache, pixelBuffer, NULL, MTLPixelFormatGBGR422, width, height, 1,
125 /// &outTexture
126 /// );
127 #[cfg(all(
128 feature = "CVBuffer",
129 feature = "CVImageBuffer",
130 feature = "CVMetalTexture",
131 feature = "CVReturn",
132 feature = "objc2-metal"
133 ))]
134 #[cfg(not(target_os = "watchos"))]
135 pub fn CVMetalTextureCacheCreateTextureFromImage(
136 allocator: Option<&CFAllocator>,
137 texture_cache: &CVMetalTextureCache,
138 source_image: &CVImageBuffer,
139 texture_attributes: Option<&CFDictionary>,
140 pixel_format: MTLPixelFormat,
141 width: usize,
142 height: usize,
143 plane_index: usize,
144 texture_out: NonNull<*mut CVMetalTexture>,
145 ) -> CVReturn;
146}
147
148extern "C-unwind" {
149 /// Performs internal housekeeping/recycling operations
150 ///
151 /// This call must be made periodically to give the texture cache a chance to do internal housekeeping operations.
152 ///
153 /// Parameter `textureCache`: The texture cache object to flush
154 ///
155 /// Parameter `options`: Currently unused, set to 0.
156 #[cfg(feature = "CVBase")]
157 pub fn CVMetalTextureCacheFlush(texture_cache: &CVMetalTextureCache, options: CVOptionFlags);
158}