Last active
October 30, 2023 04:17
-
-
Save eyeplum/353be4bd4e62fa05cbf1 to your computer and use it in GitHub Desktop.
CVDisplayLinkOutputCallback in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func createDisplayLink() { | |
CVDisplayLinkCreateWithActiveCGDisplays(&displayLink) | |
guard let displayLink = displayLink else { | |
return | |
} | |
let callback: CVDisplayLinkOutputCallback = { (_, _, _, _, _, userInfo) -> CVReturn in | |
let myView = Unmanaged<MyView>.fromOpaque(COpaquePointer(userInfo)).takeUnretainedValue() | |
dispatch_async(dispatch_get_main_queue()) { | |
myView.update() | |
} | |
return kCVReturnSuccess | |
} | |
let userInfo = UnsafeMutablePointer<Void>(Unmanaged.passUnretained(self).toOpaque()) | |
CVDisplayLinkSetOutputCallback(displayLink, callback, userInfo) | |
CVDisplayLinkStart(displayLink) | |
} | |
private func update() { | |
// Do your view updates | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment