Skip to content
Permalink
Browse files

Fix stretched screen when entering and exiting fullscreen

  • Loading branch information...
alejx committed Apr 1, 2019
1 parent 36311f9 commit 73b8b065f72594c2001c3f6c3fc7c913507eb43a
Showing with 30 additions and 31 deletions.
  1. +3 −0 iina/MPVController.swift
  2. +15 −30 iina/MainWindowController.swift
  3. +12 −1 iina/ViewLayer.swift
@@ -1080,6 +1080,9 @@ fileprivate func mpvGetOpenGLFunc(_ ctx: UnsafeMutableRawPointer?, _ name: Unsaf

fileprivate func mpvUpdateCallback(_ ctx: UnsafeMutableRawPointer?) {
let layer = unsafeBitCast(ctx, to: ViewLayer.self)
if layer.blocked {
return
}
layer.mpvGLQueue.async {
layer.draw()
}
@@ -1335,9 +1335,6 @@ class MainWindowController: NSWindowController, NSWindowDelegate {
exitInteractiveMode(immediately: true)
}

// Let mpv decide the correct render region in full screen
player.mpv.setFlag(MPVOption.Window.keepaspect, true)

// Set the appearance to match the theme so the titlebar matches the theme
let iinaTheme = Preference.enum(for: .themeMaterial) as Preference.Theme
if #available(macOS 10.14, *) {
@@ -1376,7 +1373,9 @@ class MainWindowController: NSWindowController, NSWindowDelegate {
exitPIP()
}

videoView.videoLayer.mpvGLQueue.suspend()
videoView.videoLayer.suspend()
// Let mpv decide the correct render region in full screen
player.mpv.setFlag(MPVOption.Window.keepaspect, true)
}

func windowDidEnterFullScreen(_ notification: Notification) {
@@ -1385,19 +1384,12 @@ class MainWindowController: NSWindowController, NSWindowDelegate {
titleTextField?.alphaValue = 1
removeStandardButtonsFromFadeableViews()

videoView.videoLayer.mpvGLQueue.resume()

// we must block the mpv rendering queue to do the following atomically
videoView.videoLayer.mpvGLQueue.async {
DispatchQueue.main.sync {
for (_, constraint) in self.videoViewConstraints {
constraint.constant = 0
}
self.videoView.needsLayout = true
self.videoView.layoutSubtreeIfNeeded()
self.videoView.videoLayer.draw()
}
for (_, constraint) in self.videoViewConstraints {
constraint.constant = 0
}
self.videoView.needsLayout = true
self.videoView.layoutSubtreeIfNeeded()
videoView.videoLayer.resume()

if Preference.bool(for: .blackOutMonitor) {
blackOutOtherMonitors()
@@ -1440,31 +1432,24 @@ class MainWindowController: NSWindowController, NSWindowDelegate {

fsState.startAnimatingToWindow()

videoView.videoLayer.mpvGLQueue.suspend()
videoView.videoLayer.suspend()
self.player.mpv.setFlag(MPVOption.Window.keepaspect, false)
}

func windowDidExitFullScreen(_ notification: Notification) {
videoView.videoLayer.mpvGLQueue.resume()

if oscPosition != .top {
addBackTitlebarViewToFadeableViews()
}
addBackStandardButtonsToFadeableViews()
titleBarView.isHidden = false
showUI()

videoView.videoLayer.mpvGLQueue.async {
// reset `keepaspect`
self.player.mpv.setFlag(MPVOption.Window.keepaspect, false)
DispatchQueue.main.sync {
for (_, constraint) in self.videoViewConstraints {
constraint.constant = 0
}
self.videoView.needsLayout = true
self.videoView.layoutSubtreeIfNeeded()
self.videoView.videoLayer.draw()
}
for (_, constraint) in self.videoViewConstraints {
constraint.constant = 0
}
videoView.needsLayout = true
videoView.layoutSubtreeIfNeeded()
videoView.videoLayer.resume()

fsState.finishAnimating()

@@ -15,6 +15,7 @@ class ViewLayer: CAOpenGLLayer {
weak var videoView: VideoView!

lazy var mpvGLQueue = DispatchQueue(label: "com.colliderli.iina.mpvgl", qos: .userInteractive)
var blocked = false

private var fbo: GLint = 1

@@ -88,7 +89,6 @@ class ViewLayer: CAOpenGLLayer {
return pix!
}


override func copyCGLContext(forPixelFormat pf: CGLPixelFormatObj) -> CGLContextObj {
let ctx = super.copyCGLContext(forPixelFormat: pf)

@@ -160,6 +160,17 @@ class ViewLayer: CAOpenGLLayer {
videoView.uninitLock.unlock()
}

func suspend() {
blocked = true
mpvGLQueue.suspend()
}

func resume() {
blocked = false
draw(forced: true)
mpvGLQueue.resume()
}

func draw(forced: Bool = false) {
needsMPVRender = true
if forced { forceRender = true }

0 comments on commit 73b8b06

Please sign in to comment.
You can’t perform that action at this time.