objc2_compositor_services/generated/
drawable.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;
7use objc2::__framework_prelude::*;
8#[cfg(feature = "objc2-metal")]
9use objc2_metal::*;
10
11use crate::*;
12
13/// The state of ownership for the drawable.
14///
15/// Use these constants to determine whether the drawable is ready
16/// for you to use. When the drawable is in the ``cp_drawable_state_rendering``
17/// state, you can begin drawing. Other states indicate the
18/// drawable is either busy or not assigned to a frame.
19///
20/// See also [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_drawable_state?language=objc)
21// NS_ENUM
22#[repr(transparent)]
23#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
24pub struct cp_drawable_state(pub u32);
25impl cp_drawable_state {
26    /// A drawable that is not in use and ready for assignment to a frame.
27    #[doc(alias = "cp_drawable_state_available")]
28    pub const available: Self = Self(0);
29    /// A drawable that is assigned to a frame and ready to accept
30    /// your drawing commands.
31    #[doc(alias = "cp_drawable_state_rendering")]
32    pub const rendering: Self = Self(1);
33    /// A drawable that the compositor is currently displaying onscreen.
34    #[doc(alias = "cp_drawable_state_presenting")]
35    pub const presenting: Self = Self(2);
36}
37
38unsafe impl Encode for cp_drawable_state {
39    const ENCODING: Encoding = u32::ENCODING;
40}
41
42unsafe impl RefEncode for cp_drawable_state {
43    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
44}
45
46/// [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_drawable?language=objc)
47#[repr(C)]
48#[derive(Debug)]
49pub struct cp_drawable {
50    inner: [u8; 0],
51    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
52}
53
54unsafe impl RefEncode for cp_drawable {
55    const ENCODING_REF: Encoding = Encoding::Pointer(&Encoding::Struct("cp_drawable", &[]));
56}
57
58/// An opaque type that contains the textures and other information
59/// you need to set up your render pipeline.
60///
61/// Use the drawable type to retrieve the textures for your render pipelines,
62/// and use the drawable’s views to get details about how to render to those
63/// textures. Get the drawable for a frame using the ``cp_frame_query_drawable``
64/// function. The layer manages a limited number of reusable drawable types
65/// and recycles them after each use. Draw only one frame at a time to ensure
66/// each new frame’s drawable type is ready in time.
67///
68/// See also [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_drawable_t?language=objc)
69pub type cp_drawable_t = *mut cp_drawable;
70
71impl cp_drawable {
72    /// Returns the number of color and depth textures available in the drawable.
73    ///
74    /// - Parameters:
75    /// - drawable: The drawable for a frame.
76    /// - Returns: The number of textures available for drawing. For example, a return
77    /// value of `2` indicates there are two color textures and two depth
78    /// textures available.
79    ///
80    /// Use the returned value as the maximum number of textures to retrieve
81    /// from the ``cp_drawable_get_color_texture`` or ``cp_drawable_get_depth_texture``
82    /// functions.
83    #[doc(alias = "cp_drawable_get_texture_count")]
84    #[inline]
85    pub unsafe fn texture_count(drawable: cp_drawable_t) -> usize {
86        extern "C-unwind" {
87            fn cp_drawable_get_texture_count(drawable: cp_drawable_t) -> usize;
88        }
89        unsafe { cp_drawable_get_texture_count(drawable) }
90    }
91
92    /// Returns the depth texture at the specified index in the drawable.
93    ///
94    /// - Parameters:
95    /// - drawable: The drawable for a frame.
96    /// - index: The index of the depth texture you want. The index must
97    /// be greater than or equal to `0` and less than the value that
98    /// ``cp_drawable_get_texture_count`` returns.
99    /// - Returns: The Metal depth texture at the specified index.
100    ///
101    /// Use the returned texture in your render pipeline as the depth texture
102    /// for your content. The layer’s texture topology determines the layout and
103    /// content for each texture. The drawable’s views contain information
104    /// about how those views map to the textures.
105    #[doc(alias = "cp_drawable_get_depth_texture")]
106    #[cfg(feature = "objc2-metal")]
107    #[inline]
108    pub unsafe fn depth_texture(
109        drawable: cp_drawable_t,
110        index: usize,
111    ) -> Retained<ProtocolObject<dyn MTLTexture>> {
112        extern "C-unwind" {
113            fn cp_drawable_get_depth_texture(
114                drawable: cp_drawable_t,
115                index: usize,
116            ) -> *mut ProtocolObject<dyn MTLTexture>;
117        }
118        let ret = unsafe { cp_drawable_get_depth_texture(drawable, index) };
119        unsafe { Retained::retain_autoreleased(ret) }
120            .expect("function was marked as returning non-null, but actually returned NULL")
121    }
122
123    /// Returns the color texture at the specified index in the drawable.
124    ///
125    /// - Parameters:
126    /// - drawable: The drawable for a frame.
127    /// - index: The index of the color texture you want. The index must
128    /// be greater than or equal to `0` and less than the value that
129    /// ``cp_drawable_get_texture_count`` returns.
130    /// - Returns: The Metal color texture at the specified index.
131    ///
132    /// Use the returned texture in your render pipeline to store the pixels
133    /// you want to appear onscreen. The layer’s texture topology determines
134    /// the layout and content for each texture. The drawable’s views contain
135    /// information about how those views map to the textures.
136    #[doc(alias = "cp_drawable_get_color_texture")]
137    #[cfg(feature = "objc2-metal")]
138    #[inline]
139    pub unsafe fn color_texture(
140        drawable: cp_drawable_t,
141        index: usize,
142    ) -> Retained<ProtocolObject<dyn MTLTexture>> {
143        extern "C-unwind" {
144            fn cp_drawable_get_color_texture(
145                drawable: cp_drawable_t,
146                index: usize,
147            ) -> *mut ProtocolObject<dyn MTLTexture>;
148        }
149        let ret = unsafe { cp_drawable_get_color_texture(drawable, index) };
150        unsafe { Retained::retain_autoreleased(ret) }
151            .expect("function was marked as returning non-null, but actually returned NULL")
152    }
153
154    /// Returns the number of rasterization rate maps associated with the
155    /// drawable.
156    ///
157    /// - Parameters:
158    /// - drawable: The drawable for a frame.
159    /// - Returns: The number of rasterization rate maps available for drawing.
160    ///
161    /// Use the returned value as the maximum number of rate maps to retrieve
162    /// from the ``cp_drawable_get_rasterization_rate_map`` function.
163    #[doc(alias = "cp_drawable_get_rasterization_rate_map_count")]
164    #[inline]
165    pub unsafe fn rasterization_rate_map_count(drawable: cp_drawable_t) -> usize {
166        extern "C-unwind" {
167            fn cp_drawable_get_rasterization_rate_map_count(drawable: cp_drawable_t) -> usize;
168        }
169        unsafe { cp_drawable_get_rasterization_rate_map_count(drawable) }
170    }
171
172    /// Returns the rasterization rate map at the specified index in the drawable.
173    ///
174    /// - Parameters:
175    /// - drawable: The drawable for a frame.
176    /// - index: The index of the rasterization rate map you want.
177    /// The index must be greater than or equal to `0` and less than the value
178    /// that ``cp_drawable_get_rasterization_rate_map_count`` returns.
179    /// - Returns: The rasterization rate map at the specified index.
180    ///
181    /// Apply the rasterization rate map to your render descriptor when you set
182    /// up your drawing environment. A rate map defines how the GPU scales
183    /// different parts of the texture to fill the screen. You use these rate
184    /// maps to save time and render less important parts of your scene at lower
185    /// resolutions. For example, when foveation is enabled, the drawable
186    /// includes a rasterization rate map to render the portions of the texture
187    /// in someone’s peripheral vision at a lower resolution.
188    #[doc(alias = "cp_drawable_get_rasterization_rate_map")]
189    #[cfg(feature = "objc2-metal")]
190    #[inline]
191    pub unsafe fn rasterization_rate_map(
192        drawable: cp_drawable_t,
193        index: usize,
194    ) -> Retained<ProtocolObject<dyn MTLRasterizationRateMap>> {
195        extern "C-unwind" {
196            fn cp_drawable_get_rasterization_rate_map(
197                drawable: cp_drawable_t,
198                index: usize,
199            ) -> *mut ProtocolObject<dyn MTLRasterizationRateMap>;
200        }
201        let ret = unsafe { cp_drawable_get_rasterization_rate_map(drawable, index) };
202        unsafe { Retained::retain_autoreleased(ret) }
203            .expect("function was marked as returning non-null, but actually returned NULL")
204    }
205
206    /// Returns the Y flipped rasterization rate map at the specified index in the drawable.
207    ///
208    /// - Parameters:
209    /// - drawable: The drawable for a frame.
210    /// - index: The index of the rasterization rate map you want.
211    /// The index must be greater than or equal to `0` and less than the value
212    /// that ``cp_drawable_get_rasterization_rate_map_count`` returns.
213    /// - Returns: The Y flipped rasterization rate map at the specified index.
214    ///
215    /// This function provides a Y flipped map that is generated form the ``cp_drawable_get_rasterization_rate_map``.
216    /// Flipped is defined as +Y = down for clip/normalized device coordinates (flipped from Metal).
217    /// If projection matrix is needed, use ``cp_drawable_compute_projection``
218    /// with a +Y = down axes convention to generate the correct matrix.
219    ///
220    /// Can only be used for intermediary render passes, the final render pass of the
221    /// drawable it cannot be flipped and must use Metal convention of +Y = up.
222    ///
223    /// Generating a flipped rasterization rate map will bring additional computational
224    /// cost to your render loop.
225    ///
226    /// In order to generate Y flipped rasterization rate maps in your rendering session,
227    /// update the ``cp_layer_renderer_configuration_t`` using the function
228    /// ``cp_layer_renderer_configuration_set_generate_flipped_rasterization_rate_maps``.
229    #[doc(alias = "cp_drawable_get_flipped_rasterization_rate_map")]
230    #[cfg(feature = "objc2-metal")]
231    #[inline]
232    pub unsafe fn flipped_rasterization_rate_map(
233        drawable: cp_drawable_t,
234        index: usize,
235    ) -> Retained<ProtocolObject<dyn MTLRasterizationRateMap>> {
236        extern "C-unwind" {
237            fn cp_drawable_get_flipped_rasterization_rate_map(
238                drawable: cp_drawable_t,
239                index: usize,
240            ) -> *mut ProtocolObject<dyn MTLRasterizationRateMap>;
241        }
242        let ret = unsafe { cp_drawable_get_flipped_rasterization_rate_map(drawable, index) };
243        unsafe { Retained::retain_autoreleased(ret) }
244            .expect("function was marked as returning non-null, but actually returned NULL")
245    }
246
247    /// Returns the number of separate views to draw for the frame.
248    ///
249    /// - Parameters:
250    /// - drawable: The drawable for a frame.
251    /// - Returns: The number of separate views to draw.
252    ///
253    /// The number of views corresponds to the number of separate versions
254    /// of your scene you create for the frame. For a device with stereoscopic
255    /// video, you render two views — one for each eye. The actual number of
256    /// views can vary based on the drawing environment or your app’s
257    /// configuration. For example, you typically render only one view in
258    /// Simulator.
259    ///
260    /// Fetch the actual views using the ``cp_drawable_get_view`` function.
261    #[doc(alias = "cp_drawable_get_view_count")]
262    #[inline]
263    pub unsafe fn view_count(drawable: cp_drawable_t) -> usize {
264        extern "C-unwind" {
265            fn cp_drawable_get_view_count(drawable: cp_drawable_t) -> usize;
266        }
267        unsafe { cp_drawable_get_view_count(drawable) }
268    }
269
270    /// Returns the specified view from the drawable.
271    ///
272    /// - Parameters:
273    /// - drawable: The drawable for a frame.
274    /// - index: The index of the view you want. The index must be
275    /// greater than or equal to 0 and less than the value that
276    /// ``cp_drawable_get_view_count`` returns.
277    /// - Returns: The view at the specified index.
278    ///
279    /// Each view contains information you need to render into the drawable’s
280    /// textures.
281    #[doc(alias = "cp_drawable_get_view")]
282    #[cfg(feature = "view")]
283    #[inline]
284    pub unsafe fn view(drawable: cp_drawable_t, index: usize) -> cp_view_t {
285        extern "C-unwind" {
286            fn cp_drawable_get_view(drawable: cp_drawable_t, index: usize) -> cp_view_t;
287        }
288        unsafe { cp_drawable_get_view(drawable, index) }
289    }
290
291    /// Encodes a notification event to the specified command buffer to present
292    /// the drawable’s content onscreen.
293    ///
294    /// - Parameters:
295    /// - drawable: The drawable for a frame.
296    /// - command_buffer: The command buffer you used to encode your
297    /// frame’s content. If the command buffer is already committed,
298    /// this function aborts your app with an error.
299    ///
300    /// Call this function as the last step before committing the specified
301    /// command buffer. Specifically, call it after you finish encoding all
302    /// the work required to render the frame, and immediately before you
303    /// call the command buffer’s
304    /// <doc
305    /// ://com.apple.documentation/documentation/metal/mtlcommandbuffer/1443003-commit>
306    /// method. The function adds a presentation event to the buffer that
307    /// causes the compositor to display your frame.
308    #[doc(alias = "cp_drawable_encode_present")]
309    #[cfg(feature = "objc2-metal")]
310    #[inline]
311    pub unsafe fn encode_present(
312        drawable: cp_drawable_t,
313        command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
314    ) {
315        extern "C-unwind" {
316            fn cp_drawable_encode_present(
317                drawable: cp_drawable_t,
318                command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
319            );
320        }
321        unsafe { cp_drawable_encode_present(drawable, command_buffer) }
322    }
323
324    /// Returns a value that indicates the current operational state
325    /// of the drawable type.
326    ///
327    /// - Parameters: The drawable to test.
328    /// - Returns: ``cp_drawable_state/cp_drawable_state_rendering`` if the
329    /// drawable type is ready for you to draw your content, or any other value if
330    /// the compositor currently owns the drawable.
331    ///
332    /// Compositor reuses the underlying data structures associated with
333    /// drawable types, and the state of the drawable indicates whether
334    /// it's ready for you to use. Perform your drawing operations only
335    /// when the drawable is in the ``cp_drawable_state/cp_drawable_state_rendering`` state.
336    #[doc(alias = "cp_drawable_get_state")]
337    #[inline]
338    pub unsafe fn state(drawable: cp_drawable_t) -> cp_drawable_state {
339        extern "C-unwind" {
340            fn cp_drawable_get_state(drawable: cp_drawable_t) -> cp_drawable_state;
341        }
342        unsafe { cp_drawable_get_state(drawable) }
343    }
344
345    /// Returns the index of the frame of content for you to produce.
346    ///
347    /// - Parameters:
348    /// - drawable: The drawable for a frame.
349    /// - Returns: The presentation index of the frame.
350    ///
351    /// When your compositor scene becomes visible, you start drawing
352    /// frames of content. The compositor assigns a sequential index to
353    /// each frame to indicate its position in the final output. You can
354    /// use these indexes to differentiate frames during drawing or predict
355    /// future frame indexes. For example, you might start playback of an
356    /// audio file when a specific frame appears onscreen.
357    #[doc(alias = "cp_drawable_get_presentation_frame_index")]
358    #[cfg(feature = "cp_types")]
359    #[inline]
360    pub unsafe fn presentation_frame_index(drawable: cp_drawable_t) -> cp_compositor_frame_index_t {
361        extern "C-unwind" {
362            fn cp_drawable_get_presentation_frame_index(
363                drawable: cp_drawable_t,
364            ) -> cp_compositor_frame_index_t;
365        }
366        unsafe { cp_drawable_get_presentation_frame_index(drawable) }
367    }
368
369    /// Returns the timing information for the frame of the specified drawable.
370    ///
371    /// - Parameters:
372    /// - drawable: The drawable for a frame.
373    /// - Returns: The timing information for the drawable’s associated frame.
374    ///
375    /// Pass the returned type to the ``cp_frame_timing_get_optimal_input_time``
376    /// function to determine when to start the encoding process for a frame.
377    /// Pass it to other functions to determine other time-related deadlines.
378    #[doc(alias = "cp_drawable_get_frame_timing")]
379    #[cfg(feature = "frame_timing")]
380    #[inline]
381    pub unsafe fn frame_timing(drawable: cp_drawable_t) -> cp_frame_timing_t {
382        extern "C-unwind" {
383            fn cp_drawable_get_frame_timing(drawable: cp_drawable_t) -> cp_frame_timing_t;
384        }
385        unsafe { cp_drawable_get_frame_timing(drawable) }
386    }
387}
388
389extern "C-unwind" {
390    #[deprecated = "renamed to `cp_drawable::texture_count`"]
391    pub fn cp_drawable_get_texture_count(drawable: cp_drawable_t) -> usize;
392}
393
394#[cfg(feature = "objc2-metal")]
395#[deprecated = "renamed to `cp_drawable::depth_texture`"]
396#[inline]
397pub unsafe extern "C-unwind" fn cp_drawable_get_depth_texture(
398    drawable: cp_drawable_t,
399    index: usize,
400) -> Retained<ProtocolObject<dyn MTLTexture>> {
401    extern "C-unwind" {
402        fn cp_drawable_get_depth_texture(
403            drawable: cp_drawable_t,
404            index: usize,
405        ) -> *mut ProtocolObject<dyn MTLTexture>;
406    }
407    let ret = unsafe { cp_drawable_get_depth_texture(drawable, index) };
408    unsafe { Retained::retain_autoreleased(ret) }
409        .expect("function was marked as returning non-null, but actually returned NULL")
410}
411
412#[cfg(feature = "objc2-metal")]
413#[deprecated = "renamed to `cp_drawable::color_texture`"]
414#[inline]
415pub unsafe extern "C-unwind" fn cp_drawable_get_color_texture(
416    drawable: cp_drawable_t,
417    index: usize,
418) -> Retained<ProtocolObject<dyn MTLTexture>> {
419    extern "C-unwind" {
420        fn cp_drawable_get_color_texture(
421            drawable: cp_drawable_t,
422            index: usize,
423        ) -> *mut ProtocolObject<dyn MTLTexture>;
424    }
425    let ret = unsafe { cp_drawable_get_color_texture(drawable, index) };
426    unsafe { Retained::retain_autoreleased(ret) }
427        .expect("function was marked as returning non-null, but actually returned NULL")
428}
429
430extern "C-unwind" {
431    #[deprecated = "renamed to `cp_drawable::rasterization_rate_map_count`"]
432    pub fn cp_drawable_get_rasterization_rate_map_count(drawable: cp_drawable_t) -> usize;
433}
434
435#[cfg(feature = "objc2-metal")]
436#[deprecated = "renamed to `cp_drawable::rasterization_rate_map`"]
437#[inline]
438pub unsafe extern "C-unwind" fn cp_drawable_get_rasterization_rate_map(
439    drawable: cp_drawable_t,
440    index: usize,
441) -> Retained<ProtocolObject<dyn MTLRasterizationRateMap>> {
442    extern "C-unwind" {
443        fn cp_drawable_get_rasterization_rate_map(
444            drawable: cp_drawable_t,
445            index: usize,
446        ) -> *mut ProtocolObject<dyn MTLRasterizationRateMap>;
447    }
448    let ret = unsafe { cp_drawable_get_rasterization_rate_map(drawable, index) };
449    unsafe { Retained::retain_autoreleased(ret) }
450        .expect("function was marked as returning non-null, but actually returned NULL")
451}
452
453#[cfg(feature = "objc2-metal")]
454#[deprecated = "renamed to `cp_drawable::flipped_rasterization_rate_map`"]
455#[inline]
456pub unsafe extern "C-unwind" fn cp_drawable_get_flipped_rasterization_rate_map(
457    drawable: cp_drawable_t,
458    index: usize,
459) -> Retained<ProtocolObject<dyn MTLRasterizationRateMap>> {
460    extern "C-unwind" {
461        fn cp_drawable_get_flipped_rasterization_rate_map(
462            drawable: cp_drawable_t,
463            index: usize,
464        ) -> *mut ProtocolObject<dyn MTLRasterizationRateMap>;
465    }
466    let ret = unsafe { cp_drawable_get_flipped_rasterization_rate_map(drawable, index) };
467    unsafe { Retained::retain_autoreleased(ret) }
468        .expect("function was marked as returning non-null, but actually returned NULL")
469}
470
471extern "C-unwind" {
472    #[deprecated = "renamed to `cp_drawable::view_count`"]
473    pub fn cp_drawable_get_view_count(drawable: cp_drawable_t) -> usize;
474}
475
476extern "C-unwind" {
477    #[cfg(feature = "view")]
478    #[deprecated = "renamed to `cp_drawable::view`"]
479    pub fn cp_drawable_get_view(drawable: cp_drawable_t, index: usize) -> cp_view_t;
480}
481
482extern "C-unwind" {
483    #[cfg(feature = "objc2-metal")]
484    #[deprecated = "renamed to `cp_drawable::encode_present`"]
485    pub fn cp_drawable_encode_present(
486        drawable: cp_drawable_t,
487        command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
488    );
489}
490
491extern "C-unwind" {
492    #[deprecated = "renamed to `cp_drawable::state`"]
493    pub fn cp_drawable_get_state(drawable: cp_drawable_t) -> cp_drawable_state;
494}
495
496extern "C-unwind" {
497    #[cfg(feature = "cp_types")]
498    #[deprecated = "renamed to `cp_drawable::presentation_frame_index`"]
499    pub fn cp_drawable_get_presentation_frame_index(
500        drawable: cp_drawable_t,
501    ) -> cp_compositor_frame_index_t;
502}
503
504extern "C-unwind" {
505    #[cfg(feature = "frame_timing")]
506    #[deprecated = "renamed to `cp_drawable::frame_timing`"]
507    pub fn cp_drawable_get_frame_timing(drawable: cp_drawable_t) -> cp_frame_timing_t;
508}