objc2-compositor-services 0.3.2

Bindings to the CompositorServices framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
//! 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;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-metal")]
use objc2_metal::*;

use crate::*;

/// The state of ownership for the drawable.
///
/// Use these constants to determine whether the drawable is ready
/// for you to use. When the drawable is in the ``cp_drawable_state_rendering``
/// state, you can begin drawing. Other states indicate the
/// drawable is either busy or not assigned to a frame.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_drawable_state?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct cp_drawable_state(pub u32);
impl cp_drawable_state {
    /// A drawable that is not in use and ready for assignment to a frame.
    #[doc(alias = "cp_drawable_state_available")]
    pub const available: Self = Self(0);
    /// A drawable that is assigned to a frame and ready to accept
    /// your drawing commands.
    #[doc(alias = "cp_drawable_state_rendering")]
    pub const rendering: Self = Self(1);
    /// A drawable that the compositor is currently displaying onscreen.
    #[doc(alias = "cp_drawable_state_presenting")]
    pub const presenting: Self = Self(2);
}

unsafe impl Encode for cp_drawable_state {
    const ENCODING: Encoding = u32::ENCODING;
}

unsafe impl RefEncode for cp_drawable_state {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// The target where the drawable will be displayed/used.
///
/// Use these constants to determine whether content should
/// be drawn for certain targets.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_drawable_target?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct cp_drawable_target(pub u32);
impl cp_drawable_target {
    /// A drawable that is targeting the built-in display,
    /// this is what a user will see in the device.
    #[doc(alias = "cp_drawable_target_built_in")]
    pub const built_in: Self = Self(0);
    /// A drawable that will be used for capture purposes,
    /// this could be used for video or AirPlay streaming and
    /// will be visible to users outside of the device.
    #[doc(alias = "cp_drawable_target_capture")]
    pub const capture: Self = Self(1);
}

unsafe impl Encode for cp_drawable_target {
    const ENCODING: Encoding = u32::ENCODING;
}

unsafe impl RefEncode for cp_drawable_target {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_drawable?language=objc)
#[repr(C)]
#[derive(Debug)]
pub struct cp_drawable {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

unsafe impl RefEncode for cp_drawable {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Encoding::Struct("cp_drawable", &[]));
}

/// An opaque type that contains the textures and other information
/// you need to set up your render pipeline.
///
/// Use the drawable type to retrieve the textures for your render pipelines,
/// and use the drawable’s views to get details about how to render to those
/// textures. Get the drawable for a frame using the ``cp_frame_query_drawable``
/// function. The layer manages a limited number of reusable drawable types
/// and recycles them after each use. Draw only one frame at a time to ensure
/// each new frame’s drawable type is ready in time.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_drawable_t?language=objc)
pub type cp_drawable_t = *mut cp_drawable;

impl cp_drawable {
    /// Returns the number of color and depth textures available in the drawable.
    ///
    /// - Parameters:
    /// - drawable: The drawable for a frame.
    /// - Returns: The number of textures available for drawing. For example, a return
    /// value of `2` indicates there are two color textures and two depth
    /// textures available.
    ///
    /// Use the returned value as the maximum number of textures to retrieve
    /// from the ``cp_drawable_get_color_texture`` or ``cp_drawable_get_depth_texture``
    /// functions.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_get_texture_count")]
    #[inline]
    pub unsafe fn texture_count(drawable: cp_drawable_t) -> usize {
        extern "C-unwind" {
            fn cp_drawable_get_texture_count(drawable: cp_drawable_t) -> usize;
        }
        unsafe { cp_drawable_get_texture_count(drawable) }
    }

    /// Returns the number of tracking areas textures available in the drawable.
    ///
    /// - Parameters:
    /// - drawable: The drawable for a frame.
    /// - Returns: The number of textures available for drawing. For example, a return
    /// value of `2` indicates there are two tracking areas textures available.
    ///
    /// Use the returned value as the maximum number of textures to retrieve
    /// from the ``cp_drawable_get_tracking_areas_texture``function.
    /// This will be equal to ``cp_drawable_get_texture_count`` when tracking
    /// areas textures are enabled through the configuration otherwise will be 0.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_get_tracking_areas_texture_count")]
    #[inline]
    pub unsafe fn tracking_areas_texture_count(drawable: cp_drawable_t) -> usize {
        extern "C-unwind" {
            fn cp_drawable_get_tracking_areas_texture_count(drawable: cp_drawable_t) -> usize;
        }
        unsafe { cp_drawable_get_tracking_areas_texture_count(drawable) }
    }

