objc2_paravirtualized_graphics/generated/PGDisplay.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5#[cfg(feature = "dispatch2")]
6use dispatch2::*;
7use objc2::__framework_prelude::*;
8#[cfg(feature = "objc2-app-kit")]
9use objc2_app_kit::*;
10use objc2_foundation::*;
11#[cfg(feature = "objc2-metal")]
12use objc2_metal::*;
13
14use crate::*;
15
16/// A struct for describing size of or offsets into a 2D array of pixels (used for size of display mode, size of cursor, and cursor hotSpot).
17/// Field: x Represents horizontal pixel offset/size
18/// Field: y Represents vertical pixel offset/size
19///
20/// See also [Apple's documentation](https://developer.apple.com/documentation/paravirtualizedgraphics/pgdisplaycoord_t?language=objc)
21#[repr(C)]
22#[derive(Clone, Copy, Debug, PartialEq)]
23pub struct PGDisplayCoord_t {
24 pub x: u16,
25 pub y: u16,
26}
27
28unsafe impl Encode for PGDisplayCoord_t {
29 const ENCODING: Encoding = Encoding::Struct("?", &[<u16>::ENCODING, <u16>::ENCODING]);
30}
31
32unsafe impl RefEncode for PGDisplayCoord_t {
33 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
34}
35
36/// A block that will be invoked at display mode change boundaries.
37///
38/// Parameter `sizeInPixels`: Size of upcoming frames.
39///
40/// Parameter `pixelFormat`: Pixel format of upcoming frames.
41///
42/// See also [Apple's documentation](https://developer.apple.com/documentation/paravirtualizedgraphics/pgdisplaymodechangehandler?language=objc)
43#[cfg(feature = "block2")]
44pub type PGDisplayModeChangeHandler = *mut block2::DynBlock<dyn Fn(PGDisplayCoord_t, OSType)>;
45
46/// A block that will be invoked to notify client of availability of new Guest compositor frame to be further processed.
47///
48/// See encodeCurrentFrameToCommandBuffer:texture:region: below to get further processing underway.
49///
50/// See also [Apple's documentation](https://developer.apple.com/documentation/paravirtualizedgraphics/pgdisplaynewframeeventhandler?language=objc)
51#[cfg(feature = "block2")]
52pub type PGDisplayNewFrameEventHandler = *mut block2::DynBlock<dyn Fn()>;
53
54/// A block that will be invoked to handle cursor glyph updates.
55///
56/// Parameter `glyph`: Cursor glyph to apply.
57///
58/// Parameter `hotSpot`: Top,left relative location of hotSpot.
59///
60/// See also [Apple's documentation](https://developer.apple.com/documentation/paravirtualizedgraphics/pgdisplaycursorglyphhandler?language=objc)
61#[cfg(all(feature = "block2", feature = "objc2-app-kit"))]
62pub type PGDisplayCursorGlyphHandler =
63 *mut block2::DynBlock<dyn Fn(NonNull<NSBitmapImageRep>, PGDisplayCoord_t)>;
64
65/// A block that will be invoked to handle cursor show/hide updates.
66///
67/// Parameter `show`: Flag indicating whether to show cursor glyph.
68///
69/// See also [Apple's documentation](https://developer.apple.com/documentation/paravirtualizedgraphics/pgdisplaycursorshowhandler?language=objc)
70#[cfg(feature = "block2")]
71pub type PGDisplayCursorShowHandler = *mut block2::DynBlock<dyn Fn(Bool)>;
72
73/// A block that will be invoked to handle cursor movement.
74///
75/// See also [Apple's documentation](https://developer.apple.com/documentation/paravirtualizedgraphics/pgdisplaycursormovehandler?language=objc)
76#[cfg(feature = "block2")]
77pub type PGDisplayCursorMoveHandler = *mut block2::DynBlock<dyn Fn()>;
78
79extern_class!(
80 /// Descriptor to facilitate creation of PGDisplay.
81 ///
82 /// See [PGDevice newDisplayWithDescriptor:port:serialNum]
83 ///
84 /// See also [Apple's documentation](https://developer.apple.com/documentation/paravirtualizedgraphics/pgdisplaydescriptor?language=objc)
85 #[unsafe(super(NSObject))]
86 #[derive(Debug, PartialEq, Eq, Hash)]
87 pub struct PGDisplayDescriptor;
88);
89
90extern_conformance!(
91 unsafe impl NSObjectProtocol for PGDisplayDescriptor {}
92);
93
94impl PGDisplayDescriptor {
95 extern_methods!(
96 /// Client supplied name of display, as seen by guest.
97 ///
98 /// Truncates to 13 characters. Defaults to "Apple Virtual". Value provided here may be made visible via guest UI.
99 #[unsafe(method(name))]
100 #[unsafe(method_family = none)]
101 pub unsafe fn name(&self) -> Option<Retained<NSString>>;
102
103 /// Setter for [`name`][Self::name].
104 ///
105 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
106 #[unsafe(method(setName:))]
107 #[unsafe(method_family = none)]
108 pub unsafe fn setName(&self, name: Option<&NSString>);
109
110 /// Client supplied display size conveyed to guest compositor.
111 ///
112 /// Conveyed size contributes to guest compositor layout, but host-side VM app can scale to UI of its own choosing.
113 #[unsafe(method(sizeInMillimeters))]
114 #[unsafe(method_family = none)]
115 pub unsafe fn sizeInMillimeters(&self) -> NSSize;
116
117 /// Setter for [`sizeInMillimeters`][Self::sizeInMillimeters].
118 #[unsafe(method(setSizeInMillimeters:))]
119 #[unsafe(method_family = none)]
120 pub unsafe fn setSizeInMillimeters(&self, size_in_millimeters: NSSize);
121
122 #[cfg(feature = "dispatch2")]
123 /// Client supplied dispatch_queue on which to invoke client supplied blocks.
124 ///
125 /// Typical client provides serial queue, and redispatches if beneficial to process out of order.
126 #[unsafe(method(queue))]
127 #[unsafe(method_family = none)]
128 pub unsafe fn queue(&self) -> Option<Retained<DispatchQueue>>;
129
130 #[cfg(feature = "dispatch2")]
131 /// Setter for [`queue`][Self::queue].
132 ///
133 /// # Safety
134 ///
135 /// `queue` possibly has additional threading requirements.
136 #[unsafe(method(setQueue:))]
137 #[unsafe(method_family = none)]
138 pub unsafe fn setQueue(&self, queue: Option<&DispatchQueue>);
139
140 #[cfg(feature = "block2")]
141 /// The block to invoke to handle display mode change.
142 ///
143 /// Handler invocation indicative of display mode change.
144 #[unsafe(method(modeChangeHandler))]
145 #[unsafe(method_family = none)]
146 pub unsafe fn modeChangeHandler(&self) -> PGDisplayModeChangeHandler;
147
148 #[cfg(feature = "block2")]
149 /// Setter for [`modeChangeHandler`][Self::modeChangeHandler].
150 ///
151 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
152 ///
153 /// # Safety
154 ///
155 /// `mode_change_handler` must be a valid pointer or null.
156 #[unsafe(method(setModeChangeHandler:))]
157 #[unsafe(method_family = none)]
158 pub unsafe fn setModeChangeHandler(&self, mode_change_handler: PGDisplayModeChangeHandler);
159
160 #[cfg(feature = "block2")]
161 /// The block to invoke to handle notification of the presence of a new Guest compositor frame.
162 ///
163 /// Handler invocation indicates presence of new frame to be processed for display. Only one of newFrameEventHandler or presentHandler may be non-nil.
164 #[unsafe(method(newFrameEventHandler))]
165 #[unsafe(method_family = none)]
166 pub unsafe fn newFrameEventHandler(&self) -> PGDisplayNewFrameEventHandler;
167
168 #[cfg(feature = "block2")]
169 /// Setter for [`newFrameEventHandler`][Self::newFrameEventHandler].
170 ///
171 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
172 ///
173 /// # Safety
174 ///
175 /// `new_frame_event_handler` must be a valid pointer or null.
176 #[unsafe(method(setNewFrameEventHandler:))]
177 #[unsafe(method_family = none)]
178 pub unsafe fn setNewFrameEventHandler(
179 &self,
180 new_frame_event_handler: PGDisplayNewFrameEventHandler,
181 );
182
183 #[cfg(all(feature = "block2", feature = "objc2-app-kit"))]
184 /// The block to invoke to handle cursor glyph updates.
185 ///
186 /// Handler invocation indicative of new cursor image for display. If this block is not set, cursor will be precomposited in presented image.
187 ///
188 /// # Safety
189 ///
190 /// The returned block's argument 1 must be a valid pointer.
191 #[unsafe(method(cursorGlyphHandler))]
192 #[unsafe(method_family = none)]
193 pub unsafe fn cursorGlyphHandler(&self) -> PGDisplayCursorGlyphHandler;
194
195 #[cfg(all(feature = "block2", feature = "objc2-app-kit"))]
196 /// Setter for [`cursorGlyphHandler`][Self::cursorGlyphHandler].
197 ///
198 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
199 ///
200 /// # Safety
201 ///
202 /// `cursor_glyph_handler` must be a valid pointer or null.
203 #[unsafe(method(setCursorGlyphHandler:))]
204 #[unsafe(method_family = none)]
205 pub unsafe fn setCursorGlyphHandler(
206 &self,
207 cursor_glyph_handler: PGDisplayCursorGlyphHandler,
208 );
209
210 #[cfg(feature = "block2")]
211 /// The block to invoke to handle cursor show/hide updates.
212 ///
213 /// Handler invocation indicative of hide/show of cursor glyph. If this block is not set, cursor will be precomposited in presented image.
214 #[unsafe(method(cursorShowHandler))]
215 #[unsafe(method_family = none)]
216 pub unsafe fn cursorShowHandler(&self) -> PGDisplayCursorShowHandler;
217
218 #[cfg(feature = "block2")]
219 /// Setter for [`cursorShowHandler`][Self::cursorShowHandler].
220 ///
221 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
222 ///
223 /// # Safety
224 ///
225 /// `cursor_show_handler` must be a valid pointer or null.
226 #[unsafe(method(setCursorShowHandler:))]
227 #[unsafe(method_family = none)]
228 pub unsafe fn setCursorShowHandler(&self, cursor_show_handler: PGDisplayCursorShowHandler);
229
230 #[cfg(feature = "block2")]
231 /// The block to invoke to handle cursor movement.
232 ///
233 /// Handler invocation indicative of movement. Handler should resampling via PGDisplay::cursorPosition.
234 #[unsafe(method(cursorMoveHandler))]
235 #[unsafe(method_family = none)]
236 pub unsafe fn cursorMoveHandler(&self) -> PGDisplayCursorMoveHandler;
237
238 #[cfg(feature = "block2")]
239 /// Setter for [`cursorMoveHandler`][Self::cursorMoveHandler].
240 ///
241 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
242 ///
243 /// # Safety
244 ///
245 /// `cursor_move_handler` must be a valid pointer or null.
246 #[unsafe(method(setCursorMoveHandler:))]
247 #[unsafe(method_family = none)]
248 pub unsafe fn setCursorMoveHandler(&self, cursor_move_handler: PGDisplayCursorMoveHandler);
249 );
250}
251
252/// Methods declared on superclass `NSObject`.
253impl PGDisplayDescriptor {
254 extern_methods!(
255 #[unsafe(method(init))]
256 #[unsafe(method_family = init)]
257 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
258
259 #[unsafe(method(new))]
260 #[unsafe(method_family = new)]
261 pub unsafe fn new() -> Retained<Self>;
262 );
263}
264
265extern_class!(
266 /// Description of supported display mode.
267 ///
268 /// Client of PGDisplay can dynamically supply NSArray of PGDisplayMode objects to convey supported modes. The first mode in array is preferred.
269 ///
270 /// See also [Apple's documentation](https://developer.apple.com/documentation/paravirtualizedgraphics/pgdisplaymode?language=objc)
271 #[unsafe(super(NSObject))]
272 #[derive(Debug, PartialEq, Eq, Hash)]
273 pub struct PGDisplayMode;
274);
275
276extern_conformance!(
277 unsafe impl NSObjectProtocol for PGDisplayMode {}
278);
279
280impl PGDisplayMode {
281 extern_methods!(
282 /// Width/height of supported display mode.
283 #[unsafe(method(sizeInPixels))]
284 #[unsafe(method_family = none)]
285 pub unsafe fn sizeInPixels(&self) -> PGDisplayCoord_t;
286
287 /// refreshRate of supported display mode. Consider only supplying modes using a refreshRate equal to that of host OS's physical display where representation is ultimately shown.
288 #[unsafe(method(refreshRate))]
289 #[unsafe(method_family = none)]
290 pub unsafe fn refreshRate(&self) -> c_double;
291
292 /// Used to conjure up display mode objects (to be arranged into NSArrays for modeList).
293 ///
294 /// Parameter `sizeInPixels`: Width/height of supported display mode.
295 ///
296 /// Parameter `refreshRateInHz`: Refresh rate of supported display mode.
297 #[unsafe(method(initWithSizeInPixels:refreshRateInHz:))]
298 #[unsafe(method_family = init)]
299 pub unsafe fn initWithSizeInPixels_refreshRateInHz(
300 this: Allocated<Self>,
301 size_in_pixels: PGDisplayCoord_t,
302 refresh_rate_in_hz: c_double,
303 ) -> Option<Retained<PGDisplayMode>>;
304 );
305}
306
307/// Methods declared on superclass `NSObject`.
308impl PGDisplayMode {
309 extern_methods!(
310 #[unsafe(method(init))]
311 #[unsafe(method_family = init)]
312 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
313
314 #[unsafe(method(new))]
315 #[unsafe(method_family = new)]
316 pub unsafe fn new() -> Retained<Self>;
317 );
318}
319
320extern_protocol!(
321 /// Object providing display functionality to guest in a way that host-side VM app can intercept (and process as it chooses).
322 ///
323 /// The first time the modeList is set for a display, the guest will receive a simulated hot-plug of a display on its port. When this object is freed, the guest will receive a simulated hot-unplug of the display on its port.
324 ///
325 /// See also [Apple's documentation](https://developer.apple.com/documentation/paravirtualizedgraphics/pgdisplay?language=objc)
326 pub unsafe trait PGDisplay: NSObjectProtocol {
327 /// The name of the display.
328 #[unsafe(method(name))]
329 #[unsafe(method_family = none)]
330 unsafe fn name(&self) -> Option<Retained<NSString>>;
331
332 /// The size of the display.
333 ///
334 /// Mostly for debug visibility.
335 #[unsafe(method(sizeInMillimeters))]
336 #[unsafe(method_family = none)]
337 unsafe fn sizeInMillimeters(&self) -> NSSize;
338
339 #[cfg(feature = "dispatch2")]
340 /// The dispatch_queue on which to invoke client supplied blocks.
341 #[unsafe(method(queue))]
342 #[unsafe(method_family = none)]
343 unsafe fn queue(&self) -> Option<Retained<DispatchQueue>>;
344
345 #[cfg(feature = "block2")]
346 /// The block to invoke to handle display mode change.
347 #[unsafe(method(modeChangeHandler))]
348 #[unsafe(method_family = none)]
349 unsafe fn modeChangeHandler(&self) -> PGDisplayModeChangeHandler;
350
351 #[cfg(feature = "block2")]
352 /// The block to invoke to notify presence of new Guest frame to be processed.
353 ///
354 /// See encodeCurrentFrameToCommandBuffer:texture:region: below to get further processing underway.
355 #[unsafe(method(newFrameEventHandler))]
356 #[unsafe(method_family = none)]
357 unsafe fn newFrameEventHandler(&self) -> PGDisplayNewFrameEventHandler;
358
359 #[cfg(all(feature = "block2", feature = "objc2-app-kit"))]
360 /// The block to invoke to handle cursor glyph updates.
361 ///
362 /// # Safety
363 ///
364 /// The returned block's argument 1 must be a valid pointer.
365 #[unsafe(method(cursorGlyphHandler))]
366 #[unsafe(method_family = none)]
367 unsafe fn cursorGlyphHandler(&self) -> PGDisplayCursorGlyphHandler;
368
369 #[cfg(feature = "block2")]
370 /// The block to invoke to handle cursor show/hide updates.
371 #[unsafe(method(cursorShowHandler))]
372 #[unsafe(method_family = none)]
373 unsafe fn cursorShowHandler(&self) -> PGDisplayCursorShowHandler;
374
375 #[cfg(feature = "block2")]
376 /// The block to invoke to handle cursor movement.
377 #[unsafe(method(cursorMoveHandler))]
378 #[unsafe(method_family = none)]
379 unsafe fn cursorMoveHandler(&self) -> PGDisplayCursorMoveHandler;
380
381 /// Top,left display relative position of cursor hotSpot.
382 ///
383 /// This is a low overhead mechanism to sample cursor location on this display of guest compositor. Sentinel value for cursor not on display is {0xffff,0xffff}.
384 #[unsafe(method(cursorPosition))]
385 #[unsafe(method_family = none)]
386 unsafe fn cursorPosition(&self) -> PGDisplayCoord_t;
387
388 /// Create-time serialNum of display.
389 ///
390 /// Mostly for debug visibility. Param of [PGDevice newDisplayWithDescriptor:port:serialNum].
391 #[unsafe(method(serialNum))]
392 #[unsafe(method_family = none)]
393 unsafe fn serialNum(&self) -> u32;
394
395 /// Create-time port number of display.
396 ///
397 /// Mostly for debug visibility. Param of [PGDevice newDisplayWithDescriptor:port:serialNum].
398 #[unsafe(method(port))]
399 #[unsafe(method_family = none)]
400 unsafe fn port(&self) -> NSUInteger;
401
402 #[cfg(feature = "objc2-metal")]
403 /// Minimally required textureUsage bits for destination texture of encodeCurrentFrameToCommandBuffer:texture:region:.
404 ///
405 /// If destination texture doesn't meet this requirement, encodeCurrentFrameToCommandBuffer:texture:region: will fail.
406 #[unsafe(method(minimumTextureUsage))]
407 #[unsafe(method_family = none)]
408 unsafe fn minimumTextureUsage(&self) -> MTLTextureUsage;
409
410 /// The number of frame presents generated by the guest since object creation.
411 ///
412 /// This value could exceed the number of times newFrameEventHandler block is invoked when host is not encoding frames fast enough to keep up.
413 #[unsafe(method(guestPresentCount))]
414 #[unsafe(method_family = none)]
415 unsafe fn guestPresentCount(&self) -> NSUInteger;
416
417 /// The number of unique frames encoded for present by the host since object creation.
418 ///
419 /// This value could be smaller than than the count of times encodeCurrentFrameToCommandBuffer:texture:region: is invoked when same frame is encoded multiple times.
420 #[unsafe(method(hostPresentCount))]
421 #[unsafe(method_family = none)]
422 unsafe fn hostPresentCount(&self) -> NSUInteger;
423
424 /// Supported list of display modes.
425 ///
426 /// This is the only writeable property of display object. Setting it will update supported mode list (up to 128 modes) and potentially trigger a mode change. First setting looks like hot-plug.
427 #[unsafe(method(modeList))]
428 #[unsafe(method_family = none)]
429 unsafe fn modeList(&self) -> Retained<NSArray<PGDisplayMode>>;
430
431 /// Setter for [`modeList`][Self::modeList].
432 ///
433 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
434 #[unsafe(method(setModeList:))]
435 #[unsafe(method_family = none)]
436 unsafe fn setModeList(&self, mode_list: &NSArray<PGDisplayMode>);
437
438 #[cfg(feature = "objc2-metal")]
439 /// Encode processing of new frame (to deal with gamma, CSC, and more...), landing it in specific region of specific texture.
440 ///
441 /// Parameter `commandBuffer`: The Metal command buffer in which to encode processing of new frame.
442 ///
443 /// Parameter `texture`: The Metal texture in which the processed frame should land.
444 ///
445 /// Parameter `region`: The region within the Metal texture that the (linear scaled) frame should land in.
446 ///
447 /// Returns: True if encoding was successful, otherwise, false.
448 ///
449 /// Client calls this method to direct display object to append encoded display processing Metal pass to client supplied commandBuffer. Processed frame will land in specified region of client supplied texture. Nothing outside the specified region will be written. Note that commandBuffer and texture objects must both be descendants of host Metal device being used for guest acceleration. Note that texture.textureUsage must contain the bits specified in self.minimumTextureUsage. See newFrameEventHandler above since it notifies client of the existence of a new frame.
450 ///
451 /// # Safety
452 ///
453 /// - `texture` may need to be synchronized.
454 /// - `texture` may be unretained, you must ensure it is kept alive while in use.
455 #[unsafe(method(encodeCurrentFrameToCommandBuffer:texture:region:))]
456 #[unsafe(method_family = none)]
457 unsafe fn encodeCurrentFrameToCommandBuffer_texture_region(
458 &self,
459 command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
460 texture: &ProtocolObject<dyn MTLTexture>,
461 region: MTLRegion,
462 ) -> bool;
463 }
464);