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/// The target where the drawable will be displayed/used.
47///
48/// Use these constants to determine whether content should
49/// be drawn for certain targets.
50///
51/// See also [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_drawable_target?language=objc)
52// NS_ENUM
53#[repr(transparent)]
54#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
55pub struct cp_drawable_target(pub u32);
56impl cp_drawable_target {
57 /// A drawable that is targeting the built-in display,
58 /// this is what a user will see in the device.
59 #[doc(alias = "cp_drawable_target_built_in")]
60 pub const built_in: Self = Self(0);
61 /// A drawable that will be used for capture purposes,
62 /// this could be used for video or AirPlay streaming and
63 /// will be visible to users outside of the device.
64 #[doc(alias = "cp_drawable_target_capture")]
65 pub const capture: Self = Self(1);
66}
67
68unsafe impl Encode for cp_drawable_target {
69 const ENCODING: Encoding = u32::ENCODING;
70}
71
72unsafe impl RefEncode for cp_drawable_target {
73 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
74}
75
76/// [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_drawable?language=objc)
77#[repr(C)]
78#[derive(Debug)]
79pub struct cp_drawable {
80 inner: [u8; 0],
81 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
82}
83
84unsafe impl RefEncode for cp_drawable {
85 const ENCODING_REF: Encoding = Encoding::Pointer(&Encoding::Struct("cp_drawable", &[]));
86}
87
88/// An opaque type that contains the textures and other information
89/// you need to set up your render pipeline.
90///
91/// Use the drawable type to retrieve the textures for your render pipelines,
92/// and use the drawable’s views to get details about how to render to those
93/// textures. Get the drawable for a frame using the ``cp_frame_query_drawable``
94/// function. The layer manages a limited number of reusable drawable types
95/// and recycles them after each use. Draw only one frame at a time to ensure
96/// each new frame’s drawable type is ready in time.
97///
98/// See also [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_drawable_t?language=objc)
99pub type cp_drawable_t = *mut cp_drawable;
100
101impl cp_drawable {
102 /// Returns the number of color and depth textures available in the drawable.
103 ///
104 /// - Parameters:
105 /// - drawable: The drawable for a frame.
106 /// - Returns: The number of textures available for drawing. For example, a return
107 /// value of `2` indicates there are two color textures and two depth
108 /// textures available.
109 ///
110 /// Use the returned value as the maximum number of textures to retrieve
111 /// from the ``cp_drawable_get_color_texture`` or ``cp_drawable_get_depth_texture``
112 /// functions.
113 ///
114 /// # Safety
115 ///
116 /// `drawable` must be a valid pointer.
117 #[doc(alias = "cp_drawable_get_texture_count")]
118 #[inline]
119 pub unsafe fn texture_count(drawable: cp_drawable_t) -> usize {
120 extern "C-unwind" {
121 fn cp_drawable_get_texture_count(drawable: cp_drawable_t) -> usize;
122 }
123 unsafe { cp_drawable_get_texture_count(drawable) }
124 }
125
126 /// Returns the number of tracking areas textures available in the drawable.
127 ///
128 /// - Parameters:
129 /// - drawable: The drawable for a frame.
130 /// - Returns: The number of textures available for drawing. For example, a return
131 /// value of `2` indicates there are two tracking areas textures available.
132 ///
133 /// Use the returned value as the maximum number of textures to retrieve
134 /// from the ``cp_drawable_get_tracking_areas_texture``function.
135 /// This will be equal to ``cp_drawable_get_texture_count`` when tracking
136 /// areas textures are enabled through the configuration otherwise will be 0.
137 ///
138 /// # Safety
139 ///
140 /// `drawable` must be a valid pointer.
141 #[doc(alias = "cp_drawable_get_tracking_areas_texture_count")]
142 #[inline]
143 pub unsafe fn tracking_areas_texture_count(drawable: cp_drawable_t) -> usize {
144 extern "C-unwind" {
145 fn cp_drawable_get_tracking_areas_texture_count(drawable: cp_drawable_t) -> usize;
146 }
147 unsafe { cp_drawable_get_tracking_areas_texture_count(drawable) }
148 }
149
150 /// Returns the depth texture at the specified index in the drawable.
151 ///
152 /// - Parameters:
153 /// - drawable: The drawable for a frame.
154 /// - index: The index of the depth texture you want. The index must
155 /// be greater than or equal to `0` and less than the value that
156 /// ``cp_drawable_get_texture_count`` returns.
157 /// - Returns: The Metal depth texture at the specified index.
158 ///
159 /// Use the returned texture in your render pipeline as the depth texture
160 /// for your content. The layer’s texture topology determines the layout and
161 /// content for each texture. The drawable’s views contain information
162 /// about how those views map to the textures.
163 ///
164 /// # Safety
165 ///
166 /// `drawable` must be a valid pointer.
167 #[doc(alias = "cp_drawable_get_depth_texture")]
168 #[cfg(feature = "objc2-metal")]
169 #[inline]
170 pub unsafe fn depth_texture(
171 drawable: cp_drawable_t,
172 index: usize,
173 ) -> Retained<ProtocolObject<dyn MTLTexture>> {
174 extern "C-unwind" {
175 fn cp_drawable_get_depth_texture(
176 drawable: cp_drawable_t,
177 index: usize,
178 ) -> *mut ProtocolObject<dyn MTLTexture>;
179 }
180 let ret = unsafe { cp_drawable_get_depth_texture(drawable, index) };
181 unsafe { Retained::retain_autoreleased(ret) }
182 .expect("function was marked as returning non-null, but actually returned NULL")
183 }
184
185 /// Returns the color texture at the specified index in the drawable.
186 ///
187 /// - Parameters:
188 /// - drawable: The drawable for a frame.
189 /// - index: The index of the color texture you want. The index must
190 /// be greater than or equal to `0` and less than the value that
191 /// ``cp_drawable_get_texture_count`` returns.
192 /// - Returns: The Metal color texture at the specified index.
193 ///
194 /// Use the returned texture in your render pipeline to store the pixels
195 /// you want to appear onscreen. The layer’s texture topology determines
196 /// the layout and content for each texture. The drawable’s views contain
197 /// information about how those views map to the textures.
198 ///
199 /// # Safety
200 ///
201 /// `drawable` must be a valid pointer.
202 #[doc(alias = "cp_drawable_get_color_texture")]
203 #[cfg(feature = "objc2-metal")]
204 #[inline]
205 pub unsafe fn color_texture(
206 drawable: cp_drawable_t,
207 index: usize,
208 ) -> Retained<ProtocolObject<dyn MTLTexture>> {
209 extern "C-unwind" {
210 fn cp_drawable_get_color_texture(
211 drawable: cp_drawable_t,
212 index: usize,
213 ) -> *mut ProtocolObject<dyn MTLTexture>;
214 }
215 let ret = unsafe { cp_drawable_get_color_texture(drawable, index) };
216 unsafe { Retained::retain_autoreleased(ret) }
217 .expect("function was marked as returning non-null, but actually returned NULL")
218 }
219
220 /// Returns the tracking areas texture at the specified index in the drawable.
221 ///
222 /// - Parameters:
223 /// - drawable: The drawable for a frame.
224 /// - index: The index of the texture you want. The index must
225 /// be greater than or equal to `0` and less than the value that
226 /// ``cp_drawable_get_tracking_areas_texture_count`` returns.
227 /// - Returns: The Metal object index texture at the specified index.
228 ///
229 /// Use the returned texture in your render pipeline to store the tracking areas ID
230 /// used for hover effects and indirect gestures. The layer’s texture topology determines
231 /// the layout and content for each texture. The drawable’s views contain
232 /// information about how those views map to the textures.
233 ///
234 /// # Safety
235 ///
236 /// `drawable` must be a valid pointer.
237 #[doc(alias = "cp_drawable_get_tracking_areas_texture")]
238 #[cfg(feature = "objc2-metal")]
239 #[inline]
240 pub unsafe fn tracking_areas_texture(
241 drawable: cp_drawable_t,
242 index: usize,
243 ) -> Retained<ProtocolObject<dyn MTLTexture>> {
244 extern "C-unwind" {
245 fn cp_drawable_get_tracking_areas_texture(
246 drawable: cp_drawable_t,
247 index: usize,
248 ) -> *mut ProtocolObject<dyn MTLTexture>;
249 }
250 let ret = unsafe { cp_drawable_get_tracking_areas_texture(drawable, index) };
251 unsafe { Retained::retain_autoreleased(ret) }
252 .expect("function was marked as returning non-null, but actually returned NULL")
253 }
254
255 /// Returns a tracking area which is create on the drawable's list of tracking areas.
256 ///
257 /// - Parameters:
258 /// - drawable: The drawable for a frame.
259 /// - identifier: The unique identifier for the tracking area.
260 /// - Returns: A tracking area that was created.
261 ///
262 /// A tracking area describes a region of a view that interacts
263 /// with the gaze/cursor.
264 /// Cannot use ``cp_tracking_area_identifier_invalid`` as
265 /// an identifier.
266 ///
267 /// # Safety
268 ///
269 /// `drawable` must be a valid pointer.
270 #[doc(alias = "cp_drawable_add_tracking_area")]
271 #[cfg(feature = "tracking_area")]
272 #[inline]
273 pub unsafe fn add_tracking_area(
274 drawable: cp_drawable_t,
275 identifier: cp_tracking_area_identifier,
276 ) -> cp_tracking_area_t {
277 extern "C-unwind" {
278 fn cp_drawable_add_tracking_area(
279 drawable: cp_drawable_t,
280 identifier: cp_tracking_area_identifier,
281 ) -> cp_tracking_area_t;
282 }
283 unsafe { cp_drawable_add_tracking_area(drawable, identifier) }
284 }
285
286 /// Returns the number of rasterization rate maps associated with the
287 /// drawable.
288 ///
289 /// - Parameters:
290 /// - drawable: The drawable for a frame.
291 /// - Returns: The number of rasterization rate maps available for drawing.
292 ///
293 /// Use the returned value as the maximum number of rate maps to retrieve
294 /// from the ``cp_drawable_get_rasterization_rate_map`` function.
295 ///
296 /// # Safety
297 ///
298 /// `drawable` must be a valid pointer.
299 #[doc(alias = "cp_drawable_get_rasterization_rate_map_count")]
300 #[inline]
301 pub unsafe fn rasterization_rate_map_count(drawable: cp_drawable_t) -> usize {
302 extern "C-unwind" {
303 fn cp_drawable_get_rasterization_rate_map_count(drawable: cp_drawable_t) -> usize;
304 }
305 unsafe { cp_drawable_get_rasterization_rate_map_count(drawable) }
306 }
307
308 /// Returns the rasterization rate map at the specified index in the drawable.
309 ///
310 /// - Parameters:
311 /// - drawable: The drawable for a frame.
312 /// - index: The index of the rasterization rate map you want.
313 /// The index must be greater than or equal to `0` and less than the value
314 /// that ``cp_drawable_get_rasterization_rate_map_count`` returns.
315 /// - Returns: The rasterization rate map at the specified index.
316 ///
317 /// Apply the rasterization rate map to your render descriptor when you set
318 /// up your drawing environment. A rate map defines how the GPU scales
319 /// different parts of the texture to fill the screen. You use these rate
320 /// maps to save time and render less important parts of your scene at lower
321 /// resolutions. For example, when foveation is enabled, the drawable
322 /// includes a rasterization rate map to render the portions of the texture
323 /// in someone’s peripheral vision at a lower resolution.
324 ///
325 /// # Safety
326 ///
327 /// `drawable` must be a valid pointer.
328 #[doc(alias = "cp_drawable_get_rasterization_rate_map")]
329 #[cfg(feature = "objc2-metal")]
330 #[inline]
331 pub unsafe fn rasterization_rate_map(
332 drawable: cp_drawable_t,
333 index: usize,
334 ) -> Retained<ProtocolObject<dyn MTLRasterizationRateMap>> {
335 extern "C-unwind" {
336 fn cp_drawable_get_rasterization_rate_map(
337 drawable: cp_drawable_t,
338 index: usize,
339 ) -> *mut ProtocolObject<dyn MTLRasterizationRateMap>;
340 }
341 let ret = unsafe { cp_drawable_get_rasterization_rate_map(drawable, index) };
342 unsafe { Retained::retain_autoreleased(ret) }
343 .expect("function was marked as returning non-null, but actually returned NULL")
344 }
345
346 /// Returns the Y flipped rasterization rate map at the specified index in the drawable.
347 ///
348 /// - Parameters:
349 /// - drawable: The drawable for a frame.
350 /// - index: The index of the rasterization rate map you want.
351 /// The index must be greater than or equal to `0` and less than the value
352 /// that ``cp_drawable_get_rasterization_rate_map_count`` returns.
353 /// - Returns: The Y flipped rasterization rate map at the specified index.
354 ///
355 /// This function provides a Y flipped map that is generated form the ``cp_drawable_get_rasterization_rate_map``.
356 /// Flipped is defined as +Y = down for clip/normalized device coordinates (flipped from Metal).
357 /// If projection matrix is needed, use ``cp_drawable_compute_projection``
358 /// with a +Y = down axes convention to generate the correct matrix.
359 ///
360 /// Can only be used for intermediary render passes, the final render pass of the
361 /// drawable it cannot be flipped and must use Metal convention of +Y = up.
362 ///
363 /// Generating a flipped rasterization rate map will bring additional computational
364 /// cost to your render loop.
365 ///
366 /// In order to generate Y flipped rasterization rate maps in your rendering session,
367 /// update the ``cp_layer_renderer_configuration_t`` using the function
368 /// ``cp_layer_renderer_configuration_set_generate_flipped_rasterization_rate_maps``.
369 ///
370 /// # Safety
371 ///
372 /// `drawable` must be a valid pointer.
373 #[doc(alias = "cp_drawable_get_flipped_rasterization_rate_map")]
374 #[cfg(feature = "objc2-metal")]
375 #[inline]
376 pub unsafe fn flipped_rasterization_rate_map(
377 drawable: cp_drawable_t,
378 index: usize,
379 ) -> Retained<ProtocolObject<dyn MTLRasterizationRateMap>> {
380 extern "C-unwind" {
381 fn cp_drawable_get_flipped_rasterization_rate_map(
382 drawable: cp_drawable_t,
383 index: usize,
384 ) -> *mut ProtocolObject<dyn MTLRasterizationRateMap>;
385 }
386 let ret = unsafe { cp_drawable_get_flipped_rasterization_rate_map(drawable, index) };
387 unsafe { Retained::retain_autoreleased(ret) }
388 .expect("function was marked as returning non-null, but actually returned NULL")
389 }
390
391 /// Returns the number of separate views to draw for the frame.
392 ///
393 /// - Parameters:
394 /// - drawable: The drawable for a frame.
395 /// - Returns: The number of separate views to draw.
396 ///
397 /// The number of views corresponds to the number of separate versions
398 /// of your scene you create for the frame. For a device with stereoscopic
399 /// video, you render two views — one for each eye. The actual number of
400 /// views can vary based on the drawing environment or your app’s
401 /// configuration. For example, you typically render only one view in
402 /// Simulator.
403 ///
404 /// Fetch the actual views using the ``cp_drawable_get_view`` function.
405 ///
406 /// # Safety
407 ///
408 /// `drawable` must be a valid pointer.
409 #[doc(alias = "cp_drawable_get_view_count")]
410 #[inline]
411 pub unsafe fn view_count(drawable: cp_drawable_t) -> usize {
412 extern "C-unwind" {
413 fn cp_drawable_get_view_count(drawable: cp_drawable_t) -> usize;
414 }
415 unsafe { cp_drawable_get_view_count(drawable) }
416 }
417
418 /// Returns the specified view from the drawable.
419 ///
420 /// - Parameters:
421 /// - drawable: The drawable for a frame.
422 /// - index: The index of the view you want. The index must be
423 /// greater than or equal to 0 and less than the value that
424 /// ``cp_drawable_get_view_count`` returns.
425 /// - Returns: The view at the specified index.
426 ///
427 /// Each view contains information you need to render into the drawable’s
428 /// textures.
429 ///
430 /// # Safety
431 ///
432 /// `drawable` must be a valid pointer.
433 #[doc(alias = "cp_drawable_get_view")]
434 #[cfg(feature = "view")]
435 #[inline]
436 pub unsafe fn view(drawable: cp_drawable_t, index: usize) -> cp_view_t {
437 extern "C-unwind" {
438 fn cp_drawable_get_view(drawable: cp_drawable_t, index: usize) -> cp_view_t;
439 }
440 unsafe { cp_drawable_get_view(drawable, index) }
441 }
442
443 /// Encodes a notification event to the specified command buffer to present
444 /// the drawable’s content onscreen.
445 ///
446 /// - Parameters:
447 /// - drawable: The drawable for a frame.
448 /// - command_buffer: The command buffer you used to encode your
449 /// frame’s content. If the command buffer is already committed,
450 /// this function aborts your app with an error.
451 ///
452 /// - Note: Commit the command buffer after calling present.
453 ///
454 /// Call this function as the last step before committing the specified
455 /// command buffer. Specifically, call it after you finish encoding all
456 /// the work required to render the frame, and immediately before you
457 /// call the command buffer’s
458 /// <doc
459 /// ://com.apple.documentation/documentation/metal/mtlcommandbuffer/1443003-commit>
460 /// method. The function adds a presentation event to the buffer that
461 /// causes the compositor to display your frame.
462 ///
463 /// # Safety
464 ///
465 /// `drawable` must be a valid pointer.
466 #[doc(alias = "cp_drawable_encode_present")]
467 #[cfg(feature = "objc2-metal")]
468 #[inline]
469 pub unsafe fn encode_present(
470 drawable: cp_drawable_t,
471 command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
472 ) {
473 extern "C-unwind" {
474 fn cp_drawable_encode_present(
475 drawable: cp_drawable_t,
476 command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
477 );
478 }
479 unsafe { cp_drawable_encode_present(drawable, command_buffer) }
480 }
481
482 /// Encodes a notification event to the specified command buffer to present
483 /// the drawable’s content onscreen.
484 ///
485 /// - Parameters:
486 /// - drawable: The drawable for a frame.
487 ///
488 /// - Note: Commit the command buffer to the layer queue before calling present.
489 ///
490 /// Call this function as the last step before committing the specified
491 /// command buffer. Specifically, call it after you finish encoding all
492 /// the work required to render the frame, and immediately before you
493 /// call the command buffer’s
494 /// <doc
495 /// ://com.apple.documentation/documentation/metal/mtlcommandbuffer/1443003-commit>
496 /// method. The function adds a presentation event to the buffer that
497 /// causes the compositor to display your frame.
498 ///
499 /// # Safety
500 ///
501 /// `drawable` must be a valid pointer.
502 #[doc(alias = "cp_drawable_mtl4_encode_present")]
503 #[inline]
504 pub unsafe fn mtl4_encode_present(drawable: cp_drawable_t) {
505 extern "C-unwind" {
506 fn cp_drawable_mtl4_encode_present(drawable: cp_drawable_t);
507 }
508 unsafe { cp_drawable_mtl4_encode_present(drawable) }
509 }
510
511 /// Returns a value that indicates the current operational state
512 /// of the drawable type.
513 ///
514 /// - Parameters: The drawable to check.
515 /// - Returns: ``cp_drawable_state/cp_drawable_state_rendering`` if the
516 /// drawable type is ready for you to draw your content, or any other value if
517 /// the compositor currently owns the drawable.
518 ///
519 /// Compositor reuses the underlying data structures associated with
520 /// drawable types, and the state of the drawable indicates whether
521 /// it's ready for you to use. Perform your drawing operations only
522 /// when the drawable is in the ``cp_drawable_state/cp_drawable_state_rendering`` state.
523 ///
524 /// # Safety
525 ///
526 /// `drawable` must be a valid pointer.
527 #[doc(alias = "cp_drawable_get_state")]
528 #[inline]
529 pub unsafe fn state(drawable: cp_drawable_t) -> cp_drawable_state {
530 extern "C-unwind" {
531 fn cp_drawable_get_state(drawable: cp_drawable_t) -> cp_drawable_state;
532 }
533 unsafe { cp_drawable_get_state(drawable) }
534 }
535
536 /// Returns a value that indicates the target of the drawable type.
537 ///
538 /// - Parameters: The drawable to check.
539 /// - Returns: ``cp_drawable_target/cp_drawable_target_built_in`` if the
540 /// drawable will be displayed for the user in the device, or any other value if the drawable
541 /// maybe used for other purposes.
542 ///
543 /// When drawing for the drawable this can be used to alter
544 /// what is rendered for different targets.
545 /// Renderer should always prioritize ``cp_drawable_target/cp_drawable_target_built_in``
546 /// target type.
547 ///
548 /// # Safety
549 ///
550 /// `drawable` must be a valid pointer.
551 #[doc(alias = "cp_drawable_get_target")]
552 #[inline]
553 pub unsafe fn target(drawable: cp_drawable_t) -> cp_drawable_target {
554 extern "C-unwind" {
555 fn cp_drawable_get_target(drawable: cp_drawable_t) -> cp_drawable_target;
556 }
557 unsafe { cp_drawable_get_target(drawable) }
558 }
559
560 /// Returns the index of the frame of content for you to produce.
561 ///
562 /// - Parameters:
563 /// - drawable: The drawable for a frame.
564 /// - Returns: The presentation index of the frame.
565 ///
566 /// When your compositor scene becomes visible, you start drawing
567 /// frames of content. The compositor assigns a sequential index to
568 /// each frame to indicate its position in the final output. You can
569 /// use these indexes to differentiate frames during drawing or predict
570 /// future frame indexes. For example, you might start playback of an
571 /// audio file when a specific frame appears onscreen.
572 ///
573 /// # Safety
574 ///
575 /// `drawable` must be a valid pointer.
576 #[doc(alias = "cp_drawable_get_presentation_frame_index")]
577 #[cfg(feature = "cp_types")]
578 #[inline]
579 pub unsafe fn presentation_frame_index(drawable: cp_drawable_t) -> cp_compositor_frame_index_t {
580 extern "C-unwind" {
581 fn cp_drawable_get_presentation_frame_index(
582 drawable: cp_drawable_t,
583 ) -> cp_compositor_frame_index_t;
584 }
585 unsafe { cp_drawable_get_presentation_frame_index(drawable) }
586 }
587
588 /// Returns the timing information for the frame of the specified drawable.
589 ///
590 /// - Parameters:
591 /// - drawable: The drawable for a frame.
592 /// - Returns: The timing information for the drawable’s associated frame.
593 ///
594 /// Pass the returned type to the ``cp_frame_timing_get_optimal_input_time``
595 /// function to determine when to start the encoding process for a frame.
596 /// Pass it to other functions to determine other time-related deadlines.
597 ///
598 /// # Safety
599 ///
600 /// `drawable` must be a valid pointer.
601 #[doc(alias = "cp_drawable_get_frame_timing")]
602 #[cfg(feature = "frame_timing")]
603 #[inline]
604 pub unsafe fn frame_timing(drawable: cp_drawable_t) -> cp_frame_timing_t {
605 extern "C-unwind" {
606 fn cp_drawable_get_frame_timing(drawable: cp_drawable_t) -> cp_frame_timing_t;
607 }
608 unsafe { cp_drawable_get_frame_timing(drawable) }
609 }
610
611 /// Returns whether content capture is protected and it is safe to
612 /// draw content that should be protected from capture.
613 ///
614 /// - Parameters:
615 /// - drawable: The drawable for a frame.
616 /// - Returns: Whether it is safe to draw content that is for built-in
617 /// display only. When this value is true, any capture of content
618 /// being displayed on the built-in display will be obscured by the
619 /// system. If false, it cannot be assumed that content will not
620 /// be seen by users outside of the device, both live and recorded.
621 ///
622 /// Use this function to ensure that drawing that is only meant for
623 /// eyes in the device is not drawn when false.
624 /// Only adopt if app has adopted SwiftUI `activatesContentCaptureProtected`
625 /// scene modifier and drawing will have content that is not desired
626 /// to meant to be captured.
627 /// For ``cp_drawable_target_capture`` this will
628 /// always return false as it is upto the renderer to handle drawing
629 /// content that will be captured beyond the built-in displays.
630 ///
631 /// # Safety
632 ///
633 /// `drawable` must be a valid pointer.
634 #[doc(alias = "cp_drawable_is_content_capture_protected")]
635 #[inline]
636 pub unsafe fn is_content_capture_protected(drawable: cp_drawable_t) -> bool {
637 extern "C-unwind" {
638 fn cp_drawable_is_content_capture_protected(drawable: cp_drawable_t) -> bool;
639 }
640 unsafe { cp_drawable_is_content_capture_protected(drawable) }
641 }
642
643 /// Adds a render context to a drawable.
644 /// This object will draw any content that the compositor needs to render
645 /// in the application.
646 /// - Note: The render context can only be used when the layer renderer is using layered layout
647 /// or in platforms that only render one view (ex: simulator)
648 ///
649 /// - Note: The render context makes use of the device_anchor set in
650 /// ``cp_drawable_set_device_anchor`` the device_anchor should be set in the
651 /// drawable before calling ``cp_drawable_add_render_context``.
652 ///
653 /// # Safety
654 ///
655 /// `drawable` must be a valid pointer.
656 #[doc(alias = "cp_drawable_add_render_context")]
657 #[cfg(all(feature = "drawable_render_context", feature = "objc2-metal"))]
658 #[inline]
659 pub unsafe fn add_render_context(
660 drawable: cp_drawable_t,
661 cmd_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
662 ) -> cp_drawable_render_context_t {
663 extern "C-unwind" {
664 fn cp_drawable_add_render_context(
665 drawable: cp_drawable_t,
666 cmd_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
667 ) -> cp_drawable_render_context_t;
668 }
669 unsafe { cp_drawable_add_render_context(drawable, cmd_buffer) }
670 }
671
672 /// Adds a render context to a drawable.
673 /// This object will draw any content that the compositor needs to render
674 /// in the application.
675 /// - Note: The render context can only be used when the layer renderer is using layered layout
676 /// or in platforms that only render one view (ex: simulator)
677 ///
678 /// - Note: The render context makes use of the device_anchor set in
679 /// ``cp_drawable_set_device_anchor`` the device_anchor should be set in the
680 /// drawable before calling ``cp_drawable_add_render_context``.
681 ///
682 /// # Safety
683 ///
684 /// `drawable` must be a valid pointer.
685 #[doc(alias = "cp_drawable_add_mtl4_render_context")]
686 #[cfg(feature = "drawable_render_context")]
687 #[inline]
688 pub unsafe fn add_mtl4_render_context(drawable: cp_drawable_t) -> cp_drawable_render_context_t {
689 extern "C-unwind" {
690 fn cp_drawable_add_mtl4_render_context(
691 drawable: cp_drawable_t,
692 ) -> cp_drawable_render_context_t;
693 }
694 unsafe { cp_drawable_add_mtl4_render_context(drawable) }
695 }
696}
697
698/// [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_drawable_array?language=objc)
699#[repr(C)]
700#[derive(Debug)]
701pub struct cp_drawable_array {
702 inner: [u8; 0],
703 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
704}
705
706unsafe impl RefEncode for cp_drawable_array {
707 const ENCODING_REF: Encoding = Encoding::Pointer(&Encoding::Struct("cp_drawable_array", &[]));
708}
709
710/// An opaque type that contains the drawable types and other information
711/// you need to set up your render pipeline.
712///
713/// See ``cp_drawable_t`` for more information about drawables.
714///
715/// See also [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_drawable_array_t?language=objc)
716pub type cp_drawable_array_t = *mut cp_drawable_array;
717
718impl cp_drawable_array {
719 /// Returns the drawable at the specified index in the array.
720 ///
721 /// - Parameters:
722 /// - drawable_array: The drawable array for a frame.
723 /// - index: The index of the drawable you want. The index must
724 /// be greater than or equal to `0` and less than the value that
725 /// ``cp_drawable_array_get_count`` returns.
726 /// - Returns: The drawable available for drawing at the specified index.
727 ///
728 /// The ``cp_drawable_t`` type contains the textures and other
729 /// information you need to set up your render descriptor in Metal.
730 ///
731 /// # Safety
732 ///
733 /// `drawable_array` must be a valid pointer.
734 #[doc(alias = "cp_drawable_array_get_drawable")]
735 #[inline]
736 pub unsafe fn drawable(drawable_array: cp_drawable_array_t, index: usize) -> cp_drawable_t {
737 extern "C-unwind" {
738 fn cp_drawable_array_get_drawable(
739 drawable_array: cp_drawable_array_t,
740 index: usize,
741 ) -> cp_drawable_t;
742 }
743 unsafe { cp_drawable_array_get_drawable(drawable_array, index) }
744 }
745
746 /// Returns the number of drawables in the array.
747 ///
748 /// - Parameters:
749 /// - drawable_array: The drawable array for a frame.
750 /// - Returns: The number of drawables available for drawing. For example, a return
751 /// value of `2` indicates there are two drawables for this frame.
752 ///
753 /// Use the returned value as the maximum number of textures to retrieve
754 /// from the ``cp_drawable_array_get_drawable`` functions.
755 ///
756 /// # Safety
757 ///
758 /// `drawable_array` must be a valid pointer.
759 #[doc(alias = "cp_drawable_array_get_count")]
760 #[inline]
761 pub unsafe fn count(drawable_array: cp_drawable_array_t) -> usize {
762 extern "C-unwind" {
763 fn cp_drawable_array_get_count(drawable_array: cp_drawable_array_t) -> usize;
764 }
765 unsafe { cp_drawable_array_get_count(drawable_array) }
766 }
767}
768
769extern "C-unwind" {
770 #[deprecated = "renamed to `cp_drawable::texture_count`"]
771 pub fn cp_drawable_get_texture_count(drawable: cp_drawable_t) -> usize;
772}
773
774extern "C-unwind" {
775 #[deprecated = "renamed to `cp_drawable::tracking_areas_texture_count`"]
776 pub fn cp_drawable_get_tracking_areas_texture_count(drawable: cp_drawable_t) -> usize;
777}
778
779#[cfg(feature = "objc2-metal")]
780#[deprecated = "renamed to `cp_drawable::depth_texture`"]
781#[inline]
782pub unsafe extern "C-unwind" fn cp_drawable_get_depth_texture(
783 drawable: cp_drawable_t,
784 index: usize,
785) -> Retained<ProtocolObject<dyn MTLTexture>> {
786 extern "C-unwind" {
787 fn cp_drawable_get_depth_texture(
788 drawable: cp_drawable_t,
789 index: usize,
790 ) -> *mut ProtocolObject<dyn MTLTexture>;
791 }
792 let ret = unsafe { cp_drawable_get_depth_texture(drawable, index) };
793 unsafe { Retained::retain_autoreleased(ret) }
794 .expect("function was marked as returning non-null, but actually returned NULL")
795}
796
797#[cfg(feature = "objc2-metal")]
798#[deprecated = "renamed to `cp_drawable::color_texture`"]
799#[inline]
800pub unsafe extern "C-unwind" fn cp_drawable_get_color_texture(
801 drawable: cp_drawable_t,
802 index: usize,
803) -> Retained<ProtocolObject<dyn MTLTexture>> {
804 extern "C-unwind" {
805 fn cp_drawable_get_color_texture(
806 drawable: cp_drawable_t,
807 index: usize,
808 ) -> *mut ProtocolObject<dyn MTLTexture>;
809 }
810 let ret = unsafe { cp_drawable_get_color_texture(drawable, index) };
811 unsafe { Retained::retain_autoreleased(ret) }
812 .expect("function was marked as returning non-null, but actually returned NULL")
813}
814
815#[cfg(feature = "objc2-metal")]
816#[deprecated = "renamed to `cp_drawable::tracking_areas_texture`"]
817#[inline]
818pub unsafe extern "C-unwind" fn cp_drawable_get_tracking_areas_texture(
819 drawable: cp_drawable_t,
820 index: usize,
821) -> Retained<ProtocolObject<dyn MTLTexture>> {
822 extern "C-unwind" {
823 fn cp_drawable_get_tracking_areas_texture(
824 drawable: cp_drawable_t,
825 index: usize,
826 ) -> *mut ProtocolObject<dyn MTLTexture>;
827 }
828 let ret = unsafe { cp_drawable_get_tracking_areas_texture(drawable, index) };
829 unsafe { Retained::retain_autoreleased(ret) }
830 .expect("function was marked as returning non-null, but actually returned NULL")
831}
832
833extern "C-unwind" {
834 #[cfg(feature = "tracking_area")]
835 #[deprecated = "renamed to `cp_drawable::add_tracking_area`"]
836 pub fn cp_drawable_add_tracking_area(
837 drawable: cp_drawable_t,
838 identifier: cp_tracking_area_identifier,
839 ) -> cp_tracking_area_t;
840}
841
842extern "C-unwind" {
843 #[deprecated = "renamed to `cp_drawable::rasterization_rate_map_count`"]
844 pub fn cp_drawable_get_rasterization_rate_map_count(drawable: cp_drawable_t) -> usize;
845}
846
847#[cfg(feature = "objc2-metal")]
848#[deprecated = "renamed to `cp_drawable::rasterization_rate_map`"]
849#[inline]
850pub unsafe extern "C-unwind" fn cp_drawable_get_rasterization_rate_map(
851 drawable: cp_drawable_t,
852 index: usize,
853) -> Retained<ProtocolObject<dyn MTLRasterizationRateMap>> {
854 extern "C-unwind" {
855 fn cp_drawable_get_rasterization_rate_map(
856 drawable: cp_drawable_t,
857 index: usize,
858 ) -> *mut ProtocolObject<dyn MTLRasterizationRateMap>;
859 }
860 let ret = unsafe { cp_drawable_get_rasterization_rate_map(drawable, index) };
861 unsafe { Retained::retain_autoreleased(ret) }
862 .expect("function was marked as returning non-null, but actually returned NULL")
863}
864
865#[cfg(feature = "objc2-metal")]
866#[deprecated = "renamed to `cp_drawable::flipped_rasterization_rate_map`"]
867#[inline]
868pub unsafe extern "C-unwind" fn cp_drawable_get_flipped_rasterization_rate_map(
869 drawable: cp_drawable_t,
870 index: usize,
871) -> Retained<ProtocolObject<dyn MTLRasterizationRateMap>> {
872 extern "C-unwind" {
873 fn cp_drawable_get_flipped_rasterization_rate_map(
874 drawable: cp_drawable_t,
875 index: usize,
876 ) -> *mut ProtocolObject<dyn MTLRasterizationRateMap>;
877 }
878 let ret = unsafe { cp_drawable_get_flipped_rasterization_rate_map(drawable, index) };
879 unsafe { Retained::retain_autoreleased(ret) }
880 .expect("function was marked as returning non-null, but actually returned NULL")
881}
882
883extern "C-unwind" {
884 #[deprecated = "renamed to `cp_drawable::view_count`"]
885 pub fn cp_drawable_get_view_count(drawable: cp_drawable_t) -> usize;
886}
887
888extern "C-unwind" {
889 #[cfg(feature = "view")]
890 #[deprecated = "renamed to `cp_drawable::view`"]
891 pub fn cp_drawable_get_view(drawable: cp_drawable_t, index: usize) -> cp_view_t;
892}
893
894extern "C-unwind" {
895 #[cfg(feature = "objc2-metal")]
896 #[deprecated = "renamed to `cp_drawable::encode_present`"]
897 pub fn cp_drawable_encode_present(
898 drawable: cp_drawable_t,
899 command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
900 );
901}
902
903extern "C-unwind" {
904 #[deprecated = "renamed to `cp_drawable::mtl4_encode_present`"]
905 pub fn cp_drawable_mtl4_encode_present(drawable: cp_drawable_t);
906}
907
908extern "C-unwind" {
909 #[deprecated = "renamed to `cp_drawable::state`"]
910 pub fn cp_drawable_get_state(drawable: cp_drawable_t) -> cp_drawable_state;
911}
912
913extern "C-unwind" {
914 #[deprecated = "renamed to `cp_drawable::target`"]
915 pub fn cp_drawable_get_target(drawable: cp_drawable_t) -> cp_drawable_target;
916}
917
918extern "C-unwind" {
919 #[cfg(feature = "cp_types")]
920 #[deprecated = "renamed to `cp_drawable::presentation_frame_index`"]
921 pub fn cp_drawable_get_presentation_frame_index(
922 drawable: cp_drawable_t,
923 ) -> cp_compositor_frame_index_t;
924}
925
926extern "C-unwind" {
927 #[cfg(feature = "frame_timing")]
928 #[deprecated = "renamed to `cp_drawable::frame_timing`"]
929 pub fn cp_drawable_get_frame_timing(drawable: cp_drawable_t) -> cp_frame_timing_t;
930}
931
932extern "C-unwind" {
933 #[deprecated = "renamed to `cp_drawable::is_content_capture_protected`"]
934 pub fn cp_drawable_is_content_capture_protected(drawable: cp_drawable_t) -> bool;
935}
936
937extern "C-unwind" {
938 #[cfg(all(feature = "drawable_render_context", feature = "objc2-metal"))]
939 #[deprecated = "renamed to `cp_drawable::add_render_context`"]
940 pub fn cp_drawable_add_render_context(
941 drawable: cp_drawable_t,
942 cmd_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
943 ) -> cp_drawable_render_context_t;
944}
945
946extern "C-unwind" {
947 #[cfg(feature = "drawable_render_context")]
948 #[deprecated = "renamed to `cp_drawable::add_mtl4_render_context`"]
949 pub fn cp_drawable_add_mtl4_render_context(
950 drawable: cp_drawable_t,
951 ) -> cp_drawable_render_context_t;
952}
953
954extern "C-unwind" {
955 #[deprecated = "renamed to `cp_drawable_array::drawable`"]
956 pub fn cp_drawable_array_get_drawable(
957 drawable_array: cp_drawable_array_t,
958 index: usize,
959 ) -> cp_drawable_t;
960}
961
962extern "C-unwind" {
963 #[deprecated = "renamed to `cp_drawable_array::count`"]
964 pub fn cp_drawable_array_get_count(drawable_array: cp_drawable_array_t) -> usize;
965}