    /// Returns the depth texture at the specified index in the drawable.
    ///
    /// - Parameters:
    /// - drawable: The drawable for a frame.
    /// - index: The index of the depth texture you want. The index must
    /// be greater than or equal to `0` and less than the value that
    /// ``cp_drawable_get_texture_count`` returns.
    /// - Returns: The Metal depth texture at the specified index.
    ///
    /// Use the returned texture in your render pipeline as the depth texture
    /// for your content. The layer’s texture topology determines the layout and
    /// content for each texture. The drawable’s views contain information
    /// about how those views map to the textures.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_get_depth_texture")]
    #[cfg(feature = "objc2-metal")]
    #[inline]
    pub unsafe fn depth_texture(
        drawable: cp_drawable_t,
        index: usize,
    ) -> Retained<ProtocolObject<dyn MTLTexture>> {
        extern "C-unwind" {
            fn cp_drawable_get_depth_texture(
                drawable: cp_drawable_t,
                index: usize,
            ) -> *mut ProtocolObject<dyn MTLTexture>;
        }
        let ret = unsafe { cp_drawable_get_depth_texture(drawable, index) };
        unsafe { Retained::retain_autoreleased(ret) }
            .expect("function was marked as returning non-null, but actually returned NULL")
    }

    /// Returns the color texture at the specified index in the drawable.
    ///
    /// - Parameters:
    /// - drawable: The drawable for a frame.
    /// - index: The index of the color texture you want. The index must
    /// be greater than or equal to `0` and less than the value that
    /// ``cp_drawable_get_texture_count`` returns.
    /// - Returns: The Metal color texture at the specified index.
    ///
    /// Use the returned texture in your render pipeline to store the pixels
    /// you want to appear onscreen. The layer’s texture topology determines
    /// the layout and content for each texture. The drawable’s views contain
    /// information about how those views map to the textures.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_get_color_texture")]
    #[cfg(feature = "objc2-metal")]
    #[inline]
    pub unsafe fn color_texture(
        drawable: cp_drawable_t,
        index: usize,
    ) -> Retained<ProtocolObject<dyn MTLTexture>> {
        extern "C-unwind" {
            fn cp_drawable_get_color_texture(
                drawable: cp_drawable_t,
                index: usize,
            ) -> *mut ProtocolObject<dyn MTLTexture>;
        }
        let ret = unsafe { cp_drawable_get_color_texture(drawable, index) };
        unsafe { Retained::retain_autoreleased(ret) }
            .expect("function was marked as returning non-null, but actually returned NULL")
    }

    /// Returns the tracking areas texture at the specified index in the drawable.
    ///
    /// - Parameters:
    /// - drawable: The drawable for a frame.
    /// - index: The index of the texture you want. The index must
    /// be greater than or equal to `0` and less than the value that
    /// ``cp_drawable_get_tracking_areas_texture_count`` returns.
    /// - Returns: The Metal object index texture at the specified index.
    ///
    /// Use the returned texture in your render pipeline to store the tracking areas ID
    /// used for hover effects and indirect gestures. The layer’s texture topology determines
    /// the layout and content for each texture. The drawable’s views contain
    /// information about how those views map to the textures.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_get_tracking_areas_texture")]
    #[cfg(feature = "objc2-metal")]
    #[inline]
    pub unsafe fn tracking_areas_texture(
        drawable: cp_drawable_t,
        index: usize,
    ) -> Retained<ProtocolObject<dyn MTLTexture>> {
        extern "C-unwind" {
            fn cp_drawable_get_tracking_areas_texture(
                drawable: cp_drawable_t,
                index: usize,
            ) -> *mut ProtocolObject<dyn MTLTexture>;
        }
        let ret = unsafe { cp_drawable_get_tracking_areas_texture(drawable, index) };
        unsafe { Retained::retain_autoreleased(ret) }
            .expect("function was marked as returning non-null, but actually returned NULL")
    }

