//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
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::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgrenderingbufferprovider?language=objc)
#[doc(alias = "CGRenderingBufferProviderRef")]
#[repr(C)]
pub struct CGRenderingBufferProvider {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

cf_type!(
    unsafe impl CGRenderingBufferProvider {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
    unsafe impl RefEncode<"CGRenderingBufferProvider"> for CGRenderingBufferProvider {}
);

impl CGRenderingBufferProvider {
    /// # Safety
    ///
    /// - `info` must be a valid pointer or null.
    /// - `lock_pointer` block's return must be a valid pointer or null.
    #[doc(alias = "CGRenderingBufferProviderCreate")]
    #[cfg(feature = "block2")]
    #[inline]
    pub unsafe fn new(
        info: *mut c_void,
        size: usize,
        lock_pointer: &block2::DynBlock<dyn Fn(*mut c_void) -> *mut c_void>,
        unlock_pointer: Option<&block2::DynBlock<dyn Fn(*mut c_void, NonNull<c_void>)>>,
        release_info: Option<&block2::DynBlock<dyn Fn(*mut c_void)>>,
    ) -> Option<CFRetained<CGRenderingBufferProvider>> {
        extern "C-unwind" {
            fn CGRenderingBufferProviderCreate(
                info: *mut c_void,
                size: usize,
                lock_pointer: &block2::DynBlock<dyn Fn(*mut c_void) -> *mut c_void>,
                unlock_pointer: Option<&block2::DynBlock<dyn Fn(*mut c_void, NonNull<c_void>)>>,
                release_info: Option<&block2::DynBlock<dyn Fn(*mut c_void)>>,
            ) -> Option<NonNull<CGRenderingBufferProvider>>;
        }
        let ret = unsafe {
            CGRenderingBufferProviderCreate(info, size, lock_pointer, unlock_pointer, release_info)
        };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    #[doc(alias = "CGRenderingBufferProviderCreateWithCFData")]
    #[inline]
    pub fn with_cf_data(data: &CFMutableData) -> Option<CFRetained<CGRenderingBufferProvider>> {
        extern "C-unwind" {
            fn CGRenderingBufferProviderCreateWithCFData(
                data: &CFMutableData,
            ) -> Option<NonNull<CGRenderingBufferProvider>>;
        }
        let ret = unsafe { CGRenderingBufferProviderCreateWithCFData(data) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    #[doc(alias = "CGRenderingBufferProviderGetSize")]
    #[inline]
    pub fn size(&self) -> usize {
        extern "C-unwind" {
            fn CGRenderingBufferProviderGetSize(provider: &CGRenderingBufferProvider) -> usize;
        }
        unsafe { CGRenderingBufferProviderGetSize(self) }
    }
}

#[inline]
pub extern "C-unwind" fn CGRenderingBufferLockBytePtr(
    provider: &CGRenderingBufferProvider,
) -> *mut c_void {
    extern "C-unwind" {
        fn CGRenderingBufferLockBytePtr(provider: &CGRenderingBufferProvider) -> *mut c_void;
    }
    unsafe { CGRenderingBufferLockBytePtr(provider) }
}

#[inline]
pub extern "C-unwind" fn CGRenderingBufferUnlockBytePtr(provider: &CGRenderingBufferProvider) {
    extern "C-unwind" {
        fn CGRenderingBufferUnlockBytePtr(provider: &CGRenderingBufferProvider);
    }
    unsafe { CGRenderingBufferUnlockBytePtr(provider) }
}

unsafe impl ConcreteType for CGRenderingBufferProvider {
    #[doc(alias = "CGRenderingBufferProviderGetTypeID")]
    #[inline]
    fn type_id() -> CFTypeID {
        extern "C-unwind" {
            fn CGRenderingBufferProviderGetTypeID() -> CFTypeID;
        }
        unsafe { CGRenderingBufferProviderGetTypeID() }
    }
}

#[cfg(feature = "block2")]
#[deprecated = "renamed to `CGRenderingBufferProvider::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CGRenderingBufferProviderCreate(
    info: *mut c_void,
    size: usize,
    lock_pointer: &block2::DynBlock<dyn Fn(*mut c_void) -> *mut c_void>,
    unlock_pointer: Option<&block2::DynBlock<dyn Fn(*mut c_void, NonNull<c_void>)>>,
    release_info: Option<&block2::DynBlock<dyn Fn(*mut c_void)>>,
) -> Option<CFRetained<CGRenderingBufferProvider>> {
    extern "C-unwind" {
        fn CGRenderingBufferProviderCreate(
            info: *mut c_void,
            size: usize,
            lock_pointer: &block2::DynBlock<dyn Fn(*mut c_void) -> *mut c_void>,
            unlock_pointer: Option<&block2::DynBlock<dyn Fn(*mut c_void, NonNull<c_void>)>>,
            release_info: Option<&block2::DynBlock<dyn Fn(*mut c_void)>>,
        ) -> Option<NonNull<CGRenderingBufferProvider>>;
    }
    let ret = unsafe {
        CGRenderingBufferProviderCreate(info, size, lock_pointer, unlock_pointer, release_info)
    };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[deprecated = "renamed to `CGRenderingBufferProvider::with_cf_data`"]
#[inline]
pub extern "C-unwind" fn CGRenderingBufferProviderCreateWithCFData(
    data: &CFMutableData,
) -> Option<CFRetained<CGRenderingBufferProvider>> {
    extern "C-unwind" {
        fn CGRenderingBufferProviderCreateWithCFData(
            data: &CFMutableData,
        ) -> Option<NonNull<CGRenderingBufferProvider>>;
    }
    let ret = unsafe { CGRenderingBufferProviderCreateWithCFData(data) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[deprecated = "renamed to `CGRenderingBufferProvider::size`"]
#[inline]
pub extern "C-unwind" fn CGRenderingBufferProviderGetSize(
    provider: &CGRenderingBufferProvider,
) -> usize {
    extern "C-unwind" {
        fn CGRenderingBufferProviderGetSize(provider: &CGRenderingBufferProvider) -> usize;
    }
    unsafe { CGRenderingBufferProviderGetSize(provider) }
}
