cocoa-cb: fix drawing on macOS 10.11

the CVDisplayLinkSetOutputHandler function introduced with 10.11 is
broken on the very same version of the OS, which caused our render loop
never to start. fallback to the old display link callback on 10.11.
for reference the radar http://www.openradar.me/26640780

Fixes #5527
This commit is contained in:
Akemi 2018-02-14 16:42:15 +01:00 committed by Kevin Mitchell
parent 6751b5b1c2
commit 31ee350cce
1 changed files with 19 additions and 3 deletions

View File

@ -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!)
}