    /// Returns a tracking area which is create on the drawable's list of tracking areas.
    ///
    /// - Parameters:
    /// - drawable: The drawable for a frame.
    /// - identifier: The unique identifier for the tracking area.
    /// - Returns: A tracking area that was created.
    ///
    /// A tracking area describes a region of a view that interacts
    /// with the gaze/cursor.
    /// Cannot use ``cp_tracking_area_identifier_invalid`` as
    /// an identifier.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_add_tracking_area")]
    #[cfg(feature = "tracking_area")]
    #[inline]
    pub unsafe fn add_tracking_area(
        drawable: cp_drawable_t,
        identifier: cp_tracking_area_identifier,
    ) -> cp_tracking_area_t {
        extern "C-unwind" {
            fn cp_drawable_add_tracking_area(
                drawable: cp_drawable_t,
                identifier: cp_tracking_area_identifier,
            ) -> cp_tracking_area_t;
        }
        unsafe { cp_drawable_add_tracking_area(drawable, identifier) }
    }

    /// Returns the number of rasterization rate maps associated with the
    /// drawable.
    ///
    /// - Parameters:
    /// - drawable: The drawable for a frame.
    /// - Returns: The number of rasterization rate maps available for drawing.
    ///
    /// Use the returned value as the maximum number of rate maps to retrieve
    /// from the ``cp_drawable_get_rasterization_rate_map`` function.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_get_rasterization_rate_map_count")]
    #[inline]
    pub unsafe fn rasterization_rate_map_count(drawable: cp_drawable_t) -> usize {
        extern "C-unwind" {
            fn cp_drawable_get_rasterization_rate_map_count(drawable: cp_drawable_t) -> usize;
        }
        unsafe { cp_drawable_get_rasterization_rate_map_count(drawable) }
    }

    /// Returns the rasterization rate map at the specified index in the drawable.
    ///
    /// - Parameters:
    /// - drawable: The drawable for a frame.
    /// - index: The index of the rasterization rate map you want.
    /// The index must be greater than or equal to `0` and less than the value
    /// that ``cp_drawable_get_rasterization_rate_map_count`` returns.
    /// - Returns: The rasterization rate map at the specified index.
    ///
    /// Apply the rasterization rate map to your render descriptor when you set
    /// up your drawing environment. A rate map defines how the GPU scales
    /// different parts of the texture to fill the screen. You use these rate
    /// maps to save time and render less important parts of your scene at lower
    /// resolutions. For example, when foveation is enabled, the drawable
    /// includes a rasterization rate map to render the portions of the texture
    /// in someone’s peripheral vision at a lower resolution.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_get_rasterization_rate_map")]
    #[cfg(feature = "objc2-metal")]
    #[inline]
    pub unsafe fn rasterization_rate_map(
        drawable: cp_drawable_t,
        index: usize,
    ) -> Retained<ProtocolObject<dyn MTLRasterizationRateMap>> {
        extern "C-unwind" {
            fn cp_drawable_get_rasterization_rate_map(
                drawable: cp_drawable_t,
                index: usize,
            ) -> *mut ProtocolObject<dyn MTLRasterizationRateMap>;
        }
        let ret = unsafe { cp_drawable_get_rasterization_rate_map(drawable, index) };
        unsafe { Retained::retain_autoreleased(ret) }
            .expect("function was marked as returning non-null, but actually returned NULL")
    }

    /// Returns the Y flipped rasterization rate map at the specified index in the drawable.
    ///
    /// - Parameters:
    /// - drawable: The drawable for a frame.
    /// - index: The index of the rasterization rate map you want.
    /// The index must be greater than or equal to `0` and less than the value
    /// that ``cp_drawable_get_rasterization_rate_map_count`` returns.
    /// - Returns: The Y flipped rasterization rate map at the specified index.
    ///
    /// This function provides a Y flipped map that is generated form the ``cp_drawable_get_rasterization_rate_map``.
    /// Flipped is defined as +Y = down for clip/normalized device coordinates (flipped from Metal).
    /// If projection matrix is needed, use ``cp_drawable_compute_projection``
    /// with a +Y = down axes convention to generate the correct matrix.
    ///
    /// Can only be used for intermediary render passes, the final render pass of the
    /// drawable it cannot be flipped and must use Metal convention of +Y = up.
    ///
    /// Generating a flipped rasterization rate map will bring additional computational
    /// cost to your render loop.
    ///
    /// In order to generate Y flipped rasterization rate maps in your rendering session,
    /// update the ``cp_layer_renderer_configuration_t`` using the function
    /// ``cp_layer_renderer_configuration_set_generate_flipped_rasterization_rate_maps``.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_get_flipped_rasterization_rate_map")]
    #[cfg(feature = "objc2-metal")]
    #[inline]
    pub unsafe fn flipped_rasterization_rate_map(
        drawable: cp_drawable_t,
        index: usize,
    ) -> Retained<ProtocolObject<dyn MTLRasterizationRateMap>> {
        extern "C-unwind" {
            fn cp_drawable_get_flipped_rasterization_rate_map(
                drawable: cp_drawable_t,
                index: usize,
            ) -> *mut ProtocolObject<dyn MTLRasterizationRateMap>;
        }
        let ret = unsafe { cp_drawable_get_flipped_rasterization_rate_map(drawable, index) };
        unsafe { Retained::retain_autoreleased(ret) }
            .expect("function was marked as returning non-null, but actually returned NULL")
    }

