From 9e466ee6214ed302a6846dd40264cf06eb712b3a Mon Sep 17 00:00:00 2001 From: Akemi Date: Tue, 12 Jun 2018 02:48:31 +0200 Subject: 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. --- video/out/cocoa-cb/video_layer.swift | 40 ++++++++++++------------------------ 1 file changed, 13 insertions(+), 27 deletions(-) (limited to 'video/out/cocoa-cb/video_layer.swift') 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?) { 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() } } -- cgit v1.2.3