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
160/// Returns the command queue that the layer uses for drawing operations.
161///
162/// - Parameters layer_renderer: The layer renderer to query.
163///
164/// Should only be called with when supporting Metal4 through configuration.
165/// ``cp_layer_renderer_configuration_set_supports_mtl4``
166#[cfg(feature = "objc2-metal")]
167#[inline]
168pub unsafe extern "C-unwind" fn cp_layer_renderer_get_mtl4_command_queue(
169 layer_renderer: &cp_layer_renderer_t,
170) -> Retained<ProtocolObject<dyn MTL4CommandQueue>> {
171 extern "C-unwind" {
172 fn cp_layer_renderer_get_mtl4_command_queue(
173 layer_renderer: &cp_layer_renderer_t,
174 ) -> *mut ProtocolObject<dyn MTL4CommandQueue>;
175 }
176 let ret = unsafe { cp_layer_renderer_get_mtl4_command_queue(layer_renderer) };
177 unsafe { Retained::retain_autoreleased(ret) }
178 .expect("function was marked as returning non-null, but actually returned NULL")
179}
180
181extern "C-unwind" {
182 /// Returns the layer's current state, which indicates whether the layer is
183 /// visible and ready for you to draw content.
184 ///
185 /// - Parameters layer_renderer: The layer renderer to query.
186 /// - Returns: The current state of the layer.
187 ///
188 /// Use the layer's state value to determine when to start and stop your
189 /// rendering loop. Draw content only when the layer is in the
190 /// ``cp_layer_renderer/cp_layer_renderer_state_running`` state. Stop your rendering loop when
191 /// the layer enters other states. When the layer reaches the
192 /// ``cp_layer_renderer/cp_layer_renderer_state_invalidated`` state, it's safe to
193 /// clean up and deallocate your render loop structures.
194 pub fn cp_layer_renderer_get_state(
195 layer_renderer: &cp_layer_renderer_t,
196 ) -> cp_layer_renderer_state;
197}
198
199extern "C-unwind" {
200 /// Stops further execution of your code until the layer renderer leaves
201 /// the paused state.
202 ///
203 /// - Parameters layer_renderer: The layer renderer to monitor. If the layer isn't
204 /// in the ``cp_layer_renderer/cp_layer_renderer_state_paused`` state, this function returns
205 /// immediately.
206 ///
207 /// Call this function to let the system handle events while
208 /// you wait for the layer renderer to become ready. The function services
209 /// incoming layer-related events until the layer exits the paused
210 /// state.
211 pub fn cp_layer_renderer_wait_until_running(layer_renderer: &cp_layer_renderer_t);
212}
213
214extern "C-unwind" {
215 /// Returns the next frame to use for drawing.
216 ///
217 /// - Parameters layer_renderer: The layer renderer that manages the drawing destination.
218 ///
219 /// - Returns: An opaque type to use for drawing operations. The function
220 /// returns `nil` if the layer is paused, invalidated, or has too many frames
221 /// already in use.
222 ///
223 /// This function retrieves the next frame for you to use in your drawing
224 /// operations. The system maintains a limited number of frames, so don't try
225 /// to render more than one frame in advance. If this function returns `nil`,
226 /// wait a short time and try again. After the system draws the current frame,
227 /// it returns that frame to the shared pool and makes it available for you
228 /// to use.
229 ///
230 /// The index of each returned frame is always greater than the index of the
231 /// previous frame. The system increments index values sequentially so you
232 /// can differentiate frames you are currently drawing.
233 #[cfg(feature = "frame")]
234 pub fn cp_layer_renderer_query_next_frame(layer_renderer: &cp_layer_renderer_t) -> cp_frame_t;
235}
236
237extern "C-unwind" {
238 /// Return how many times a frame is repeated on display. This is typically used to
239 /// build dynamic frame pacing.
240 ///
241 /// - Parameters layer_renderer: The layer on which you're drawing.
242 ///
243 /// - Returns: The repeat count. If the repeat count is set to a value greater or equal to 1, it means this
244 /// layer repeated the client frame `repeat count` times, effectively multiplying the
245 /// frame duration by `repeat count + 1`.
246 ///
247 /// Lowering the number of frames being rendered every second will decrease the power usage per frame.
248 /// This value should only be increased if appropriate for the content being rendered.
249 pub fn cp_layer_renderer_get_minimum_frame_repeat_count(
250 layer_renderer: &cp_layer_renderer_t,
251 ) -> c_int;
252}
253
254extern "C-unwind" {
255 /// Set the frame repeat count. This is typically used to build dynamic frame pacing.
256 ///
257 /// - Parameters:
258 /// - layer_renderer: The layer on which you're drawing.
259 /// - frame_repeat_count: How many times a frame is repeated on display.
260 ///
261 /// If the repeat count is set to a value greater or equal to 1, it means this
262 /// layer repeats the client frame `repeat count` times, effectively multiplying the
263 /// frame duration by `repeat count + 1`.
264 ///
265 /// Lowering the number of frames being rendered every second will decrease the power usage per frame.
266 /// This value should only be increased if appropriate for the content being rendered.
267 pub fn cp_layer_renderer_set_minimum_frame_repeat_count(
268 layer_renderer: &cp_layer_renderer_t,
269 frame_repeat_count: c_int,
270 );
271}
272
273extern "C-unwind" {
274 /// Get the render quality to be used by the drawables.
275 ///
276 /// - Parameters:
277 /// - layer_renderer: The layer on which you're drawing.
278 ///
279 /// The render quality will increase the resolution at which rendering happens.
280 /// This value cannot exceed the quality specified on the layer renderer configuration
281 /// see ``cp_layer_renderer_configuration_set_max_render_quality``.
282 /// The quality will be changed to the target render quality over a set duration to hide
283 /// the transition of quality from the user.
284 ///
285 /// The renderer should monitor its frame rate to determine whether its making the frames
286 /// on time. If it is unable to maintain proper frame rate, the app should reduce the render
287 /// quality, reduce the scene complexity, or increase the frame repeat count see
288 /// ``cp_layer_renderer_set_minimum_frame_repeat_count``.
289 /// It is generally preferable to reduce anything else before increasing the frame repeat count.
290 #[cfg(feature = "cp_types")]
291 pub fn cp_layer_renderer_get_render_quality(
292 layer_renderer: &cp_layer_renderer_t,
293 ) -> cp_render_quality_t;
294}
295
296extern "C-unwind" {
297 /// Set the render quality to be used by the drawables.
298 ///
299 /// - Parameters:
300 /// - layer_renderer: The layer on which you're drawing.
301 /// - render_quality: The value of quality [0, 1].
302 /// With 0 being the minimum quality that is supported on the device,
303 /// and 1 being the highest quality that is supported on the device.
304 ///
305 /// The render quality will increase the resolution at which rendering happens.
306 /// This value cannot exceed the quality specified on the layer renderer configuration
307 /// see ``cp_layer_renderer_configuration_set_max_render_quality``.
308 /// The quality will be changed to the target render quality over a set duration to hide
309 /// the transition of quality from the user.
310 ///
311 /// The renderer should monitor its frame rate to determine whether its making the frames
312 /// on time. If it is unable to maintain proper frame rate, the app should reduce the render
313 /// quality, reduce the scene complexity, or increase the frame repeat count see
314 /// ``cp_layer_renderer_set_minimum_frame_repeat_count``.
315 /// It is generally preferable to reduce anything else before increasing the frame repeat count.
316 #[cfg(feature = "cp_types")]
317 pub fn cp_layer_renderer_set_render_quality(
318 layer_renderer: &cp_layer_renderer_t,
319 render_quality: cp_render_quality_t,
320 );
321}