    /// Returns the number of separate views to draw for the frame.
    ///
    /// - Parameters:
    /// - drawable: The drawable for a frame.
    /// - Returns: The number of separate views to draw.
    ///
    /// The number of views corresponds to the number of separate versions
    /// of your scene you create for the frame. For a device with stereoscopic
    /// video, you render two views — one for each eye. The actual number of
    /// views can vary based on the drawing environment or your app’s
    /// configuration. For example, you typically render only one view in
    /// Simulator.
    ///
    /// Fetch the actual views using the ``cp_drawable_get_view`` function.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_get_view_count")]
    #[inline]
    pub unsafe fn view_count(drawable: cp_drawable_t) -> usize {
        extern "C-unwind" {
            fn cp_drawable_get_view_count(drawable: cp_drawable_t) -> usize;
        }
        unsafe { cp_drawable_get_view_count(drawable) }
    }

    /// Returns the specified view from the drawable.
    ///
    /// - Parameters:
    /// - drawable: The drawable for a frame.
    /// - index: The index of the view you want. The index must be
    /// greater than or equal to 0 and less than the value that
    /// ``cp_drawable_get_view_count`` returns.
    /// - Returns: The view at the specified index.
    ///
    /// Each view contains information you need to render into the drawable’s
    /// textures.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_get_view")]
    #[cfg(feature = "view")]
    #[inline]
    pub unsafe fn view(drawable: cp_drawable_t, index: usize) -> cp_view_t {
        extern "C-unwind" {
            fn cp_drawable_get_view(drawable: cp_drawable_t, index: usize) -> cp_view_t;
        }
        unsafe { cp_drawable_get_view(drawable, index) }
    }

    /// Encodes a notification event to the specified command buffer to present
    /// the drawable’s content onscreen.
    ///
    /// - Parameters:
    /// - drawable: The drawable for a frame.
    /// - command_buffer: The command buffer you used to encode your
    /// frame’s content. If the command buffer is already committed,
    /// this function aborts your app with an error.
    ///
    /// - Note: Commit the command buffer after calling present.
    ///
    /// Call this function as the last step before committing the specified
    /// command buffer. Specifically, call it after you finish encoding all
    /// the work required to render the frame, and immediately before you
    /// call the command buffer’s
    /// <doc
    /// ://com.apple.documentation/documentation/metal/mtlcommandbuffer/1443003-commit>
    /// method. The function adds a presentation event to the buffer that
    /// causes the compositor to display your frame.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_encode_present")]
    #[cfg(feature = "objc2-metal")]
    #[inline]
    pub unsafe fn encode_present(
        drawable: cp_drawable_t,
        command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
    ) {
        extern "C-unwind" {
            fn cp_drawable_encode_present(
                drawable: cp_drawable_t,
                command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
            );
        }
        unsafe { cp_drawable_encode_present(drawable, command_buffer) }
    }

    /// Encodes a notification event to the specified command buffer to present
    /// the drawable’s content onscreen.
    ///
    /// - Parameters:
    /// - drawable: The drawable for a frame.
    ///
    /// - Note: Commit the command buffer to the layer queue before calling present.
    ///
    /// Call this function as the last step before committing the specified
    /// command buffer. Specifically, call it after you finish encoding all
    /// the work required to render the frame, and immediately before you
    /// call the command buffer’s
    /// <doc
    /// ://com.apple.documentation/documentation/metal/mtlcommandbuffer/1443003-commit>
    /// method. The function adds a presentation event to the buffer that
    /// causes the compositor to display your frame.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_mtl4_encode_present")]
    #[inline]
    pub unsafe fn mtl4_encode_present(drawable: cp_drawable_t) {
        extern "C-unwind" {
            fn cp_drawable_mtl4_encode_present(drawable: cp_drawable_t);
        }
        unsafe { cp_drawable_mtl4_encode_present(drawable) }
    }

