diff options
author | Akemi <der.richter@gmx.de> | 2018-06-12 02:48:31 +0200 |
---|---|---|
committer | Jan Ekström <jeebjp@gmail.com> | 2018-11-13 20:43:29 +0200 |
commit | 9e466ee6214ed302a6846dd40264cf06eb712b3a (patch) | |
tree | 174510e25423da823810d416cb7ceb0392c256b1 /video | |
parent | 317d3ac26634d6719c2c70e3e88acbf0c108fd73 (diff) |
cocoa-cb: use libmpv's advanced rendering control and timing
this adds support for GPU rendered screenshots, DR (theoretically) and
possible other advanced functions in the future that need to be executed
from the rendering thread.
additionally frames that would be off screen or not be displayed when on
screen are being dropped now.
Diffstat (limited to 'video')
-rw-r--r-- | video/out/cocoa-cb/video_layer.swift | 40 | ||||
-rw-r--r-- | video/out/cocoa-cb/window.swift | 6 | ||||
-rw-r--r-- | video/out/cocoa_cb_common.swift | 4 |
3 files changed, 19 insertions, 31 deletions
diff --git a/video/out/cocoa-cb/video_layer.swift b/video/out/cocoa-cb/video_layer.swift index d6456abe9b..0e14e45dc3 100644 --- a/video/out/cocoa-cb/video_layer.swift +++ b/video/out/cocoa-cb/video_layer.swift @@ -28,9 +28,8 @@ class VideoLayer: CAOpenGLLayer { let videoLock = NSLock() let displayLock = NSLock() - var hasVideo: Bool = false var needsFlip: Bool = false - var canDrawOffScreen: Bool = false + var forceDraw: Bool = false var cglContext: CGLContextObj? = nil var cglPixelFormat: CGLPixelFormatObj? = nil var surfaceSize: NSSize? @@ -53,7 +52,7 @@ class VideoLayer: CAOpenGLLayer { if inLiveResize { isAsynchronous = true } - update() + update(force: true) } } @@ -91,7 +90,8 @@ class VideoLayer: CAOpenGLLayer { if inLiveResize == false { isAsynchronous = false } - return mpv != nil && cocoaCB.backendState == .initialized + return mpv != nil && cocoaCB.backendState == .initialized && + (forceDraw || mpv.isRenderUpdateFrame()) } override func draw(inCGLContext ctx: CGLContextObj, @@ -99,11 +99,8 @@ class VideoLayer: CAOpenGLLayer { forLayerTime t: CFTimeInterval, displayTime ts: UnsafePointer<CVTimeStamp>?) { needsFlip = false - canDrawOffScreen = true - draw(ctx) - } + forceDraw = false - func draw(_ ctx: CGLContextObj) { if draw.rawValue >= Draw.atomic.rawValue { if draw == .atomic { draw = .atomicEnd @@ -135,7 +132,7 @@ class VideoLayer: CAOpenGLLayer { } func atomicDrawingStart() { - if draw == .normal && hasVideo { + if draw == .normal { NSDisableScreenUpdates() draw = .atomic } @@ -225,33 +222,22 @@ class VideoLayer: CAOpenGLLayer { let isUpdate = needsFlip super.display() CATransaction.flush() - if isUpdate { - if !cocoaCB.window.occlusionState.contains(.visible) && - needsFlip && canDrawOffScreen - { - CGLSetCurrentContext(cglContext!) - draw(cglContext!) - } else if needsFlip { - update() + if isUpdate && needsFlip { + CGLSetCurrentContext(cglContext!) + if mpv.isRenderUpdateFrame() { + mpv.drawRender(NSZeroSize, skip: true) } } displayLock.unlock() } - func setVideo(_ state: Bool) { - videoLock.lock() - hasVideo = state - videoLock.unlock() - } - - func update() { + func update(force: Bool = false) { + if force { forceDraw = true } queue.async { - self.videoLock.lock() - if !self.inLiveResize && self.hasVideo { + if self.forceDraw || !self.inLiveResize { self.needsFlip = true self.display() } - self.videoLock.unlock() } } diff --git a/video/out/cocoa-cb/window.swift b/video/out/cocoa-cb/window.swift index 34a73f88d1..d11706f38b 100644 --- a/video/out/cocoa-cb/window.swift +++ b/video/out/cocoa-cb/window.swift @@ -613,6 +613,12 @@ class Window: NSWindow, NSWindowDelegate { cocoaCB.updateCusorVisibility() } + func windowDidChangeOcclusionState(_ notification: Notification) { + if occlusionState.contains(.visible) { + cocoaCB.layer.update(force: true) + } + } + func windowWillMove(_ notification: Notification) { isMoving = true } diff --git a/video/out/cocoa_cb_common.swift b/video/out/cocoa_cb_common.swift index 790a07deb8..355fa537e1 100644 --- a/video/out/cocoa_cb_common.swift +++ b/video/out/cocoa_cb_common.swift @@ -72,7 +72,6 @@ class CocoaCB: NSObject { } func uninit() { - layer.setVideo(false) window.orderOut(nil) } @@ -81,7 +80,6 @@ class CocoaCB: NSObject { DispatchQueue.main.sync { self.initBackend(vo) } } else { DispatchQueue.main.async { - self.layer.setVideo(true) self.updateWindowSize(vo) self.layer.update() } @@ -106,7 +104,6 @@ class CocoaCB: NSObject { window.makeMain() window.makeKeyAndOrderFront(nil) NSApp.activate(ignoringOtherApps: true) - layer.setVideo(true) if Bool(opts.fullscreen) { DispatchQueue.main.async { @@ -449,7 +446,6 @@ class CocoaCB: NSObject { func shutdown(_ destroy: Bool = false) { setCursorVisiblility(true) - layer.setVideo(false) stopDisplaylink() uninitLightSensor() removeDisplayReconfigureObserver() |