From 833e984ed178ad557899f7b45d6daac7ecfd6dd6 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sat, 11 Jun 2022 02:17:14 +0200 Subject: [PATCH] Remove core-video-sys dependency Hasn't been updated in over 2 years - many open PRs, seems abandoned. Is the cause of several duplicate dependencies in our dependency tree! --- Cargo.toml | 5 ---- src/platform_impl/macos/ffi.rs | 42 ++++++++++++++++++++++++++++++ src/platform_impl/macos/monitor.rs | 16 +++++------- 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d98a6bc1c2..7582a9ce14 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,11 +51,6 @@ core-foundation = "0.9" core-graphics = "0.22" dispatch = "0.2.0" -[target.'cfg(target_os = "macos")'.dependencies.core-video-sys] -version = "0.1.4" -default_features = false -features = ["display_link"] - [target.'cfg(target_os = "windows")'.dependencies] parking_lot = "0.12" diff --git a/src/platform_impl/macos/ffi.rs b/src/platform_impl/macos/ffi.rs index 229bd6598d..0a23e60d41 100644 --- a/src/platform_impl/macos/ffi.rs +++ b/src/platform_impl/macos/ffi.rs @@ -221,3 +221,45 @@ extern "C" { pub fn CGDisplayModeRetain(mode: CGDisplayModeRef); pub fn CGDisplayModeRelease(mode: CGDisplayModeRef); } + +mod core_video { + use super::*; + + #[link(name = "CoreVideo", kind = "framework")] + extern "C" {} + + // CVBase.h + + pub type CVTimeFlags = i32; // int32_t + pub const kCVTimeIsIndefinite: CVTimeFlags = 1 << 0; + + #[repr(C)] + #[derive(Debug, Clone)] + pub struct CVTime { + pub time_value: i64, // int64_t + pub time_scale: i32, // int32_t + pub flags: i32, // int32_t + } + + // CVReturn.h + + pub type CVReturn = i32; // int32_t + pub const kCVReturnSuccess: CVReturn = 0; + + // CVDisplayLink.h + + pub type CVDisplayLinkRef = *mut c_void; + + extern "C" { + pub fn CVDisplayLinkCreateWithCGDisplay( + displayID: CGDirectDisplayID, + displayLinkOut: *mut CVDisplayLinkRef, + ) -> CVReturn; + pub fn CVDisplayLinkGetNominalOutputVideoRefreshPeriod( + displayLink: CVDisplayLinkRef, + ) -> CVTime; + pub fn CVDisplayLinkRelease(displayLink: CVDisplayLinkRef); + } +} + +pub use core_video::*; diff --git a/src/platform_impl/macos/monitor.rs b/src/platform_impl/macos/monitor.rs index 08dba6c9f9..d421951e1d 100644 --- a/src/platform_impl/macos/monitor.rs +++ b/src/platform_impl/macos/monitor.rs @@ -16,10 +16,6 @@ use core_foundation::{ string::CFString, }; use core_graphics::display::{CGDirectDisplayID, CGDisplay, CGDisplayBounds}; -use core_video_sys::{ - kCVReturnSuccess, kCVTimeIsIndefinite, CVDisplayLinkCreateWithCGDisplay, - CVDisplayLinkGetNominalOutputVideoRefreshPeriod, CVDisplayLinkRelease, -}; #[derive(Clone)] pub struct VideoMode { @@ -228,16 +224,16 @@ impl MonitorHandle { let cv_refresh_rate = unsafe { let mut display_link = std::ptr::null_mut(); assert_eq!( - CVDisplayLinkCreateWithCGDisplay(self.0, &mut display_link), - kCVReturnSuccess + ffi::CVDisplayLinkCreateWithCGDisplay(self.0, &mut display_link), + ffi::kCVReturnSuccess ); - let time = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(display_link); - CVDisplayLinkRelease(display_link); + let time = ffi::CVDisplayLinkGetNominalOutputVideoRefreshPeriod(display_link); + ffi::CVDisplayLinkRelease(display_link); // This value is indefinite if an invalid display link was specified - assert!(time.flags & kCVTimeIsIndefinite == 0); + assert!(time.flags & ffi::kCVTimeIsIndefinite == 0); - time.timeScale as i64 / time.timeValue + time.time_scale as i64 / time.time_value }; let monitor = self.clone();