    /// Returns a value that indicates the current operational state
    /// of the drawable type.
    ///
    /// - Parameters: The drawable to check.
    /// - Returns: ``cp_drawable_state/cp_drawable_state_rendering`` if the
    /// drawable type is ready for you to draw your content, or any other value if
    /// the compositor currently owns the drawable.
    ///
    /// Compositor reuses the underlying data structures associated with
    /// drawable types, and the state of the drawable indicates whether
    /// it's ready for you to use. Perform your drawing operations only
    /// when the drawable is in the ``cp_drawable_state/cp_drawable_state_rendering`` state.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_get_state")]
    #[inline]
    pub unsafe fn state(drawable: cp_drawable_t) -> cp_drawable_state {
        extern "C-unwind" {
            fn cp_drawable_get_state(drawable: cp_drawable_t) -> cp_drawable_state;
        }
        unsafe { cp_drawable_get_state(drawable) }
    }

    /// Returns a value that indicates the target of the drawable type.
    ///
    /// - Parameters: The drawable to check.
    /// - Returns: ``cp_drawable_target/cp_drawable_target_built_in`` if the
    /// drawable will be displayed for the user in the device, or any other value if the drawable
    /// maybe used for other purposes.
    ///
    /// When drawing for the drawable this can be used to alter
    /// what is rendered for different targets.
    /// Renderer should always prioritize ``cp_drawable_target/cp_drawable_target_built_in``
    /// target type.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_get_target")]
    #[inline]
    pub unsafe fn target(drawable: cp_drawable_t) -> cp_drawable_target {
        extern "C-unwind" {
            fn cp_drawable_get_target(drawable: cp_drawable_t) -> cp_drawable_target;
        }
        unsafe { cp_drawable_get_target(drawable) }
    }

    /// Returns the index of the frame of content for you to produce.
    ///
    /// - Parameters:
    /// - drawable: The drawable for a frame.
    /// - Returns: The presentation index of the frame.
    ///
    /// When your compositor scene becomes visible, you start drawing
    /// frames of content. The compositor assigns a sequential index to
    /// each frame to indicate its position in the final output. You can
    /// use these indexes to differentiate frames during drawing or predict
    /// future frame indexes. For example, you might start playback of an
    /// audio file when a specific frame appears onscreen.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_get_presentation_frame_index")]
    #[cfg(feature = "cp_types")]
    #[inline]
    pub unsafe fn presentation_frame_index(drawable: cp_drawable_t) -> cp_compositor_frame_index_t {
        extern "C-unwind" {
            fn cp_drawable_get_presentation_frame_index(
                drawable: cp_drawable_t,
            ) -> cp_compositor_frame_index_t;
        }
        unsafe { cp_drawable_get_presentation_frame_index(drawable) }
    }

    /// Returns the timing information for the frame of the specified drawable.
    ///
    /// - Parameters:
    /// - drawable: The drawable for a frame.
    /// - Returns: The timing information for the drawable’s associated frame.
    ///
    /// Pass the returned type to the ``cp_frame_timing_get_optimal_input_time``
    /// function to determine when to start the encoding process for a frame.
    /// Pass it to other functions to determine other time-related deadlines.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_get_frame_timing")]
    #[cfg(feature = "frame_timing")]
    #[inline]
    pub unsafe fn frame_timing(drawable: cp_drawable_t) -> cp_frame_timing_t {
        extern "C-unwind" {
            fn cp_drawable_get_frame_timing(drawable: cp_drawable_t) -> cp_frame_timing_t;
        }
        unsafe { cp_drawable_get_frame_timing(drawable) }
    }

    /// Returns whether content capture is protected and it is safe to
    /// draw content that should be protected from capture.
    ///
    /// - Parameters:
    /// - drawable: The drawable for a frame.
    /// - Returns: Whether it is safe to draw content that is for built-in
    /// display only. When this value is true, any capture of content
    /// being displayed on the built-in display will be obscured by the
    /// system. If false, it cannot be assumed that content will not
    /// be seen by users outside of the device, both live and recorded.
    ///
    /// Use this function to ensure that drawing that is only meant for
    /// eyes in the device is not drawn when false.
    /// Only adopt if app has adopted SwiftUI `activatesContentCaptureProtected`
    /// scene modifier and drawing will have content that is not desired
    /// to meant to be captured.
    /// For ``cp_drawable_target_capture`` this will
    /// always return false as it is upto the renderer to handle drawing
    /// content that will be captured beyond the built-in displays.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_is_content_capture_protected")]
    #[inline]
    pub unsafe fn is_content_capture_protected(drawable: cp_drawable_t) -> bool {
        extern "C-unwind" {
            fn cp_drawable_is_content_capture_protected(drawable: cp_drawable_t) -> bool;
        }
        unsafe { cp_drawable_is_content_capture_protected(drawable) }
    }

