use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use objc2_core_foundation::*;
#[cfg(feature = "objc2-metal")]
#[cfg(not(target_os = "watchos"))]
use objc2_metal::*;
use crate::*;
extern "C" {
pub static kCVMetalBufferCacheMaximumBufferAgeKey: &'static CFString;
}
#[doc(alias = "CVMetalBufferCacheRef")]
#[repr(C)]
pub struct CVMetalBufferCache {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CVMetalBufferCache {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CVMetalBufferCache"> for CVMetalBufferCache {}
);
unsafe impl ConcreteType for CVMetalBufferCache {
#[doc(alias = "CVMetalBufferCacheGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CVMetalBufferCacheGetTypeID() -> CFTypeID;
}
unsafe { CVMetalBufferCacheGetTypeID() }
}
}
impl CVMetalBufferCache {
#[doc(alias = "CVMetalBufferCacheCreate")]
#[cfg(all(feature = "CVReturn", feature = "objc2", feature = "objc2-metal"))]
#[cfg(not(target_os = "watchos"))]
#[inline]
pub unsafe fn create(
allocator: Option<&CFAllocator>,
cache_attributes: Option<&CFDictionary>,
metal_device: &ProtocolObject<dyn MTLDevice>,
cache_out: NonNull<*mut CVMetalBufferCache>,
) -> CVReturn {
extern "C-unwind" {
fn CVMetalBufferCacheCreate(
allocator: Option<&CFAllocator>,
cache_attributes: Option<&CFDictionary>,
metal_device: &ProtocolObject<dyn MTLDevice>,
cache_out: NonNull<*mut CVMetalBufferCache>,
) -> CVReturn;
}
unsafe { CVMetalBufferCacheCreate(allocator, cache_attributes, metal_device, cache_out) }
}
#[doc(alias = "CVMetalBufferCacheCreateBufferFromImage")]
#[cfg(all(
feature = "CVBuffer",
feature = "CVImageBuffer",
feature = "CVMetalBuffer",
feature = "CVReturn"
))]
#[inline]
pub unsafe fn create_buffer_from_image(
allocator: Option<&CFAllocator>,
buffer_cache: &CVMetalBufferCache,
image_buffer: &CVImageBuffer,
buffer_out: NonNull<*mut CVMetalBuffer>,
) -> CVReturn {
extern "C-unwind" {
fn CVMetalBufferCacheCreateBufferFromImage(
allocator: Option<&CFAllocator>,
buffer_cache: &CVMetalBufferCache,
image_buffer: &CVImageBuffer,
buffer_out: NonNull<*mut CVMetalBuffer>,
) -> CVReturn;
}
unsafe {
CVMetalBufferCacheCreateBufferFromImage(
allocator,
buffer_cache,
image_buffer,
buffer_out,
)
}
}
#[doc(alias = "CVMetalBufferCacheFlush")]
#[cfg(feature = "CVBase")]
#[inline]
pub fn flush(&self, options: CVOptionFlags) {
extern "C-unwind" {
fn CVMetalBufferCacheFlush(buffer_cache: &CVMetalBufferCache, options: CVOptionFlags);
}
unsafe { CVMetalBufferCacheFlush(self, options) }
}
}
extern "C-unwind" {
#[cfg(all(feature = "CVReturn", feature = "objc2", feature = "objc2-metal"))]
#[cfg(not(target_os = "watchos"))]
#[deprecated = "renamed to `CVMetalBufferCache::create`"]
pub fn CVMetalBufferCacheCreate(
allocator: Option<&CFAllocator>,
cache_attributes: Option<&CFDictionary>,
metal_device: &ProtocolObject<dyn MTLDevice>,
cache_out: NonNull<*mut CVMetalBufferCache>,
) -> CVReturn;
}
extern "C-unwind" {
#[cfg(all(
feature = "CVBuffer",
feature = "CVImageBuffer",
feature = "CVMetalBuffer",
feature = "CVReturn"
))]
#[deprecated = "renamed to `CVMetalBufferCache::create_buffer_from_image`"]
pub fn CVMetalBufferCacheCreateBufferFromImage(
allocator: Option<&CFAllocator>,
buffer_cache: &CVMetalBufferCache,
image_buffer: &CVImageBuffer,
buffer_out: NonNull<*mut CVMetalBuffer>,
) -> CVReturn;
}
#[cfg(feature = "CVBase")]
#[deprecated = "renamed to `CVMetalBufferCache::flush`"]
#[inline]
pub extern "C-unwind" fn CVMetalBufferCacheFlush(
buffer_cache: &CVMetalBufferCache,
options: CVOptionFlags,
) {
extern "C-unwind" {
fn CVMetalBufferCacheFlush(buffer_cache: &CVMetalBufferCache, options: CVOptionFlags);
}
unsafe { CVMetalBufferCacheFlush(buffer_cache, options) }
}