summaryrefslogtreecommitdiffstats
path: root/video/out/cocoa-cb
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2019-09-29 18:35:12 +0200
committerder richter <der.richter@gmx.de>2019-10-06 13:29:48 +0200
commit6d0f0546ee851f4106438c5b92c8d1d152937ea7 (patch)
treef4efc2a603081fe75c19bea86c261d5320716c5b /video/out/cocoa-cb
parent2b19a7c964b821945e3ea06cfa81c1c064f2504d (diff)
downloadmpv-6d0f0546ee851f4106438c5b92c8d1d152937ea7.tar.bz2
mpv-6d0f0546ee851f4106438c5b92c8d1d152937ea7.tar.xz
cocoa-cb: remove get_property_* usages and split up mpv helper
all the get_property_* usages were removed because in some circumstances they can lead to deadlocks. they were replaced by accessing the vo and mp_vo_opts structs directly, like on other vos. additionally the mpv helper was split into a mpv and libmpv helper, to differentiate between private and public APIs and for future changes like a macOS vulkan context for vo=gpu.
Diffstat (limited to 'video/out/cocoa-cb')
-rw-r--r--video/out/cocoa-cb/events_view.swift31
-rw-r--r--video/out/cocoa-cb/title_bar.swift10
-rw-r--r--video/out/cocoa-cb/video_layer.swift53
-rw-r--r--video/out/cocoa-cb/window.swift48
4 files changed, 64 insertions, 78 deletions
diff --git a/video/out/cocoa-cb/events_view.swift b/video/out/cocoa-cb/events_view.swift
index 59441d9793..31533bbb98 100644
--- a/video/out/cocoa-cb/events_view.swift
+++ b/video/out/cocoa-cb/events_view.swift
@@ -19,8 +19,8 @@ import Cocoa
class EventsView: NSView {
- weak var cocoaCB: CocoaCB!
- var mpv: MPVHelper { get { return cocoaCB.mpv } }
+ unowned var cocoaCB: CocoaCB
+ var mpv: MPVHelper? { get { return cocoaCB.mpv } }
var tracker: NSTrackingArea?
var hasMouseDown: Bool = false
@@ -117,64 +117,64 @@ class EventsView: NSView {
}
override func mouseEntered(with event: NSEvent) {
- if mpv.getBoolProperty("input-cursor") {
+ if mpv?.mouseEnabled() ?? true {
cocoa_put_key_with_modifiers(SWIFT_KEY_MOUSE_ENTER, 0)
}
}
override func mouseExited(with event: NSEvent) {
- if mpv.getBoolProperty("input-cursor") {
+ if mpv?.mouseEnabled() ?? true {
cocoa_put_key_with_modifiers(SWIFT_KEY_MOUSE_LEAVE, 0)
}
cocoaCB.titleBar?.hide()
}
override func mouseMoved(with event: NSEvent) {
- if mpv.getBoolProperty("input-cursor") {
+ if mpv?.mouseEnabled() ?? true {
signalMouseMovement(event)
}
cocoaCB.titleBar?.show()
}
override func mouseDragged(with event: NSEvent) {
- if mpv.getBoolProperty("input-cursor") {
+ if mpv?.mouseEnabled() ?? true {
signalMouseMovement(event)
}
}
override func mouseDown(with event: NSEvent) {
- if mpv.getBoolProperty("input-cursor") {
+ if mpv?.mouseEnabled() ?? true {
signalMouseDown(event)
}
}
override func mouseUp(with event: NSEvent) {
- if mpv.getBoolProperty("input-cursor") {
+ if mpv?.mouseEnabled() ?? true {
signalMouseUp(event)
}
cocoaCB.window?.isMoving = false
}
override func rightMouseDown(with event: NSEvent) {
- if mpv.getBoolProperty("input-cursor") {
+ if mpv?.mouseEnabled() ?? true {
signalMouseDown(event)
}
}
override func rightMouseUp(with event: NSEvent) {
- if mpv.getBoolProperty("input-cursor") {
+ if mpv?.mouseEnabled() ?? true {
signalMouseUp(event)
}
}
override func otherMouseDown(with event: NSEvent) {
- if mpv.getBoolProperty("input-cursor") {
+ if mpv?.mouseEnabled() ?? true {
signalMouseDown(event)
}
}
override func otherMouseUp(with event: NSEvent) {
- if mpv.getBoolProperty("input-cursor") {
+ if mpv?.mouseEnabled() ?? true {
signalMouseUp(event)
}
}
@@ -203,7 +203,7 @@ class EventsView: NSView {
cocoaCB.window?.updateMovableBackground(point)
if !(cocoaCB.window?.isMoving ?? false) {
- mpv.setMousePosition(point)
+ mpv?.setMousePosition(point)
}
}
@@ -219,11 +219,11 @@ class EventsView: NSView {
cmd = delta > 0 ? SWIFT_WHEEL_RIGHT : SWIFT_WHEEL_LEFT;
}
- mpv.putAxis(cmd, delta: abs(delta))
+ mpv?.putAxis(cmd, delta: abs(delta))
}
override func scrollWheel(with event: NSEvent) {
- if !mpv.getBoolProperty("input-cursor") {
+ if !(mpv?.mouseEnabled() ?? true) {
return
}
@@ -246,7 +246,6 @@ class EventsView: NSView {
}
func containsMouseLocation() -> Bool {
- if cocoaCB == nil { return false }
var topMargin: CGFloat = 0.0
let menuBarHeight = NSApp.mainMenu?.menuBarHeight ?? 23.0
diff --git a/video/out/cocoa-cb/title_bar.swift b/video/out/cocoa-cb/title_bar.swift
index 41d04a19ad..20812e9029 100644
--- a/video/out/cocoa-cb/title_bar.swift
+++ b/video/out/cocoa-cb/title_bar.swift
@@ -19,8 +19,8 @@ import Cocoa
class TitleBar: NSVisualEffectView {
- weak var cocoaCB: CocoaCB!
- var mpv: MPVHelper { get { return cocoaCB.mpv } }
+ unowned var cocoaCB: CocoaCB
+ var libmpv: LibmpvHelper { get { return cocoaCB.libmpv } }
var systemBar: NSView? {
get { return cocoaCB.window?.standardWindowButton(.closeButton)?.superview }
@@ -67,9 +67,9 @@ class TitleBar: NSVisualEffectView {
window.contentView?.addSubview(self, positioned: .above, relativeTo: nil)
window.titlebarAppearsTransparent = true
window.styleMask.insert(.fullSizeContentView)
- set(appearance: Int(mpv.macOpts?.macos_title_bar_appearance ?? 0))
- set(material: Int(mpv.macOpts?.macos_title_bar_material ?? 0))
- set(color: mpv.macOpts?.macos_title_bar_color ?? "#00000000")
+ set(appearance: Int(libmpv.macOpts.macos_title_bar_appearance))
+ set(material: Int(libmpv.macOpts.macos_title_bar_material))
+ set(color: libmpv.macOpts.macos_title_bar_color)
}
required init?(coder: NSCoder) {
diff --git a/video/out/cocoa-cb/video_layer.swift b/video/out/cocoa-cb/video_layer.swift
index 95727ee01f..90a37ae0c5 100644
--- a/video/out/cocoa-cb/video_layer.swift
+++ b/video/out/cocoa-cb/video_layer.swift
@@ -66,8 +66,8 @@ let attributeLookUp: [UInt32:String] = [
class VideoLayer: CAOpenGLLayer {
- weak var cocoaCB: CocoaCB!
- var mpv: MPVHelper { get { return cocoaCB.mpv } }
+ unowned var cocoaCB: CocoaCB
+ var libmpv: LibmpvHelper { get { return cocoaCB.libmpv } }
let displayLock = NSLock()
let cglContext: CGLContextObj
@@ -101,8 +101,8 @@ class VideoLayer: CAOpenGLLayer {
init(cocoaCB ccb: CocoaCB) {
cocoaCB = ccb
- (cglPixelFormat, bufferDepth) = VideoLayer.createPixelFormat(ccb.mpv)
- cglContext = VideoLayer.createContext(ccb.mpv, cglPixelFormat)
+ (cglPixelFormat, bufferDepth) = VideoLayer.createPixelFormat(ccb.libmpv)
+ cglContext = VideoLayer.createContext(ccb.libmpv, cglPixelFormat)
super.init()
autoresizingMask = [.layerWidthSizable, .layerHeightSizable]
backgroundColor = NSColor.black.cgColor
@@ -115,9 +115,9 @@ class VideoLayer: CAOpenGLLayer {
CGLSetParameter(cglContext, kCGLCPSwapInterval, &i)
CGLSetCurrentContext(cglContext)
- mpv.initRender()
- mpv.setRenderUpdateCallback(updateCallback, context: self)
- mpv.setRenderControlCallback(cocoaCB.controlCallback, context: cocoaCB)
+ libmpv.initRender()
+ libmpv.setRenderUpdateCallback(updateCallback, context: self)
+ libmpv.setRenderControlCallback(cocoaCB.controlCallback, context: cocoaCB)
}
//necessary for when the layer containing window changes the screen
@@ -144,7 +144,7 @@ class VideoLayer: CAOpenGLLayer {
isAsynchronous = false
}
return cocoaCB.backendState == .initialized &&
- (forceDraw || mpv.isRenderUpdateFrame())
+ (forceDraw || libmpv.isRenderUpdateFrame())
}
override func draw(inCGLContext ctx: CGLContextObj,
@@ -163,7 +163,7 @@ class VideoLayer: CAOpenGLLayer {
}
updateSurfaceSize()
- mpv.drawRender(surfaceSize, bufferDepth, ctx)
+ libmpv.drawRender(surfaceSize, bufferDepth, ctx)
if needsICCUpdate {
needsICCUpdate = false
@@ -218,8 +218,8 @@ class VideoLayer: CAOpenGLLayer {
CATransaction.flush()
if isUpdate && needsFlip {
CGLSetCurrentContext(cglContext)
- if mpv.isRenderUpdateFrame() {
- mpv.drawRender(NSZeroSize, bufferDepth, cglContext, skip: true)
+ if libmpv.isRenderUpdateFrame() {
+ libmpv.drawRender(NSZeroSize, bufferDepth, cglContext, skip: true)
}
}
displayLock.unlock()
@@ -235,29 +235,29 @@ class VideoLayer: CAOpenGLLayer {
}
}
- class func createPixelFormat(_ mpv: MPVHelper) -> (CGLPixelFormatObj, GLint) {
+ class func createPixelFormat(_ libmpv: LibmpvHelper) -> (CGLPixelFormatObj, GLint) {
var pix: CGLPixelFormatObj?
var depth: GLint = 8
var err: CGLError = CGLError(rawValue: 0)
- let swRender = mpv.macOpts?.cocoa_cb_sw_renderer ?? -1
+ let swRender = libmpv.macOpts.cocoa_cb_sw_renderer
if swRender != 1 {
- (pix, depth, err) = VideoLayer.findPixelFormat(mpv)
+ (pix, depth, err) = VideoLayer.findPixelFormat(libmpv)
}
if (err != kCGLNoError || pix == nil) && swRender != 0 {
- (pix, depth, err) = VideoLayer.findPixelFormat(mpv, software: true)
+ (pix, depth, err) = VideoLayer.findPixelFormat(libmpv, software: true)
}
guard let pixelFormat = pix, err == kCGLNoError else {
- mpv.sendError("Couldn't create any CGL pixel format")
+ libmpv.sendError("Couldn't create any CGL pixel format")
exit(1)
}
return (pixelFormat, depth)
}
- class func findPixelFormat(_ mpv: MPVHelper, software: Bool = false) -> (CGLPixelFormatObj?, GLint, CGLError) {
+ class func findPixelFormat(_ libmpv: LibmpvHelper, software: Bool = false) -> (CGLPixelFormatObj?, GLint, CGLError) {
var pix: CGLPixelFormatObj?
var err: CGLError = CGLError(rawValue: 0)
var npix: GLint = 0
@@ -267,7 +267,7 @@ class VideoLayer: CAOpenGLLayer {
glBase.insert(CGLPixelFormatAttribute(ver.rawValue), at: 1)
var glFormat = [glBase]
- if (mpv.macOpts?.cocoa_cb_10bit_context == 1) {
+ if (libmpv.macOpts.cocoa_cb_10bit_context == 1) {
glFormat += [glFormat10Bit]
}
glFormat += glFormatOptional
@@ -283,7 +283,7 @@ class VideoLayer: CAOpenGLLayer {
return attributeLookUp[value.rawValue] ?? String(value.rawValue)
})
- mpv.sendVerbose("Created CGL pixel format with attributes: " +
+ libmpv.sendVerbose("Created CGL pixel format with attributes: " +
"\(attArray.joined(separator: ", "))")
return (pix, glFormat.contains(glFormat10Bit) ? 16 : 8, err)
}
@@ -291,24 +291,23 @@ class VideoLayer: CAOpenGLLayer {
}
let errS = String(cString: CGLErrorString(err))
- mpv.sendWarning("Couldn't create a " +
- "\(software ? "software" : "hardware accelerated") " +
- "CGL pixel format: \(errS) (\(err.rawValue))")
-
- if software == false && (mpv.macOpts?.cocoa_cb_sw_renderer ?? -1) == -1 {
- mpv.sendWarning("Falling back to software renderer")
+ libmpv.sendWarning("Couldn't create a " +
+ "\(software ? "software" : "hardware accelerated") " +
+ "CGL pixel format: \(errS) (\(err.rawValue))")
+ if software == false && libmpv.macOpts.cocoa_cb_sw_renderer == -1 {
+ libmpv.sendWarning("Falling back to software renderer")
}
return (pix, 8, err)
}
- class func createContext(_ mpv: MPVHelper, _ pixelFormat: CGLPixelFormatObj) -> CGLContextObj {
+ class func createContext(_ libmpv: LibmpvHelper, _ pixelFormat: CGLPixelFormatObj) -> CGLContextObj {
var context: CGLContextObj?
let error = CGLCreateContext(pixelFormat, nil, &context)
guard let cglContext = context, error == kCGLNoError else {
let errS = String(cString: CGLErrorString(error))
- mpv.sendError("Couldn't create a CGLContext: " + errS)
+ libmpv.sendError("Couldn't create a CGLContext: " + errS)
exit(1)
}
diff --git a/video/out/cocoa-cb/window.swift b/video/out/cocoa-cb/window.swift
index 2f87711d22..1ac0e2bc78 100644
--- a/video/out/cocoa-cb/window.swift
+++ b/video/out/cocoa-cb/window.swift
@@ -20,7 +20,8 @@ import Cocoa
class Window: NSWindow, NSWindowDelegate {
weak var cocoaCB: CocoaCB! = nil
- var mpv: MPVHelper { get { return cocoaCB.mpv } }
+ var mpv: MPVHelper? { get { return cocoaCB.mpv } }
+ var libmpv: LibmpvHelper { get { return cocoaCB.libmpv } }
var targetScreen: NSScreen?
var previousScreen: NSScreen?
@@ -134,7 +135,7 @@ class Window: NSWindow, NSWindowDelegate {
setFrame(frame, display: true)
}
- if mpv.getBoolProperty("native-fs") {
+ if Bool(mpv?.opts.native_fs ?? 1) {
super.toggleFullScreen(sender)
} else {
if !isInFullscreen {
@@ -245,48 +246,35 @@ class Window: NSWindow, NSWindowDelegate {
cocoaCB.layer?.update()
}
- func getFsAnimationDuration(_ def: Double) -> Double{
- let duration = mpv.getStringProperty("macos-fs-animation-duration") ?? "default"
- if duration == "default" {
+ func getFsAnimationDuration(_ def: Double) -> Double {
+ let duration = libmpv.macOpts.macos_fs_animation_duration
+ if duration < 0 {
return def
} else {
- return (Double(duration) ?? 0.2)/1000
+ return Double(duration)/1000
}
}
- func setOnTop(_ state: Bool, _ ontopLevel: Any) {
- let stdLevel: NSWindow.Level = .normal
-
+ func setOnTop(_ state: Bool, _ ontopLevel: Int) {
if state {
- if ontopLevel is Int {
- switch ontopLevel as? Int {
- case .some(-1):
- level = .floating
- case .some(-2):
- level = .statusBar + 1
- default:
- level = NSWindow.Level(ontopLevel as? Int ?? stdLevel.rawValue)
- }
- } else {
- switch ontopLevel as? String {
- case .some("window"):
- level = .floating
- case .some("system"):
- level = .statusBar + 1
- default:
- level = NSWindow.Level(Int(ontopLevel as? String ?? "") ?? stdLevel.rawValue)
- }
+ switch ontopLevel {
+ case -1:
+ level = .floating
+ case -2:
+ level = .statusBar + 1
+ default:
+ level = NSWindow.Level(ontopLevel)
}
collectionBehavior.remove(.transient)
collectionBehavior.insert(.managed)
} else {
- level = stdLevel
+ level = .normal
}
}
func updateMovableBackground(_ pos: NSPoint) {
if !isInFullscreen {
- isMovableByWindowBackground = mpv.canBeDraggedAt(pos)
+ isMovableByWindowBackground = mpv?.canBeDraggedAt(pos) ?? true
} else {
isMovableByWindowBackground = false
}
@@ -448,7 +436,7 @@ class Window: NSWindow, NSWindowDelegate {
@objc func setDoubleWindowSize() { setWindowScale(2.0) }
func setWindowScale(_ scale: Double) {
- mpv.commandAsync(["osd-auto", "set", "window-scale", "\(scale)"])
+ mpv?.command("set window-scale \(scale)")
}
func windowDidChangeScreen(_ notification: Notification) {