diff options
Diffstat (limited to 'video/out/cocoa_cb_common.swift')
-rw-r--r-- | video/out/cocoa_cb_common.swift | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/video/out/cocoa_cb_common.swift b/video/out/cocoa_cb_common.swift index 9a6da82ecf..0ce06428bd 100644 --- a/video/out/cocoa_cb_common.swift +++ b/video/out/cocoa_cb_common.swift @@ -141,13 +141,29 @@ class CocoaCB: NSObject { } } + let linkCallback: CVDisplayLinkOutputCallback = { + (displayLink: CVDisplayLink, + inNow: UnsafePointer<CVTimeStamp>, + inOutputTime: UnsafePointer<CVTimeStamp>, + flagsIn: CVOptionFlags, + flagsOut: UnsafeMutablePointer<CVOptionFlags>, + displayLinkContext: UnsafeMutableRawPointer?) -> CVReturn in + let ccb: CocoaCB = MPVHelper.bridge(ptr: displayLinkContext!) + ccb.layer.reportFlip() + return kCVReturnSuccess + } + func startDisplayLink() { let displayId = UInt32(window.screen!.deviceDescription["NSScreenNumber"] as! Int) CVDisplayLinkCreateWithActiveCGDisplays(&link) CVDisplayLinkSetCurrentCGDisplay(link!, displayId) - CVDisplayLinkSetOutputHandler(link!) { link, now, out, inFlags, outFlags -> CVReturn in - self.layer.reportFlip() - return kCVReturnSuccess + if #available(macOS 10.12, *) { + CVDisplayLinkSetOutputHandler(link!) { link, now, out, inFlags, outFlags -> CVReturn in + self.layer.reportFlip() + return kCVReturnSuccess + } + } else { + CVDisplayLinkSetOutputCallback(link!, linkCallback, MPVHelper.bridge(obj: self)) } CVDisplayLinkStart(link!) } |