1use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9use objc2_core_foundation::*;
10#[cfg(feature = "objc2-core-graphics")]
11use objc2_core_graphics::*;
12#[cfg(feature = "objc2-open-gl")]
13#[cfg(target_os = "macos")]
14use objc2_open_gl::*;
15
16use crate::*;
17
18#[doc(alias = "CVDisplayLinkRef")]
20#[repr(C)]
21pub struct CVDisplayLink {
22 inner: [u8; 0],
23 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
24}
25
26cf_type!(
27 unsafe impl CVDisplayLink {}
28);
29#[cfg(feature = "objc2")]
30cf_objc2_type!(
31 unsafe impl RefEncode<"__CVDisplayLink"> for CVDisplayLink {}
32);
33
34#[cfg(all(feature = "CVBase", feature = "CVReturn"))]
36pub type CVDisplayLinkOutputCallback = Option<
37 unsafe extern "C-unwind" fn(
38 NonNull<CVDisplayLink>,
39 NonNull<CVTimeStamp>,
40 NonNull<CVTimeStamp>,
41 CVOptionFlags,
42 NonNull<CVOptionFlags>,
43 *mut c_void,
44 ) -> CVReturn,
45>;
46
47#[cfg(all(feature = "CVBase", feature = "CVReturn", feature = "block2"))]
49pub type CVDisplayLinkOutputHandler = *mut block2::DynBlock<
50 dyn Fn(
51 NonNull<CVDisplayLink>,
52 NonNull<CVTimeStamp>,
53 NonNull<CVTimeStamp>,
54 CVOptionFlags,
55 NonNull<CVOptionFlags>,
56 ) -> CVReturn,
57>;
58
59unsafe impl ConcreteType for CVDisplayLink {
60 #[doc(alias = "CVDisplayLinkGetTypeID")]
61 #[inline]
62 fn type_id() -> CFTypeID {
63 extern "C-unwind" {
64 fn CVDisplayLinkGetTypeID() -> CFTypeID;
65 }
66 unsafe { CVDisplayLinkGetTypeID() }
67 }
68}
69
70impl CVDisplayLink {
71 #[doc(alias = "CVDisplayLinkCreateWithCGDisplays")]
88 #[cfg(all(feature = "CVReturn", feature = "objc2-core-graphics"))]
89 #[deprecated = "use NSView.displayLink(target:selector:), NSWindow.displayLink(target:selector:), or NSScreen.displayLink(target:selector:) "]
90 #[inline]
91 pub unsafe fn create_with_cg_displays(
92 display_array: NonNull<CGDirectDisplayID>,
93 count: CFIndex,
94 display_link_out: NonNull<*mut CVDisplayLink>,
95 ) -> CVReturn {
96 extern "C-unwind" {
97 fn CVDisplayLinkCreateWithCGDisplays(
98 display_array: NonNull<CGDirectDisplayID>,
99 count: CFIndex,
100 display_link_out: NonNull<*mut CVDisplayLink>,
101 ) -> CVReturn;
102 }
103 unsafe { CVDisplayLinkCreateWithCGDisplays(display_array, count, display_link_out) }
104 }
105
106 #[doc(alias = "CVDisplayLinkCreateWithOpenGLDisplayMask")]
120 #[cfg(all(feature = "CVReturn", feature = "objc2-core-graphics"))]
121 #[deprecated = "use NSView.displayLink(target:selector:), NSWindow.displayLink(target:selector:), or NSScreen.displayLink(target:selector:) "]
122 #[inline]
123 pub unsafe fn create_with_open_gl_display_mask(
124 mask: CGOpenGLDisplayMask,
125 display_link_out: NonNull<*mut CVDisplayLink>,
126 ) -> CVReturn {
127 extern "C-unwind" {
128 fn CVDisplayLinkCreateWithOpenGLDisplayMask(
129 mask: CGOpenGLDisplayMask,
130 display_link_out: NonNull<*mut CVDisplayLink>,
131 ) -> CVReturn;
132 }
133 unsafe { CVDisplayLinkCreateWithOpenGLDisplayMask(mask, display_link_out) }
134 }
135
136 #[doc(alias = "CVDisplayLinkCreateWithCGDisplay")]
150 #[cfg(all(feature = "CVReturn", feature = "objc2-core-graphics"))]
151 #[deprecated = "use NSView.displayLink(target:selector:), NSWindow.displayLink(target:selector:), or NSScreen.displayLink(target:selector:) "]
152 #[inline]
153 pub unsafe fn create_with_cg_display(
154 display_id: CGDirectDisplayID,
155 display_link_out: NonNull<*mut CVDisplayLink>,
156 ) -> CVReturn {
157 extern "C-unwind" {
158 fn CVDisplayLinkCreateWithCGDisplay(
159 display_id: CGDirectDisplayID,
160 display_link_out: NonNull<*mut CVDisplayLink>,
161 ) -> CVReturn;
162 }
163 unsafe { CVDisplayLinkCreateWithCGDisplay(display_id, display_link_out) }
164 }
165
166 #[doc(alias = "CVDisplayLinkCreateWithActiveCGDisplays")]
176 #[cfg(feature = "CVReturn")]
177 #[deprecated = "use NSView.displayLink(target:selector:), NSWindow.displayLink(target:selector:), or NSScreen.displayLink(target:selector:) "]
178 #[inline]
179 pub unsafe fn create_with_active_cg_displays(
180 display_link_out: NonNull<*mut CVDisplayLink>,
181 ) -> CVReturn {
182 extern "C-unwind" {
183 fn CVDisplayLinkCreateWithActiveCGDisplays(
184 display_link_out: NonNull<*mut CVDisplayLink>,
185 ) -> CVReturn;
186 }
187 unsafe { CVDisplayLinkCreateWithActiveCGDisplays(display_link_out) }
188 }
189
190 #[doc(alias = "CVDisplayLinkSetCurrentCGDisplay")]
201 #[cfg(all(feature = "CVReturn", feature = "objc2-core-graphics"))]
202 #[deprecated = "use NSView.displayLink(target:selector:), NSWindow.displayLink(target:selector:), or NSScreen.displayLink(target:selector:) "]
203 #[inline]
204 pub fn set_current_cg_display(&self, display_id: CGDirectDisplayID) -> CVReturn {
205 extern "C-unwind" {
206 fn CVDisplayLinkSetCurrentCGDisplay(
207 display_link: &CVDisplayLink,
208 display_id: CGDirectDisplayID,
209 ) -> CVReturn;
210 }
211 unsafe { CVDisplayLinkSetCurrentCGDisplay(self, display_id) }
212 }
213
214 #[doc(alias = "CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext")]
229 #[cfg(all(feature = "CVReturn", feature = "objc2-open-gl"))]
230 #[cfg(target_os = "macos")]
231 #[deprecated = "use NSView.displayLink(target:selector:), NSWindow.displayLink(target:selector:), or NSScreen.displayLink(target:selector:) "]
232 #[inline]
233 pub unsafe fn set_current_cg_display_from_open_gl_context(
234 &self,
235 cgl_context: CGLContextObj,
236 cgl_pixel_format: CGLPixelFormatObj,
237 ) -> CVReturn {
238 extern "C-unwind" {
239 fn CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(
240 display_link: &CVDisplayLink,
241 cgl_context: CGLContextObj,
242 cgl_pixel_format: CGLPixelFormatObj,
243 ) -> CVReturn;
244 }
245 unsafe {
246 CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(self, cgl_context, cgl_pixel_format)
247 }
248 }
249
250 #[doc(alias = "CVDisplayLinkGetCurrentCGDisplay")]
258 #[cfg(feature = "objc2-core-graphics")]
259 #[deprecated = "use NSView.displayLink(target:selector:), NSWindow.displayLink(target:selector:), or NSScreen.displayLink(target:selector:) "]
260 #[inline]
261 pub fn current_cg_display(&self) -> CGDirectDisplayID {
262 extern "C-unwind" {
263 fn CVDisplayLinkGetCurrentCGDisplay(display_link: &CVDisplayLink) -> CGDirectDisplayID;
264 }
265 unsafe { CVDisplayLinkGetCurrentCGDisplay(self) }
266 }
267
268 #[doc(alias = "CVDisplayLinkSetOutputCallback")]
285 #[cfg(all(feature = "CVBase", feature = "CVReturn"))]
286 #[deprecated = "use NSView.displayLink(target:selector:), NSWindow.displayLink(target:selector:), or NSScreen.displayLink(target:selector:) "]
287 #[inline]
288 pub unsafe fn set_output_callback(
289 &self,
290 callback: CVDisplayLinkOutputCallback,
291 user_info: *mut c_void,
292 ) -> CVReturn {
293 extern "C-unwind" {
294 fn CVDisplayLinkSetOutputCallback(
295 display_link: &CVDisplayLink,
296 callback: CVDisplayLinkOutputCallback,
297 user_info: *mut c_void,
298 ) -> CVReturn;
299 }
300 unsafe { CVDisplayLinkSetOutputCallback(self, callback, user_info) }
301 }
302
303 #[doc(alias = "CVDisplayLinkSetOutputHandler")]
317 #[cfg(all(feature = "CVBase", feature = "CVReturn", feature = "block2"))]
318 #[deprecated = "use NSView.displayLink(target:selector:), NSWindow.displayLink(target:selector:), or NSScreen.displayLink(target:selector:) "]
319 #[inline]
320 pub unsafe fn set_output_handler(&self, handler: CVDisplayLinkOutputHandler) -> CVReturn {
321 extern "C-unwind" {
322 fn CVDisplayLinkSetOutputHandler(
323 display_link: &CVDisplayLink,
324 handler: CVDisplayLinkOutputHandler,
325 ) -> CVReturn;
326 }
327 unsafe { CVDisplayLinkSetOutputHandler(self, handler) }
328 }
329
330 #[doc(alias = "CVDisplayLinkStart")]
339 #[cfg(feature = "CVReturn")]
340 #[deprecated = "use NSView.displayLink(target:selector:), NSWindow.displayLink(target:selector:), or NSScreen.displayLink(target:selector:) "]
341 #[inline]
342 pub fn start(&self) -> CVReturn {
343 extern "C-unwind" {
344 fn CVDisplayLinkStart(display_link: &CVDisplayLink) -> CVReturn;
345 }
346 unsafe { CVDisplayLinkStart(self) }
347 }
348
349 #[doc(alias = "CVDisplayLinkStop")]
357 #[cfg(feature = "CVReturn")]
358 #[deprecated = "use NSView.displayLink(target:selector:), NSWindow.displayLink(target:selector:), or NSScreen.displayLink(target:selector:) "]
359 #[inline]
360 pub fn stop(&self) -> CVReturn {
361 extern "C-unwind" {
362 fn CVDisplayLinkStop(display_link: &CVDisplayLink) -> CVReturn;
363 }
364 unsafe { CVDisplayLinkStop(self) }
365 }
366
367 #[doc(alias = "CVDisplayLinkGetNominalOutputVideoRefreshPeriod")]
375 #[cfg(feature = "CVBase")]
376 #[deprecated = "use NSView.displayLink(target:selector:), NSWindow.displayLink(target:selector:), or NSScreen.displayLink(target:selector:) "]
377 #[inline]
378 pub fn nominal_output_video_refresh_period(&self) -> CVTime {
379 extern "C-unwind" {
380 fn CVDisplayLinkGetNominalOutputVideoRefreshPeriod(
381 display_link: &CVDisplayLink,
382 ) -> CVTime;
383 }
384 unsafe { CVDisplayLinkGetNominalOutputVideoRefreshPeriod(self) }
385 }
386
387 #[doc(alias = "CVDisplayLinkGetOutputVideoLatency")]
395 #[cfg(feature = "CVBase")]
396 #[deprecated = "use NSView.displayLink(target:selector:), NSWindow.displayLink(target:selector:), or NSScreen.displayLink(target:selector:) "]
397 #[inline]
398 pub fn output_video_latency(&self) -> CVTime {
399 extern "C-unwind" {
400 fn CVDisplayLinkGetOutputVideoLatency(display_link: &CVDisplayLink) -> CVTime;
401 }
402 unsafe { CVDisplayLinkGetOutputVideoLatency(self) }
403 }
404
405 #[doc(alias = "CVDisplayLinkGetActualOutputVideoRefreshPeriod")]
413 #[deprecated = "use NSView.displayLink(target:selector:), NSWindow.displayLink(target:selector:), or NSScreen.displayLink(target:selector:) "]
414 #[inline]
415 pub fn actual_output_video_refresh_period(&self) -> c_double {
416 extern "C-unwind" {
417 fn CVDisplayLinkGetActualOutputVideoRefreshPeriod(
418 display_link: &CVDisplayLink,
419 ) -> c_double;
420 }
421 unsafe { CVDisplayLinkGetActualOutputVideoRefreshPeriod(self) }
422 }
423
424 #[doc(alias = "CVDisplayLinkIsRunning")]
432 #[deprecated = "use NSView.displayLink(target:selector:), NSWindow.displayLink(target:selector:), or NSScreen.displayLink(target:selector:) "]
433 #[inline]
434 pub fn is_running(&self) -> bool {
435 extern "C-unwind" {
436 fn CVDisplayLinkIsRunning(display_link: &CVDisplayLink) -> Boolean;
437 }
438 let ret = unsafe { CVDisplayLinkIsRunning(self) };
439 ret != 0
440 }
441
442 #[doc(alias = "CVDisplayLinkGetCurrentTime")]
456 #[cfg(all(feature = "CVBase", feature = "CVReturn"))]
457 #[deprecated = "use NSView.displayLink(target:selector:), NSWindow.displayLink(target:selector:), or NSScreen.displayLink(target:selector:) "]
458 #[inline]
459 pub unsafe fn current_time(&self, out_time: NonNull<CVTimeStamp>) -> CVReturn {
460 extern "C-unwind" {
461 fn CVDisplayLinkGetCurrentTime(
462 display_link: &CVDisplayLink,
463 out_time: NonNull<CVTimeStamp>,
464 ) -> CVReturn;
465 }
466 unsafe { CVDisplayLinkGetCurrentTime(self, out_time) }
467 }
468
469 #[doc(alias = "CVDisplayLinkTranslateTime")]
487 #[cfg(all(feature = "CVBase", feature = "CVReturn"))]
488 #[deprecated = "use NSView.displayLink(target:selector:), NSWindow.displayLink(target:selector:), or NSScreen.displayLink(target:selector:) "]
489 #[inline]
490 pub unsafe fn translate_time(
491 &self,
492 in_time: NonNull<CVTimeStamp>,
493 out_time: NonNull<CVTimeStamp>,
494 ) -> CVReturn {
495 extern "C-unwind" {
496 fn CVDisplayLinkTranslateTime(
497 display_link: &CVDisplayLink,
498 in_time: NonNull<CVTimeStamp>,
499 out_time: NonNull<CVTimeStamp>,
500 ) -> CVReturn;
501 }
502 unsafe { CVDisplayLinkTranslateTime(self, in_time, out_time) }
503 }
504}
505
506extern "C-unwind" {
507 #[cfg(all(feature = "CVReturn", feature = "objc2-core-graphics"))]
508 #[deprecated = "renamed to `CVDisplayLink::create_with_cg_displays`"]
509 pub fn CVDisplayLinkCreateWithCGDisplays(
510 display_array: NonNull<CGDirectDisplayID>,
511 count: CFIndex,
512 display_link_out: NonNull<*mut CVDisplayLink>,
513 ) -> CVReturn;
514}
515
516extern "C-unwind" {
517 #[cfg(all(feature = "CVReturn", feature = "objc2-core-graphics"))]
518 #[deprecated = "renamed to `CVDisplayLink::create_with_open_gl_display_mask`"]
519 pub fn CVDisplayLinkCreateWithOpenGLDisplayMask(
520 mask: CGOpenGLDisplayMask,
521 display_link_out: NonNull<*mut CVDisplayLink>,
522 ) -> CVReturn;
523}
524
525extern "C-unwind" {
526 #[cfg(all(feature = "CVReturn", feature = "objc2-core-graphics"))]
527 #[deprecated = "renamed to `CVDisplayLink::create_with_cg_display`"]
528 pub fn CVDisplayLinkCreateWithCGDisplay(
529 display_id: CGDirectDisplayID,
530 display_link_out: NonNull<*mut CVDisplayLink>,
531 ) -> CVReturn;
532}
533
534extern "C-unwind" {
535 #[cfg(feature = "CVReturn")]
536 #[deprecated = "renamed to `CVDisplayLink::create_with_active_cg_displays`"]
537 pub fn CVDisplayLinkCreateWithActiveCGDisplays(
538 display_link_out: NonNull<*mut CVDisplayLink>,
539 ) -> CVReturn;
540}
541
542#[cfg(all(feature = "CVReturn", feature = "objc2-core-graphics"))]
543#[deprecated = "renamed to `CVDisplayLink::set_current_cg_display`"]
544#[inline]
545pub extern "C-unwind" fn CVDisplayLinkSetCurrentCGDisplay(
546 display_link: &CVDisplayLink,
547 display_id: CGDirectDisplayID,
548) -> CVReturn {
549 extern "C-unwind" {
550 fn CVDisplayLinkSetCurrentCGDisplay(
551 display_link: &CVDisplayLink,
552 display_id: CGDirectDisplayID,
553 ) -> CVReturn;
554 }
555 unsafe { CVDisplayLinkSetCurrentCGDisplay(display_link, display_id) }
556}
557
558extern "C-unwind" {
559 #[cfg(all(feature = "CVReturn", feature = "objc2-open-gl"))]
560 #[cfg(target_os = "macos")]
561 #[deprecated = "renamed to `CVDisplayLink::set_current_cg_display_from_open_gl_context`"]
562 pub fn CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(
563 display_link: &CVDisplayLink,
564 cgl_context: CGLContextObj,
565 cgl_pixel_format: CGLPixelFormatObj,
566 ) -> CVReturn;
567}
568
569#[cfg(feature = "objc2-core-graphics")]
570#[deprecated = "renamed to `CVDisplayLink::current_cg_display`"]
571#[inline]
572pub extern "C-unwind" fn CVDisplayLinkGetCurrentCGDisplay(
573 display_link: &CVDisplayLink,
574) -> CGDirectDisplayID {
575 extern "C-unwind" {
576 fn CVDisplayLinkGetCurrentCGDisplay(display_link: &CVDisplayLink) -> CGDirectDisplayID;
577 }
578 unsafe { CVDisplayLinkGetCurrentCGDisplay(display_link) }
579}
580
581extern "C-unwind" {
582 #[cfg(all(feature = "CVBase", feature = "CVReturn"))]
583 #[deprecated = "renamed to `CVDisplayLink::set_output_callback`"]
584 pub fn CVDisplayLinkSetOutputCallback(
585 display_link: &CVDisplayLink,
586 callback: CVDisplayLinkOutputCallback,
587 user_info: *mut c_void,
588 ) -> CVReturn;
589}
590
591extern "C-unwind" {
592 #[cfg(all(feature = "CVBase", feature = "CVReturn", feature = "block2"))]
593 #[deprecated = "renamed to `CVDisplayLink::set_output_handler`"]
594 pub fn CVDisplayLinkSetOutputHandler(
595 display_link: &CVDisplayLink,
596 handler: CVDisplayLinkOutputHandler,
597 ) -> CVReturn;
598}
599
600#[cfg(feature = "CVReturn")]
601#[deprecated = "renamed to `CVDisplayLink::start`"]
602#[inline]
603pub extern "C-unwind" fn CVDisplayLinkStart(display_link: &CVDisplayLink) -> CVReturn {
604 extern "C-unwind" {
605 fn CVDisplayLinkStart(display_link: &CVDisplayLink) -> CVReturn;
606 }
607 unsafe { CVDisplayLinkStart(display_link) }
608}
609
610#[cfg(feature = "CVReturn")]
611#[deprecated = "renamed to `CVDisplayLink::stop`"]
612#[inline]
613pub extern "C-unwind" fn CVDisplayLinkStop(display_link: &CVDisplayLink) -> CVReturn {
614 extern "C-unwind" {
615 fn CVDisplayLinkStop(display_link: &CVDisplayLink) -> CVReturn;
616 }
617 unsafe { CVDisplayLinkStop(display_link) }
618}
619
620#[cfg(feature = "CVBase")]
621#[deprecated = "renamed to `CVDisplayLink::nominal_output_video_refresh_period`"]
622#[inline]
623pub extern "C-unwind" fn CVDisplayLinkGetNominalOutputVideoRefreshPeriod(
624 display_link: &CVDisplayLink,
625) -> CVTime {
626 extern "C-unwind" {
627 fn CVDisplayLinkGetNominalOutputVideoRefreshPeriod(display_link: &CVDisplayLink) -> CVTime;
628 }
629 unsafe { CVDisplayLinkGetNominalOutputVideoRefreshPeriod(display_link) }
630}
631
632#[cfg(feature = "CVBase")]
633#[deprecated = "renamed to `CVDisplayLink::output_video_latency`"]
634#[inline]
635pub extern "C-unwind" fn CVDisplayLinkGetOutputVideoLatency(
636 display_link: &CVDisplayLink,
637) -> CVTime {
638 extern "C-unwind" {
639 fn CVDisplayLinkGetOutputVideoLatency(display_link: &CVDisplayLink) -> CVTime;
640 }
641 unsafe { CVDisplayLinkGetOutputVideoLatency(display_link) }
642}
643
644#[deprecated = "renamed to `CVDisplayLink::actual_output_video_refresh_period`"]
645#[inline]
646pub extern "C-unwind" fn CVDisplayLinkGetActualOutputVideoRefreshPeriod(
647 display_link: &CVDisplayLink,
648) -> c_double {
649 extern "C-unwind" {
650 fn CVDisplayLinkGetActualOutputVideoRefreshPeriod(display_link: &CVDisplayLink)
651 -> c_double;
652 }
653 unsafe { CVDisplayLinkGetActualOutputVideoRefreshPeriod(display_link) }
654}
655
656#[deprecated = "renamed to `CVDisplayLink::is_running`"]
657#[inline]
658pub extern "C-unwind" fn CVDisplayLinkIsRunning(display_link: &CVDisplayLink) -> bool {
659 extern "C-unwind" {
660 fn CVDisplayLinkIsRunning(display_link: &CVDisplayLink) -> Boolean;
661 }
662 let ret = unsafe { CVDisplayLinkIsRunning(display_link) };
663 ret != 0
664}
665
666extern "C-unwind" {
667 #[cfg(all(feature = "CVBase", feature = "CVReturn"))]
668 #[deprecated = "renamed to `CVDisplayLink::current_time`"]
669 pub fn CVDisplayLinkGetCurrentTime(
670 display_link: &CVDisplayLink,
671 out_time: NonNull<CVTimeStamp>,
672 ) -> CVReturn;
673}
674
675extern "C-unwind" {
676 #[cfg(all(feature = "CVBase", feature = "CVReturn"))]
677 #[deprecated = "renamed to `CVDisplayLink::translate_time`"]
678 pub fn CVDisplayLinkTranslateTime(
679 display_link: &CVDisplayLink,
680 in_time: NonNull<CVTimeStamp>,
681 out_time: NonNull<CVTimeStamp>,
682 ) -> CVReturn;
683}