objc2_compositor_services/generated/layer_renderer.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-metal")]
7use objc2_metal::*;
8
9use crate::*;
10
11/// The potential states of the layer renderer, which tell you how to
12/// proceed with drawing operations.
13///
14/// See also [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_layer_renderer_state?language=objc)
15// NS_ENUM
16#[repr(transparent)]
17#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
18pub struct cp_layer_renderer_state(pub u32);
19impl cp_layer_renderer_state {
20 /// A state that indicates the layer renderer isn't currently drawing.
21 ///
22 /// A layer renderer starts in this state and later transitions to the
23 /// running or invalid states. Don't draw while in this state.
24 /// Wait until the layer changes to one of the other states to
25 /// take further action on the layer.
26 #[doc(alias = "cp_layer_renderer_state_paused")]
27 pub const paused: Self = Self(1);
28 /// A state that indicates the layer renderer is ready for you to draw
29 /// your content.
30 ///
31 /// When the layer enters this state, start your rendering loop
32 /// and draw your content. Keep drawing frames of content until
33 /// the layer transitions to another state.
34 #[doc(alias = "cp_layer_renderer_state_running")]
35 pub const running: Self = Self(2);
36 /// A state that indicates the layer renderer no longer supports drawing
37 /// operations.
38 ///
39 /// A layer enters this state shortly before the system releases
40 /// its resources. When the layer enters this state, exit your
41 /// rendering loop and release any drawing-related structures.
42 #[doc(alias = "cp_layer_renderer_state_invalidated")]
43 pub const invalidated: Self = Self(3);
44}
45
46unsafe impl Encode for cp_layer_renderer_state {
47 const ENCODING: Encoding = u32::ENCODING;
48}
49
50unsafe impl RefEncode for cp_layer_renderer_state {
51 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
52}
53
54extern_class!(
55 /// An opaque type that provides the Metal types and timing
56 /// information you need to draw your content.
57 ///
58 /// See also [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_object_cp_layer_renderer?language=objc)
59 #[unsafe(super(NSObject))]
60 #[derive(Debug, PartialEq, Eq, Hash)]
61 pub struct CP_OBJECT_cp_layer_renderer;
62);
63
64extern_conformance!(
65 unsafe impl NSObjectProtocol for CP_OBJECT_cp_layer_renderer {}
66);
67
68impl CP_OBJECT_cp_layer_renderer {
69 extern_methods!(
70 #[unsafe(method(init))]
71 #[unsafe(method_family = init)]
72 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
73
74 #[unsafe(method(new))]
75 #[unsafe(method_family = new)]
76 pub unsafe fn new() -> Retained<Self>;
77 );
78}
79
80/// An opaque type that provides the Metal types and timing
81/// information you need to draw your content.
82///
83/// See also [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_layer_renderer_t?language=objc)
84pub type cp_layer_renderer_t = CP_OBJECT_cp_layer_renderer;
85
86/// Returns the configuration details you used to create the
87/// specified layer.
88///
89/// - Parameters layer_renderer: The layer renderer to query.
90/// - Returns: An opaque type you use to retrieve the configuration details.
91///
92/// Provide a custom ``LayerStageConfiguration`` to provide the initial
93/// configuration details for the layer. After the system creates the layer, use this
94/// function to retrieve those details. The system uses this information during the
95/// initial setup of the layer's data structures. Changes you make to the
96/// returned structure don't affect the layer's current configuration.
97#[cfg(feature = "layer_renderer_configuration")]
98#[inline]
99pub unsafe extern "C-unwind" fn cp_layer_renderer_get_configuration(
100 layer_renderer: &cp_layer_renderer_t,
101) -> Retained<cp_layer_renderer_configuration_t> {
102 extern "C-unwind" {
103 fn cp_layer_renderer_get_configuration(
104 layer_renderer: &cp_layer_renderer_t,
105 ) -> *mut cp_layer_renderer_configuration_t;
106 }
107 let ret = unsafe { cp_layer_renderer_get_configuration(layer_renderer) };
108 unsafe { Retained::retain_autoreleased(ret) }
109 .expect("function was marked as returning non-null, but actually returned NULL")
110}
111
112/// Returns the configured properties of the specified layer renderer.
113///
114/// - Parameters layer_renderer: The layer renderer to query.
115/// - Returns: An opaque type you can use to fetch the individual
116/// layer properties.
117///
118/// The layer properties include details about the layer's textures,
119/// such as their organization and the location of drawable views in those
120/// textures.
121#[cfg(feature = "layer_renderer_properties")]
122#[inline]
123pub unsafe extern "C-unwind" fn cp_layer_renderer_get_properties(
124 layer_renderer: &cp_layer_renderer_t,
125) -> Retained<cp_layer_renderer_properties_t> {
126 extern "C-unwind" {
127 fn cp_layer_renderer_get_properties(
128 layer_renderer: &cp_layer_renderer_t,
129 ) -> *mut cp_layer_renderer_properties_t;
130 }
131 let ret = unsafe { cp_layer_renderer_get_properties(layer_renderer) };
132 unsafe { Retained::retain_autoreleased(ret) }
133 .expect("function was marked as returning non-null, but actually returned NULL")
134}
135
136/// Returns the GPU interface that the layer uses for drawing operations.
137///
138/// - Parameters layer_renderer: The layer renderer to query.
139/// - Returns: The Metal device to use for your drawing operations.
140///
141/// You can inspect the returned device for any information you might need.
142/// The system uses the returned device to create the textures you use for
143/// drawing. It also uses the device to create synchronization events for
144/// the layer.
145#[cfg(feature = "objc2-metal")]
146#[inline]
147pub unsafe extern "C-unwind" fn cp_layer_renderer_get_device(
148 layer_renderer: &cp_layer_renderer_t,
149) -> Retained<ProtocolObject<dyn MTLDevice>> {
150 extern "C-unwind" {
151 fn cp_layer_renderer_get_device(
152 layer_renderer: &cp_layer_renderer_t,
153 ) -> *mut ProtocolObject<dyn MTLDevice>;
154 }
155 let ret = unsafe { cp_layer_renderer_get_device(layer_renderer) };
156 unsafe { Retained::retain_autoreleased(ret) }
157 .expect("function was marked as returning non-null, but actually returned NULL")
158}
159
160extern "C-unwind" {
161 /// Returns the layer's current state, which indicates whether the layer is
162 /// visible and ready for you to draw content.
163 ///
164 /// - Parameters layer_renderer: The layer renderer to query.
165 /// - Returns: The current state of the layer.
166 ///
167 /// Use the layer's state value to determine when to start and stop your
168 /// rendering loop. Draw content only when the layer is in the
169 /// ``cp_layer_renderer/cp_layer_renderer_state_running`` state. Stop your rendering loop when
170 /// the layer enters other states. When the layer reaches the
171 /// ``cp_layer_renderer/cp_layer_renderer_state_invalidated`` state, it's safe to
172 /// clean up and deallocate your render loop structures.
173 pub fn cp_layer_renderer_get_state(
174 layer_renderer: &cp_layer_renderer_t,
175 ) -> cp_layer_renderer_state;
176}
177
178extern "C-unwind" {
179 /// Stops further execution of your code until the layer renderer leaves
180 /// the paused state.
181 ///
182 /// - Parameters layer_renderer: The layer renderer to monitor. If the layer isn't
183 /// in the ``cp_layer_renderer/cp_layer_renderer_state_paused`` state, this function returns
184 /// immediately.
185 ///
186 /// Call this function to let the system handle events while
187 /// you wait for the layer renderer to become ready. The function services
188 /// incoming layer-related events until the layer exits the paused
189 /// state.
190 pub fn cp_layer_renderer_wait_until_running(layer_renderer: &cp_layer_renderer_t);
191}
192
193extern "C-unwind" {
194 /// Returns the next frame to use for drawing.
195 ///
196 /// - Parameters layer_renderer: The layer renderer that manages the drawing destination.
197 ///
198 /// - Returns: An opaque type to use for drawing operations. The function
199 /// returns `nil` if the layer is paused, invalidated, or has too many frames
200 /// already in use.
201 ///
202 /// This function retrieves the next frame for you to use in your drawing
203 /// operations. The system maintains a limited number of frames, so don't try
204 /// to render more than one frame in advance. If this function returns `nil`,
205 /// wait a short time and try again. After the system draws the current frame,
206 /// it returns that frame to the shared pool and makes it available for you
207 /// to use.
208 ///
209 /// The index of each returned frame is always greater than the index of the
210 /// previous frame. The system increments index values sequentially so you
211 /// can differentiate frames you are currently drawing.
212 #[cfg(feature = "frame")]
213 pub fn cp_layer_renderer_query_next_frame(layer_renderer: &cp_layer_renderer_t) -> cp_frame_t;
214}
215
216extern "C-unwind" {
217 /// Return how many times a frame is repeated on display. This is typically used to
218 /// build dynamic frame pacing.
219 ///
220 /// - Parameters layer_renderer: The layer on which you're drawing.
221 ///
222 /// - Returns: The repeat count. If the repeat count is set to a value greater or equal to 1, it means this
223 /// layer repeated the client frame `repeat count` times, effectively multiplying the
224 /// frame duration by `repeat count + 1`.
225 ///
226 /// Lowering the number of frames being rendered every second will decrease the power usage per frame.
227 /// This value should only be increased if appropriate for the content being rendered.
228 pub fn cp_layer_renderer_get_minimum_frame_repeat_count(
229 layer_renderer: &cp_layer_renderer_t,
230 ) -> c_int;
231}
232
233extern "C-unwind" {
234 /// Set the frame repeat count. This is typically used to build dynamic frame pacing.
235 ///
236 /// - Parameters:
237 /// - layer_renderer: The layer on which you're drawing.
238 /// - frame_repeat_count: How many times a frame is repeated on display.
239 ///
240 /// If the repeat count is set to a value greater or equal to 1, it means this
241 /// layer repeats the client frame `repeat count` times, effectively multiplying the
242 /// frame duration by `repeat count + 1`.
243 ///
244 /// Lowering the number of frames being rendered every second will decrease the power usage per frame.
245 /// This value should only be increased if appropriate for the content being rendered.
246 pub fn cp_layer_renderer_set_minimum_frame_repeat_count(
247 layer_renderer: &cp_layer_renderer_t,
248 frame_repeat_count: c_int,
249 );
250}