objc2_compositor_services/generated/frame.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 objc2::__framework_prelude::*;
7
8use crate::*;
9
10/// [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_frame?language=objc)
11#[repr(C)]
12#[derive(Debug)]
13pub struct cp_frame {
14 inner: [u8; 0],
15 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
16}
17
18unsafe impl RefEncode for cp_frame {
19 const ENCODING_REF: Encoding = Encoding::Pointer(&Encoding::Struct("cp_frame", &[]));
20}
21
22/// An opaque type that provides access to the timing information and
23/// data types you need to render a single frame of content.
24///
25/// During each cycle of your app’s rendering loop, retrieve a frame
26/// using the ``cp_layer_renderer_query_next_frame`` function and use it to
27/// render your app’s content. The ``cp_frame_t`` type provides access
28/// to the information you need to render your frame in a timely manner.
29/// It also provides access to the ``cp_drawable_t`` type you use to
30/// retrieve the textures you need for drawing.
31///
32/// Separate the work you do for each frame into two phases: the update
33/// phase and the encode phase. Use the update phase to perform app-specific
34/// tasks, such as processing interactions with your content. Use the
35/// encode phase to commit the Metal commands you need to draw your
36/// content for the current pose. For both phases, use frame functions
37/// to notify the Compositor when you start and stop the related work.
38/// For example, surround update work with calls to the
39/// ``cp_frame_start_update`` and ``cp_frame_end_update``
40/// functions.
41///
42/// See also [Apple's documentation](https://developer.apple.com/documentation/compositorservices/cp_frame_t?language=objc)
43pub type cp_frame_t = *mut cp_frame;
44
45impl cp_frame {
46 /// Returns the sequential index number of the specified frame.
47 ///
48 /// - Parameters:
49 /// - frame: The frame to query.
50 /// - Returns: The sequential index of the frame, which is always a
51 /// positive integer.
52 ///
53 /// The layer assigns a unique index number to each frame, starting at
54 /// the first frame and incrementing the index by 1 for each new frame.
55 ///
56 /// # Safety
57 ///
58 /// `frame` must be a valid pointer.
59 #[doc(alias = "cp_frame_get_frame_index")]
60 #[cfg(feature = "cp_types")]
61 #[inline]
62 pub unsafe fn frame_index(frame: cp_frame_t) -> cp_layer_frame_index_t {
63 extern "C-unwind" {
64 fn cp_frame_get_frame_index(frame: cp_frame_t) -> cp_layer_frame_index_t;
65 }
66 unsafe { cp_frame_get_frame_index(frame) }
67 }
68
69 /// Computes and returns the predicted timing information for the specified frame.
70 ///
71 /// - Parameters:
72 /// - frame: The frame you're preparing to draw.
73 /// - Returns: The predicted timing information for the specified frame, or `NULL`
74 /// if the layer is in the ``cp_layer_renderer/cp_layer_renderer_state_paused`` or
75 /// ``cp_layer_renderer/cp_layer_renderer_state_invalidated`` state.
76 ///
77 /// Use the returned timing information in any functions that return
78 /// frame-related deadlines. For example, pass the timing information
79 /// to the ``cp_frame_timing_get_optimal_input_time`` function to
80 /// determine when to start encoding the frame. This function updates
81 /// the frame-specific timing information using the latest data from
82 /// the compositor before it returns it.
83 ///
84 /// Don’t call this function after you call ``cp_frame_query_drawable``
85 /// for the specified frame. If you need the timing information after you
86 /// retrieve the frame's ``cp_drawable_t`` type, save the return value
87 /// of this function, or call ``cp_drawable_get_frame_timing`` to get
88 /// the information from the drawable instead.
89 ///
90 /// # Safety
91 ///
92 /// `frame` must be a valid pointer.
93 #[doc(alias = "cp_frame_predict_timing")]
94 #[cfg(feature = "frame_timing")]
95 #[inline]
96 pub unsafe fn predict_timing(frame: cp_frame_t) -> cp_frame_timing_t {
97 extern "C-unwind" {
98 fn cp_frame_predict_timing(frame: cp_frame_t) -> cp_frame_timing_t;
99 }
100 unsafe { cp_frame_predict_timing(frame) }
101 }
102
103 /// Returns the drawable type you use to retrieve the textures and
104 /// drawing environment for the frame.
105 ///
106 /// - Parameters:
107 /// - frame: The frame to query.
108 /// - Returns: The drawable type, or `NULL` if the layer is in the
109 /// ``cp_layer_renderer/cp_layer_renderer_state_paused`` or
110 /// ``cp_layer_renderer/cp_layer_renderer_state_invalidated`` state.
111 ///
112 /// Call this function when you're ready to encode the drawing commands
113 /// for the frame. The ``cp_drawable_t`` type contains the textures and
114 /// other information you need to set up your render descriptor in Metal.
115 ///
116 /// Note: This function isn't safe to be called concurrently. Always ensure a
117 /// single thread call this function at a time.
118 ///
119 /// # Safety
120 ///
121 /// `frame` must be a valid pointer.
122 #[doc(alias = "cp_frame_query_drawable")]
123 #[cfg(feature = "drawable")]
124 #[deprecated = "Use cp_frame_query_drawables instead"]
125 #[inline]
126 pub unsafe fn query_drawable(frame: cp_frame_t) -> cp_drawable_t {
127 extern "C-unwind" {
128 fn cp_frame_query_drawable(frame: cp_frame_t) -> cp_drawable_t;
129 }
130 unsafe { cp_frame_query_drawable(frame) }
131 }
132
133 /// Returns the drawable array type you use to retrieve the drawables for
134 /// drawing environment for the frame.
135 ///
136 /// - Parameters:
137 /// - frame: The frame to query.
138 /// - Returns: The drawable array type, if the layer is in the
139 /// ``cp_layer_renderer/cp_layer_renderer_state_paused`` or
140 /// ``cp_layer_renderer/cp_layer_renderer_state_invalidated`` states
141 /// the array will have a count of 0 and frame is invalid.
142 ///
143 /// Call this function when you're ready to encode the drawing commands
144 /// for the frame. The ``cp_drawable_t`` type contains the textures and
145 /// other information you need to set up your render descriptor in Metal.
146 /// See ``cp_drawable_get_target`` for how each drawable will be used.
147 ///
148 /// If array count is 0, the frame has been cancelled as there are no drawables
149 /// to draw to and the frame should be discarded and is invalid to access.
150 ///
151 /// Note: This function isn't safe to be called concurrently. Always ensure a
152 /// single thread call this function at a time.
153 ///
154 /// # Safety
155 ///
156 /// `frame` must be a valid pointer.
157 #[doc(alias = "cp_frame_query_drawables")]
158 #[cfg(feature = "drawable")]
159 #[inline]
160 pub unsafe fn query_drawables(frame: cp_frame_t) -> cp_drawable_array_t {
161 extern "C-unwind" {
162 fn cp_frame_query_drawables(frame: cp_frame_t) -> cp_drawable_array_t;
163 }
164 unsafe { cp_frame_query_drawables(frame) }
165 }
166
167 /// Notifies the compositor that you started updating the app-specific
168 /// content you need to render the frame.
169 ///
170 /// - Parameters:
171 /// - frame: The frame you are ready to prepare.
172 ///
173 /// This function helps you optimize your app’s rendering efficiency.
174 /// Before you render a frame, you might need to respond to
175 /// interactions and update your app's data structures before you can
176 /// render items in your scene. Call this function immediately
177 /// before you start that work, and call the ``cp_frame_end_update``
178 /// function as soon as you finish. The compositor uses the time difference
179 /// to improve its predictions for when to start the frame encoding process.
180 ///
181 /// Move as much work as possible into the update phase to minimize encoding
182 /// time. Don't do any work that relies on the current pose information during
183 /// the update phase. Instead, make any pose-related changes during the
184 /// encoding phase.
185 ///
186 /// # Safety
187 ///
188 /// `frame` must be a valid pointer.
189 #[doc(alias = "cp_frame_start_update")]
190 #[inline]
191 pub unsafe fn start_update(frame: cp_frame_t) {
192 extern "C-unwind" {
193 fn cp_frame_start_update(frame: cp_frame_t);
194 }
195 unsafe { cp_frame_start_update(frame) }
196 }
197
198 /// Notifies the compositor that you finished updating the app-specific
199 /// content you need to render the frame.
200 ///
201 /// - Parameters:
202 /// - frame: The frame you finished preparing.
203 ///
204 /// This function helps you optimize your app’s rendering efficiency.
205 /// Before you render a frame, you might need to respond to
206 /// interactions and update your app's data structures before you can
207 /// render items in your scene. Call the ``cp_frame_start_update``
208 /// function immediately before you start that work, and call this function
209 /// as soon as you finish. Compositor uses the frame update time to improve
210 /// its predictions for when to start the frame encoding process.
211 ///
212 /// Move as much work as possible into the update phase to minimize encoding
213 /// time. Don't do any work that relies on the current pose information during
214 /// the update phase. Instead, make any pose-related changes during the
215 /// encoding phase.
216 ///
217 /// # Safety
218 ///
219 /// `frame` must be a valid pointer.
220 #[doc(alias = "cp_frame_end_update")]
221 #[inline]
222 pub unsafe fn end_update(frame: cp_frame_t) {
223 extern "C-unwind" {
224 fn cp_frame_end_update(frame: cp_frame_t);
225 }
226 unsafe { cp_frame_end_update(frame) }
227 }
228
229 /// Notifies the compositor that you're ready to generate the
230 /// GPU commands to render the specified frame.
231 ///
232 /// - Parameters:
233 /// - frame: The frame you're ready to encode and send to the GPU.
234 ///
235 /// This function helps you optimize your app’s rendering efficiency.
236 /// Call this function function before you start any of the GPU work that depends
237 /// on the input data. Call the ``cp_frame_end_submission`` function after
238 /// you finish your drawing commands and are ready to commit the frame to
239 /// the GPU. Compositor uses the time difference to improve its predictions
240 /// for when to start the frame submission process. Those predictions help
241 /// you schedule the encoding process at a more optimal time for the
242 /// system.
243 ///
244 /// # Safety
245 ///
246 /// `frame` must be a valid pointer.
247 #[doc(alias = "cp_frame_start_submission")]
248 #[inline]
249 pub unsafe fn start_submission(frame: cp_frame_t) {
250 extern "C-unwind" {
251 fn cp_frame_start_submission(frame: cp_frame_t);
252 }
253 unsafe { cp_frame_start_submission(frame) }
254 }
255
256 /// Notifies the compositor that you finished generating the GPU
257 /// commands to render the specified frame.
258 ///
259 /// - Parameters:
260 /// - frame: The frame you're ready to submit to the GPU.
261 ///
262 /// This function helps you optimize your app’s rendering efficiency.
263 /// Call the ``cp_frame_start_submission`` function before you start any of the GPU
264 /// work that depends on the input data. Call this function after
265 /// you finish your drawing commands and are ready to commit the frame to
266 /// the GPU. Compositor uses the time difference to improve its predictions
267 /// for when to start the frame submission process. Those predictions help
268 /// you schedule the encoding process at a more optimal time for the
269 /// system.
270 ///
271 /// # Safety
272 ///
273 /// `frame` must be a valid pointer.
274 #[doc(alias = "cp_frame_end_submission")]
275 #[inline]
276 pub unsafe fn end_submission(frame: cp_frame_t) {
277 extern "C-unwind" {
278 fn cp_frame_end_submission(frame: cp_frame_t);
279 }
280 unsafe { cp_frame_end_submission(frame) }
281 }
282
283 /// Returns the number of view in the drawable target.
284 ///
285 /// - Parameters:
286 /// - frame: frame: The frame you finished preparing.
287 /// - drawable_target: whether this is intended for `built_in` or `recorder`drawable
288 /// - Returns: The number of views available for drawing. For example, a return
289 /// value of `2` indicates there are two views for this target drawable in this frame.
290 /// value of `0` indicates there is no view available for this target drawable in this frame.
291 ///
292 /// Use the returned value as the maximum number of views to retrieve
293 /// from the ``cp_frame_binocular_frustum_matrix_for_drawable_target``
294 /// or ``cp_frame_monocular_frustum_matrix_for_drawable_target`` functions.
295 ///
296 /// # Safety
297 ///
298 /// `frame` must be a valid pointer.
299 #[doc(alias = "cp_frame_get_drawable_target_view_count")]
300 #[cfg(feature = "drawable")]
301 #[inline]
302 pub unsafe fn drawable_target_view_count(
303 frame: cp_frame_t,
304 drawable_target: cp_drawable_target,
305 ) -> usize {
306 extern "C-unwind" {
307 fn cp_frame_get_drawable_target_view_count(
308 frame: cp_frame_t,
309 drawable_target: cp_drawable_target,
310 ) -> usize;
311 }
312 unsafe { cp_frame_get_drawable_target_view_count(frame, drawable_target) }
313 }
314}
315
316extern "C-unwind" {
317 #[cfg(feature = "cp_types")]
318 #[deprecated = "renamed to `cp_frame::frame_index`"]
319 pub fn cp_frame_get_frame_index(frame: cp_frame_t) -> cp_layer_frame_index_t;
320}
321
322extern "C-unwind" {
323 #[cfg(feature = "frame_timing")]
324 #[deprecated = "renamed to `cp_frame::predict_timing`"]
325 pub fn cp_frame_predict_timing(frame: cp_frame_t) -> cp_frame_timing_t;
326}
327
328extern "C-unwind" {
329 #[cfg(feature = "drawable")]
330 #[deprecated = "renamed to `cp_frame::query_drawable`"]
331 pub fn cp_frame_query_drawable(frame: cp_frame_t) -> cp_drawable_t;
332}
333
334extern "C-unwind" {
335 #[cfg(feature = "drawable")]
336 #[deprecated = "renamed to `cp_frame::query_drawables`"]
337 pub fn cp_frame_query_drawables(frame: cp_frame_t) -> cp_drawable_array_t;
338}
339
340extern "C-unwind" {
341 #[deprecated = "renamed to `cp_frame::start_update`"]
342 pub fn cp_frame_start_update(frame: cp_frame_t);
343}
344
345extern "C-unwind" {
346 #[deprecated = "renamed to `cp_frame::end_update`"]
347 pub fn cp_frame_end_update(frame: cp_frame_t);
348}
349
350extern "C-unwind" {
351 #[deprecated = "renamed to `cp_frame::start_submission`"]
352 pub fn cp_frame_start_submission(frame: cp_frame_t);
353}
354
355extern "C-unwind" {
356 #[deprecated = "renamed to `cp_frame::end_submission`"]
357 pub fn cp_frame_end_submission(frame: cp_frame_t);
358}
359
360extern "C-unwind" {
361 #[cfg(feature = "drawable")]
362 #[deprecated = "renamed to `cp_frame::drawable_target_view_count`"]
363 pub fn cp_frame_get_drawable_target_view_count(
364 frame: cp_frame_t,
365 drawable_target: cp_drawable_target,
366 ) -> usize;
367}