 }
 
 #elseif os(macOS) // macOS support using CVDisplayLink --------------------------------------------------
+
+import CoreVideo
 
 extension DisplayLink {
     




#if os(iOS) || os(tvOS) // iOS support using CADisplayLink --------------------------------------------------------

/// DisplayLink is used to hook into screen refreshes.
extension DisplayLink {

    }
}

#else // Linux support using a simple timer --------------------------------------------------

private let frameDuration: TimeInterval = 1.0/120.0

extension DisplayLink {
    
    /// DisplayLink is used to hook into screen refreshes.
    fileprivate final class Driver {
        
        private var timer: Timer? = nil
        
        /// The callback to call for each frame.
        var onFrame: ((Frame) -> Void)? = nil
        
        /// If the display link is paused or not.
        var isPaused: Bool = true {
            didSet {
                guard isPaused != oldValue else { return }
                if isPaused {
                    stop()
                } else {
                    start()
                }
            }
        }
        

        init() {
            
        }
        
        deinit {
            isPaused = true
        }
        
        private func start() {
            guard timer == nil else { return }
            let timer = Timer(
                fire: Date(),
                interval: frameDuration,
                repeats: true,
                block: { [weak self] timer in
                    let timestamp = Date().timeIntervalSince1970
                    let frame = Frame(
                        previousTimestamp: timestamp-frameDuration,
                        timestamp: timestamp)
                    self?.handle(frame: frame)
                })
            self.timer = timer
            RunLoop.main.add(timer, forMode: .common)
        }
        
        private func stop() {
            guard let timer = timer else { return }
            timer.invalidate()
            self.timer = nil
        }
        
        func handle(frame: Frame) {
            guard isPaused == false else { return }
            onFrame?(frame)
        }
        
    }
}

#endif // ------------------------------------------------------------------------------------------
