diff options
Diffstat (limited to 'video/out/mac_common.swift')
-rw-r--r-- | video/out/mac_common.swift | 75 |
1 files changed, 37 insertions, 38 deletions
diff --git a/video/out/mac_common.swift b/video/out/mac_common.swift index 349712b..f29815d 100644 --- a/video/out/mac_common.swift +++ b/video/out/mac_common.swift @@ -20,16 +20,18 @@ import Cocoa class MacCommon: Common { @objc var layer: MetalLayer? + var presentation: Presentation? var timer: PreciseTimer? var swapTime: UInt64 = 0 let swapLock: NSCondition = NSCondition() - var needsICCUpdate: Bool = false - @objc init(_ vo: UnsafeMutablePointer<vo>) { - let newlog = mp_log_new(vo, vo.pointee.log, "mac") - super.init(newlog) - mpv = MPVHelper(vo, log) + let log = LogHelper(mp_log_new(vo, vo.pointee.log, "mac")) + let option = OptionHelper(vo, vo.pointee.global) + super.init(option, log) + self.vo = vo + input = InputHelper(vo.pointee.input_ctx, option) + presentation = Presentation(common: self) timer = PreciseTimer(common: self) DispatchQueue.main.sync { @@ -39,16 +41,16 @@ class MacCommon: Common { } @objc func config(_ vo: UnsafeMutablePointer<vo>) -> Bool { - mpv?.vo = vo + self.vo = vo DispatchQueue.main.sync { let previousActiveApp = getActiveApp() initApp() - let (_, _, wr) = getInitProperties(vo) + let (_, wr) = getInitProperties(vo) guard let layer = self.layer else { - log.sendError("Something went wrong, no MetalLayer was initialized") + log.error("Something went wrong, no MetalLayer was initialized") exit(1) } @@ -58,12 +60,18 @@ class MacCommon: Common { initWindowState() } - if !NSEqualSizes(window?.unfsContentFramePixel.size ?? NSZeroSize, wr.size) { + if !NSEqualSizes(window?.unfsContentFramePixel.size ?? NSZeroSize, wr.size) && + option.vo.auto_window_resize + { window?.updateSize(wr.size) } + if option.vo.focus_on == 2 { + NSApp.activate(ignoringOtherApps: true) + } + windowDidResize() - needsICCUpdate = true + updateICCProfile() } return true @@ -83,7 +91,7 @@ class MacCommon: Common { } @objc func swapBuffer() { - if mpv?.macOpts.macos_render_timer ?? Int32(RENDER_TIMER_CALLBACK) != RENDER_TIMER_SYSTEM { + if option.mac.macos_render_timer > RENDER_TIMER_SYSTEM { swapLock.lock() while(swapTime < 1) { swapLock.wait() @@ -91,18 +99,16 @@ class MacCommon: Common { swapTime = 0 swapLock.unlock() } - - if needsICCUpdate { - needsICCUpdate = false - updateICCProfile() - } } - func updateRenderSize(_ size: NSSize) { - mpv?.vo.pointee.dwidth = Int32(size.width) - mpv?.vo.pointee.dheight = Int32(size.height) - flagEvents(VO_EVENT_RESIZE | VO_EVENT_EXPOSE) - } + @objc func fillVsync(info: UnsafeMutablePointer<vo_vsync_info>) { + if option.mac.macos_render_timer != RENDER_TIMER_PRESENTATION_FEEDBACK { return } + + let next = presentation?.next() + info.pointee.vsync_duration = next?.duration ?? -1 + info.pointee.skipped_vsyncs = next?.skipped ?? -1 + info.pointee.last_queue_display_time = next?.time ?? -1 + } override func displayLinkCallback(_ displayLink: CVDisplayLink, _ inNow: UnsafePointer<CVTimeStamp>, @@ -110,7 +116,6 @@ class MacCommon: Common { _ flagsIn: CVOptionFlags, _ flagsOut: UnsafeMutablePointer<CVOptionFlags>) -> CVReturn { - let frameTimer = mpv?.macOpts.macos_render_timer ?? Int32(RENDER_TIMER_CALLBACK) let signalSwap = { self.swapLock.lock() self.swapTime += 1 @@ -118,13 +123,18 @@ class MacCommon: Common { self.swapLock.unlock() } - if frameTimer != RENDER_TIMER_SYSTEM { - if let timer = self.timer, frameTimer == RENDER_TIMER_PRECISE { + if option.mac.macos_render_timer > RENDER_TIMER_SYSTEM { + if let timer = self.timer, option.mac.macos_render_timer == RENDER_TIMER_PRECISE { timer.scheduleAt(time: inOutputTime.pointee.hostTime, closure: signalSwap) return kCVReturnSuccess } signalSwap() + return kCVReturnSuccess + } + + if option.mac.macos_render_timer == RENDER_TIMER_PRESENTATION_FEEDBACK { + presentation?.add(time: inOutputTime.pointee) } return kCVReturnSuccess @@ -144,27 +154,16 @@ class MacCommon: Common { flagEvents(VO_EVENT_AMBIENT_LIGHTING_CHANGED) } - @objc override func updateICCProfile() { - guard let colorSpace = window?.screen?.colorSpace else { - log.sendWarning("Couldn't update ICC Profile, no color space available") - return - } - - layer?.colorspace = colorSpace.cgColorSpace + override func updateICCProfile() { flagEvents(VO_EVENT_ICC_PROFILE_CHANGED) } override func windowDidResize() { - guard let window = window else { - log.sendWarning("No window available on window resize event") - return - } - - updateRenderSize(window.framePixel.size) + flagEvents(VO_EVENT_RESIZE | VO_EVENT_EXPOSE) } override func windowDidChangeScreenProfile() { - needsICCUpdate = true + updateICCProfile() } override func windowDidChangeBackingProperties() { |