1
mirror of https://github.com/mpv-player/mpv synced 2024-11-03 03:19:24 +01:00

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.
This commit is contained in:
Akemi 2018-02-22 23:56:49 +01:00 committed by Kevin Mitchell
parent 1f2d8ed01c
commit 7fff1b6c10

View File

@ -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) {