From 7fff1b6c10e53ba3139eb06a2598d1587c969741 Mon Sep 17 00:00:00 2001 From: Akemi Date: Thu, 22 Feb 2018 23:56:49 +0100 Subject: cocoa-cb: fix wrong drawing size on resize on live resize, eg async resize, the layer's bounds size is not in sync with the actual surface size. this led to a wrongly sized frame and a perceived flicker. get and use the actual surface size instead. --- video/out/cocoa-cb/video_layer.swift | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'video/out') diff --git a/video/out/cocoa-cb/video_layer.swift b/video/out/cocoa-cb/video_layer.swift index ed259d04f5..2cea79bf3a 100644 --- a/video/out/cocoa-cb/video_layer.swift +++ b/video/out/cocoa-cb/video_layer.swift @@ -42,18 +42,14 @@ class VideoLayer: CAOpenGLLayer { } } - let surfaceLock = NSLock() var surfaceSize: NSSize? var inLiveResize: Bool = false { didSet { if inLiveResize == false { isAsynchronous = false - display() + neededFlips += 1 } else { - surfaceLock.lock() - updateSurfaceSize() - surfaceLock.unlock() isAsynchronous = true } } @@ -101,13 +97,8 @@ class VideoLayer: CAOpenGLLayer { } func draw(_ ctx: CGLContextObj) { - surfaceLock.lock() - if inLiveResize == false { - updateSurfaceSize() - } - + updateSurfaceSize() mpv.drawGLCB(surfaceSize!) - surfaceLock.unlock() CGLFlushDrawable(ctx) if needsICCUpdate { @@ -117,9 +108,15 @@ class VideoLayer: CAOpenGLLayer { } func updateSurfaceSize() { - surfaceSize = bounds.size - surfaceSize!.width *= contentsScale - surfaceSize!.height *= contentsScale + var dims: [GLint] = [0, 0, 0, 0] + glGetIntegerv(GLenum(GL_VIEWPORT), &dims) + surfaceSize = NSMakeSize(CGFloat(dims[2]), CGFloat(dims[3])) + + if NSEqualSizes(surfaceSize!, NSZeroSize) { + surfaceSize = bounds.size + surfaceSize!.width *= contentsScale + surfaceSize!.height *= contentsScale + } } override func copyCGLPixelFormat(forDisplayMask mask: UInt32) -> CGLPixelFormatObj { @@ -179,9 +176,7 @@ class VideoLayer: CAOpenGLLayer { override func display() { super.display() - if !isAsynchronous { - CATransaction.flush() - } + CATransaction.flush() } func setVideo(_ state: Bool) { -- cgit v1.2.3