    /// Adds a render context to a drawable.
    /// This object will draw any content that the compositor needs to render
    /// in the application.
    /// - Note: The render context can only be used when the layer renderer is using layered layout
    /// or in platforms that only render one view (ex: simulator)
    ///
    /// - Note: The render context makes use of the device_anchor set in
    /// ``cp_drawable_set_device_anchor`` the device_anchor should be set in the
    /// drawable before calling ``cp_drawable_add_render_context``.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_add_render_context")]
    #[cfg(all(feature = "drawable_render_context", feature = "objc2-metal"))]
    #[inline]
    pub unsafe fn add_render_context(
        drawable: cp_drawable_t,
        cmd_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
    ) -> cp_drawable_render_context_t {
        extern "C-unwind" {
            fn cp_drawable_add_render_context(
                drawable: cp_drawable_t,
                cmd_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
            ) -> cp_drawable_render_context_t;
        }
        unsafe { cp_drawable_add_render_context(drawable, cmd_buffer) }
    }

    /// Adds a render context to a drawable.
    /// This object will draw any content that the compositor needs to render
    /// in the application.
    /// - Note: The render context can only be used when the layer renderer is using layered layout
    /// or in platforms that only render one view (ex: simulator)
    ///
    /// - Note: The render context makes use of the device_anchor set in
    /// ``cp_drawable_set_device_anchor`` the device_anchor should be set in the
    /// drawable before calling ``cp_drawable_add_render_context``.
    ///
    /// # Safety
    ///
    /// `drawable` must be a valid pointer.
    #[doc(alias = "cp_drawable_add_mtl4_render_context")]
    #[cfg(feature = "drawable_render_context")]
    #[inline]
    pub unsafe fn add_mtl4_render_context(drawable: cp_drawable_t) -> cp_drawable_render_context_t {
        extern "C-unwind" {
            fn cp_drawable_add_mtl4_render_context(
                drawable: cp_drawable_t,
            ) -> cp_drawable_render_context_t;
        }
        unsafe { cp_drawable_add_mtl4_render_context(drawable) }
    }
}

/// [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_drawable_array?language=objc)
#[repr(C)]
#[derive(Debug)]
pub struct cp_drawable_array {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

unsafe impl RefEncode for cp_drawable_array {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Encoding::Struct("cp_drawable_array", &[]));
}

/// An opaque type that contains the drawable types and other information
/// you need to set up your render pipeline.
///
/// See ``cp_drawable_t`` for more information about drawables.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_drawable_array_t?language=objc)
pub type cp_drawable_array_t = *mut cp_drawable_array;

impl cp_drawable_array {
    /// Returns the drawable at the specified index in the array.
    ///
    /// - Parameters:
    /// - drawable_array: The drawable array for a frame.
    /// - index: The index of the drawable you want. The index must
    /// be greater than or equal to `0` and less than the value that
    /// ``cp_drawable_array_get_count`` returns.
    /// - Returns: The drawable available for drawing at the specified index.
    ///
    /// The ``cp_drawable_t`` type contains the textures and other
    /// information you need to set up your render descriptor in Metal.
    ///
    /// # Safety
    ///
    /// `drawable_array` must be a valid pointer.
    #[doc(alias = "cp_drawable_array_get_drawable")]
    #[inline]
    pub unsafe fn drawable(drawable_array: cp_drawable_array_t, index: usize) -> cp_drawable_t {
        extern "C-unwind" {
            fn cp_drawable_array_get_drawable(
                drawable_array: cp_drawable_array_t,
                index: usize,
            ) -> cp_drawable_t;
        }
        unsafe { cp_drawable_array_get_drawable(drawable_array, index) }
    }

