Skip to content

Commit

Permalink
fix: remove core-video-sys dependency, closes #435 (#441)
Browse files Browse the repository at this point in the history
Co-authored-by: Mads Marquart <mads@marquart.dk>
Co-authored-by: Ngo Iok Ui (Wu Yu Wei) <wusyong9104@gmail.com>
  • Loading branch information
3 people committed Jun 22, 2022
1 parent 054a34e commit 3bb09aa
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .changes/remove-core-display-sys-dep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"tao": patch
---
Remvoe `core-video-sys` dependency.
5 changes: 0 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ dispatch = "0.2"
scopeguard = "1.1"
png = "0.17"

[target."cfg(target_os = \"macos\")".dependencies.tao-core-video-sys]
version = "0.2"
default_features = false
features = [ "display_link" ]

[target."cfg(target_os = \"macos\")".build-dependencies]
cc = "1"

Expand Down
43 changes: 43 additions & 0 deletions src/platform_impl/macos/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
clippy::enum_variant_names
)]

use std::ffi::c_void;

use cocoa::{
base::id,
foundation::{NSInteger, NSUInteger},
Expand Down Expand Up @@ -281,3 +283,44 @@ extern "C" {
unicodeString: *mut UniChar,
) -> OSStatus;
}

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::*;
16 changes: 6 additions & 10 deletions src/platform_impl/macos/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,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 {
Expand Down Expand Up @@ -231,16 +227,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();
Expand Down

0 comments on commit 3bb09aa

Please sign in to comment.