objc2_core_graphics/generated/
CGFunction.rs1use 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
11use crate::*;
12
13#[doc(alias = "CGFunctionRef")]
15#[repr(C)]
16pub struct CGFunction {
17 inner: [u8; 0],
18 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
19}
20
21cf_type!(
22 unsafe impl CGFunction {}
23);
24#[cfg(feature = "objc2")]
25cf_objc2_type!(
26 unsafe impl RefEncode<"CGFunction"> for CGFunction {}
27);
28
29pub type CGFunctionEvaluateCallback =
31 Option<unsafe extern "C-unwind" fn(*mut c_void, NonNull<CGFloat>, NonNull<CGFloat>)>;
32
33pub type CGFunctionReleaseInfoCallback = Option<unsafe extern "C-unwind" fn(*mut c_void)>;
35
36#[repr(C)]
38#[allow(unpredictable_function_pointer_comparisons)]
39#[derive(Clone, Copy, Debug, PartialEq)]
40pub struct CGFunctionCallbacks {
41 pub version: c_uint,
42 pub evaluate: CGFunctionEvaluateCallback,
43 pub releaseInfo: CGFunctionReleaseInfoCallback,
44}
45
46#[cfg(feature = "objc2")]
47unsafe impl Encode for CGFunctionCallbacks {
48 const ENCODING: Encoding = Encoding::Struct(
49 "CGFunctionCallbacks",
50 &[
51 <c_uint>::ENCODING,
52 <CGFunctionEvaluateCallback>::ENCODING,
53 <CGFunctionReleaseInfoCallback>::ENCODING,
54 ],
55 );
56}
57
58#[cfg(feature = "objc2")]
59unsafe impl RefEncode for CGFunctionCallbacks {
60 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
61}
62
63unsafe impl ConcreteType for CGFunction {
64 #[doc(alias = "CGFunctionGetTypeID")]
65 #[inline]
66 fn type_id() -> CFTypeID {
67 extern "C-unwind" {
68 fn CGFunctionGetTypeID() -> CFTypeID;
69 }
70 unsafe { CGFunctionGetTypeID() }
71 }
72}
73
74impl CGFunction {
75 #[doc(alias = "CGFunctionCreate")]
82 #[inline]
83 pub unsafe fn new(
84 info: *mut c_void,
85 domain_dimension: usize,
86 domain: *const CGFloat,
87 range_dimension: usize,
88 range: *const CGFloat,
89 callbacks: *const CGFunctionCallbacks,
90 ) -> Option<CFRetained<CGFunction>> {
91 extern "C-unwind" {
92 fn CGFunctionCreate(
93 info: *mut c_void,
94 domain_dimension: usize,
95 domain: *const CGFloat,
96 range_dimension: usize,
97 range: *const CGFloat,
98 callbacks: *const CGFunctionCallbacks,
99 ) -> Option<NonNull<CGFunction>>;
100 }
101 let ret = unsafe {
102 CGFunctionCreate(
103 info,
104 domain_dimension,
105 domain,
106 range_dimension,
107 range,
108 callbacks,
109 )
110 };
111 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
112 }
113}
114
115#[deprecated = "renamed to `CGFunction::new`"]
116#[inline]
117pub unsafe extern "C-unwind" fn CGFunctionCreate(
118 info: *mut c_void,
119 domain_dimension: usize,
120 domain: *const CGFloat,
121 range_dimension: usize,
122 range: *const CGFloat,
123 callbacks: *const CGFunctionCallbacks,
124) -> Option<CFRetained<CGFunction>> {
125 extern "C-unwind" {
126 fn CGFunctionCreate(
127 info: *mut c_void,
128 domain_dimension: usize,
129 domain: *const CGFloat,
130 range_dimension: usize,
131 range: *const CGFloat,
132 callbacks: *const CGFunctionCallbacks,
133 ) -> Option<NonNull<CGFunction>>;
134 }
135 let ret = unsafe {
136 CGFunctionCreate(
137 info,
138 domain_dimension,
139 domain,
140 range_dimension,
141 range,
142 callbacks,
143 )
144 };
145 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
146}