From 8bfeecbc6ff1c95682b908a7e4beb87dd83fb3b7 Mon Sep 17 00:00:00 2001 From: Akemi Date: Mon, 5 Mar 2018 02:11:25 +0100 Subject: cocoa-cb: change handling of window aspect ratio changes i tried being smart and handle aspect ratio differences manually via atomic drawing and resizing to aspect fitted frames. there were a few issues with that. like unexpected visibility of certain System GUI elements on entering fullscreen or visually dropped frames due to the atomic drawing. now we rely on system mechanics to keep the proper aspect ratio of our layer, the recommended way. as a side effect it also fixes a segfault. Fixes #5581 --- video/out/cocoa-cb/video_layer.swift | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 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 c5604b88f7..8cdb692ae5 100644 --- a/video/out/cocoa-cb/video_layer.swift +++ b/video/out/cocoa-cb/video_layer.swift @@ -30,11 +30,10 @@ class VideoLayer: CAOpenGLLayer { var hasVideo: Bool = false var neededFlips: Int = 0 var cglContext: CGLContextObj? = nil + var surfaceSize: NSSize? enum Draw: Int { case normal = 1, atomic, atomicEnd } var draw: Draw = .normal - let drawLock = NSLock() - var surfaceSize: NSSize? var canDrawOffScreen: Bool = false var lastThread: Thread? = nil @@ -49,10 +48,7 @@ class VideoLayer: CAOpenGLLayer { var inLiveResize: Bool = false { didSet { - if inLiveResize == false { - isAsynchronous = false - neededFlips += 1 - } else { + if inLiveResize { isAsynchronous = true } } @@ -86,6 +82,9 @@ class VideoLayer: CAOpenGLLayer { pixelFormat pf: CGLPixelFormatObj, forLayerTime t: CFTimeInterval, displayTime ts: UnsafePointer?) -> Bool { + if inLiveResize == false { + isAsynchronous = false + } return mpv != nil && cocoaCB.backendState == .init } @@ -100,13 +99,7 @@ class VideoLayer: CAOpenGLLayer { } func draw(_ ctx: CGLContextObj) { - drawLock.lock() - updateSurfaceSize() - - let aspectRatioDiff = fabs( (surfaceSize!.width/surfaceSize!.height) - - (bounds.size.width/bounds.size.height) ) - - if aspectRatioDiff <= 0.005 && draw.rawValue >= Draw.atomic.rawValue { + if draw.rawValue >= Draw.atomic.rawValue { if draw == .atomic { draw = .atomicEnd } else { @@ -114,9 +107,9 @@ class VideoLayer: CAOpenGLLayer { } } + updateSurfaceSize() mpv.drawRender(surfaceSize!) CGLFlushDrawable(ctx) - drawLock.unlock() if needsICCUpdate { needsICCUpdate = false @@ -148,7 +141,7 @@ class VideoLayer: CAOpenGLLayer { NSEnableScreenUpdates() draw = .normal } - } + } override func copyCGLPixelFormat(forDisplayMask mask: UInt32) -> CGLPixelFormatObj { let glVersions: [CGLOpenGLProfile] = [ -- cgit v1.2.3