    /// Returns the number of drawables in the array.
    ///
    /// - Parameters:
    /// - drawable_array: The drawable array for a frame.
    /// - Returns: The number of drawables available for drawing. For example, a return
    /// value of `2` indicates there are two drawables for this frame.
    ///
    /// Use the returned value as the maximum number of textures to retrieve
    /// from the ``cp_drawable_array_get_drawable`` functions.
    ///
    /// # Safety
    ///
    /// `drawable_array` must be a valid pointer.
    #[doc(alias = "cp_drawable_array_get_count")]
    #[inline]
    pub unsafe fn count(drawable_array: cp_drawable_array_t) -> usize {
        extern "C-unwind" {
            fn cp_drawable_array_get_count(drawable_array: cp_drawable_array_t) -> usize;
        }
        unsafe { cp_drawable_array_get_count(drawable_array) }
    }
}

extern "C-unwind" {
    #[deprecated = "renamed to `cp_drawable::texture_count`"]
    pub fn cp_drawable_get_texture_count(drawable: cp_drawable_t) -> usize;
}

extern "C-unwind" {
    #[deprecated = "renamed to `cp_drawable::tracking_areas_texture_count`"]
    pub fn cp_drawable_get_tracking_areas_texture_count(drawable: cp_drawable_t) -> usize;
}

#[cfg(feature = "objc2-metal")]
#[deprecated = "renamed to `cp_drawable::depth_texture`"]
#[inline]
pub unsafe extern "C-unwind" fn cp_drawable_get_depth_texture(
    drawable: cp_drawable_t,
    index: usize,
) -> Retained<ProtocolObject<dyn MTLTexture>> {
    extern "C-unwind" {
        fn cp_drawable_get_depth_texture(
            drawable: cp_drawable_t,
            index: usize,
        ) -> *mut ProtocolObject<dyn MTLTexture>;
    }
    let ret = unsafe { cp_drawable_get_depth_texture(drawable, index) };
    unsafe { Retained::retain_autoreleased(ret) }
        .expect("function was marked as returning non-null, but actually returned NULL")
}

#[cfg(feature = "objc2-metal")]
#[deprecated = "renamed to `cp_drawable::color_texture`"]
#[inline]
pub unsafe extern "C-unwind" fn cp_drawable_get_color_texture(
    drawable: cp_drawable_t,
    index: usize,
) -> Retained<ProtocolObject<dyn MTLTexture>> {
    extern "C-unwind" {
        fn cp_drawable_get_color_texture(
            drawable: cp_drawable_t,
            index: usize,
        ) -> *mut ProtocolObject<dyn MTLTexture>;
    }
    let ret = unsafe { cp_drawable_get_color_texture(drawable, index) };
    unsafe { Retained::retain_autoreleased(ret) }
        .expect("function was marked as returning non-null, but actually returned NULL")
}

#[cfg(feature = "objc2-metal")]
#[deprecated = "renamed to `cp_drawable::tracking_areas_texture`"]
#[inline]
pub unsafe extern "C-unwind" fn cp_drawable_get_tracking_areas_texture(
    drawable: cp_drawable_t,
    index: usize,
) -> Retained<ProtocolObject<dyn MTLTexture>> {
    extern "C-unwind" {
        fn cp_drawable_get_tracking_areas_texture(
            drawable: cp_drawable_t,
            index: usize,
        ) -> *mut ProtocolObject<dyn MTLTexture>;
    }
    let ret = unsafe { cp_drawable_get_tracking_areas_texture(drawable, index) };
    unsafe { Retained::retain_autoreleased(ret) }
        .expect("function was marked as returning non-null, but actually returned NULL")
}

extern "C-unwind" {
    #[cfg(feature = "tracking_area")]
    #[deprecated = "renamed to `cp_drawable::add_tracking_area`"]
    pub fn cp_drawable_add_tracking_area(
        drawable: cp_drawable_t,
        identifier: cp_tracking_area_identifier,
    ) -> cp_tracking_area_t;
}

extern "C-unwind" {
    #[deprecated = "renamed to `cp_drawable::rasterization_rate_map_count`"]
    pub fn cp_drawable_get_rasterization_rate_map_count(drawable: cp_drawable_t) -> usize;
}

#[cfg(feature = "objc2-metal")]
#[deprecated = "renamed to `cp_drawable::rasterization_rate_map`"]
#[inline]
pub unsafe extern "C-unwind" fn cp_drawable_get_rasterization_rate_map(
    drawable: cp_drawable_t,
    index: usize,
) -> Retained<ProtocolObject<dyn MTLRasterizationRateMap>> {
    extern "C-unwind" {
        fn cp_drawable_get_rasterization_rate_map(
            drawable: cp_drawable_t,
            index: usize,
        ) -> *mut ProtocolObject<dyn MTLRasterizationRateMap>;
    }
    let ret = unsafe { cp_drawable_get_rasterization_rate_map(drawable, index) };
    unsafe { Retained::retain_autoreleased(ret) }
        .expect("function was marked as returning non-null, but actually returned NULL")
}

#[cfg(feature = "objc2-metal")]
#[deprecated = "renamed to `cp_drawable::flipped_rasterization_rate_map`"]
#[inline]
pub unsafe extern "C-unwind" fn cp_drawable_get_flipped_rasterization_rate_map(
    drawable: cp_drawable_t,
    index: usize,
) -> Retained<ProtocolObject<dyn MTLRasterizationRateMap>> {
    extern "C-unwind" {
        fn cp_drawable_get_flipped_rasterization_rate_map(
            drawable: cp_drawable_t,
            index: usize,
        ) -> *mut ProtocolObject<dyn MTLRasterizationRateMap>;
    }
    let ret = unsafe { cp_drawable_get_flipped_rasterization_rate_map(drawable, index) };
    unsafe { Retained::retain_autoreleased(ret) }
        .expect("function was marked as returning non-null, but actually returned NULL")
}

extern "C-unwind" {
    #[deprecated = "renamed to `cp_drawable::view_count`"]
    pub fn cp_drawable_get_view_count(drawable: cp_drawable_t) -> usize;
}

extern "C-unwind" {
    #[cfg(feature = "view")]
    #[deprecated = "renamed to `cp_drawable::view`"]
    pub fn cp_drawable_get_view(drawable: cp_drawable_t, index: usize) -> cp_view_t;
}

extern "C-unwind" {
    #[cfg(feature = "objc2-metal")]
    #[deprecated = "renamed to `cp_drawable::encode_present`"]
    pub fn cp_drawable_encode_present(
        drawable: cp_drawable_t,
        command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
    );
}

extern "C-unwind" {
    #[deprecated = "renamed to `cp_drawable::mtl4_encode_present`"]
    pub fn cp_drawable_mtl4_encode_present(drawable: cp_drawable_t);
}

extern "C-unwind" {
    #[deprecated = "renamed to `cp_drawable::state`"]
    pub fn cp_drawable_get_state(drawable: cp_drawable_t) -> cp_drawable_state;
}

extern "C-unwind" {
    #[deprecated = "renamed to `cp_drawable::target`"]
    pub fn cp_drawable_get_target(drawable: cp_drawable_t) -> cp_drawable_target;
}

extern "C-unwind" {
    #[cfg(feature = "cp_types")]
    #[deprecated = "renamed to `cp_drawable::presentation_frame_index`"]
    pub fn cp_drawable_get_presentation_frame_index(
        drawable: cp_drawable_t,
    ) -> cp_compositor_frame_index_t;
}

extern "C-unwind" {
    #[cfg(feature = "frame_timing")]
    #[deprecated = "renamed to `cp_drawable::frame_timing`"]
    pub fn cp_drawable_get_frame_timing(drawable: cp_drawable_t) -> cp_frame_timing_t;
}

extern "C-unwind" {
    #[deprecated = "renamed to `cp_drawable::is_content_capture_protected`"]
    pub fn cp_drawable_is_content_capture_protected(drawable: cp_drawable_t) -> bool;
}

extern "C-unwind" {
    #[cfg(all(feature = "drawable_render_context", feature = "objc2-metal"))]
    #[deprecated = "renamed to `cp_drawable::add_render_context`"]
    pub fn cp_drawable_add_render_context(
        drawable: cp_drawable_t,
        cmd_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
    ) -> cp_drawable_render_context_t;
}

extern "C-unwind" {
    #[cfg(feature = "drawable_render_context")]
    #[deprecated = "renamed to `cp_drawable::add_mtl4_render_context`"]
    pub fn cp_drawable_add_mtl4_render_context(
        drawable: cp_drawable_t,
    ) -> cp_drawable_render_context_t;
}

extern "C-unwind" {
    #[deprecated = "renamed to `cp_drawable_array::drawable`"]
    pub fn cp_drawable_array_get_drawable(
        drawable_array: cp_drawable_array_t,
        index: usize,
    ) -> cp_drawable_t;
}

extern "C-unwind" {
    #[deprecated = "renamed to `cp_drawable_array::count`"]
    pub fn cp_drawable_array_get_count(drawable_array: cp_drawable_array_t) -> usize;
}