summaryrefslogtreecommitdiffstats
path: root/video/out/cocoa-cb
diff options
context:
space:
mode:
authorAkemi <der.richter@gmx.de>2018-06-06 17:04:40 +0200
committerJan Ekström <jeebjp@gmail.com>2018-06-12 01:51:01 +0300
commit5865086aa84cae5e5505698ccf115a53a1b6b4fa (patch)
tree416b5ce30ae4c4d35af4130aa1956757fb6252ff /video/out/cocoa-cb
parent20dffe0621b3e26674850ef0b46ba3e689931d87 (diff)
downloadmpv-5865086aa84cae5e5505698ccf115a53a1b6b4fa.tar.bz2
mpv-5865086aa84cae5e5505698ccf115a53a1b6b4fa.tar.xz
cocoa-cb: remove pre-allocation of window, view and layer
the pre-allocation was needed because the layer allocated a opengl context async itself and we couldn't influence that. so we had to start the core after the context was actually allocated. furthermore a window, view and layer hierarchy had to be created so the layer would create a context. now, instead of relying on the layer to create a context we do this manually and re-use that context later when the layer wants to create one async itself.
Diffstat (limited to 'video/out/cocoa-cb')
-rw-r--r--video/out/cocoa-cb/events_view.swift5
-rw-r--r--video/out/cocoa-cb/video_layer.swift30
-rw-r--r--video/out/cocoa-cb/window.swift74
3 files changed, 63 insertions, 46 deletions
diff --git a/video/out/cocoa-cb/events_view.swift b/video/out/cocoa-cb/events_view.swift
index 7cc6a4022d..7cc295f362 100644
--- a/video/out/cocoa-cb/events_view.swift
+++ b/video/out/cocoa-cb/events_view.swift
@@ -31,9 +31,9 @@ class EventsView: NSView {
override var acceptsFirstResponder: Bool { return true }
- init(frame frameRect: NSRect, cocoaCB ccb: CocoaCB) {
+ init(cocoaCB ccb: CocoaCB) {
cocoaCB = ccb
- super.init(frame: frameRect)
+ super.init(frame: NSMakeRect(0, 0, 960, 480))
autoresizingMask = [.viewWidthSizable, .viewHeightSizable]
wantsBestResolutionOpenGLSurface = true
register(forDraggedTypes: [NSFilenamesPboardType, NSURLPboardType])
@@ -249,6 +249,7 @@ class EventsView: NSView {
}
func canHideCursor() -> Bool {
+ if cocoaCB.window == nil { return false }
return !hasMouseDown && containsMouseLocation() && window!.isKeyWindow
}
diff --git a/video/out/cocoa-cb/video_layer.swift b/video/out/cocoa-cb/video_layer.swift
index 2e347ba22e..c600b06b6c 100644
--- a/video/out/cocoa-cb/video_layer.swift
+++ b/video/out/cocoa-cb/video_layer.swift
@@ -61,7 +61,15 @@ class VideoLayer: CAOpenGLLayer {
super.init()
autoresizingMask = [.layerWidthSizable, .layerHeightSizable]
backgroundColor = NSColor.black.cgColor
- contentsScale = cocoaCB.window.backingScaleFactor
+
+ CGLCreateContext(copyCGLPixelFormat(forDisplayMask: 0), nil, &cglContext)
+ var i: GLint = 1
+ CGLSetParameter(cglContext!, kCGLCPSwapInterval, &i)
+ CGLSetCurrentContext(cglContext!)
+
+ mpv.initRender()
+ mpv.setRenderUpdateCallback(updateCallback, context: self)
+ mpv.setRenderControlCallback(cocoaCB.controlCallback, context: cocoaCB)
}
override init(layer: Any) {
@@ -74,12 +82,6 @@ class VideoLayer: CAOpenGLLayer {
fatalError("init(coder:) has not been implemented")
}
- func setUpRender() {
- mpv.initRender()
- mpv.setRenderUpdateCallback(updateCallback, context: self)
- mpv.setRenderControlCallback(cocoaCB.controlCallback, context: cocoaCB)
- }
-
override func canDraw(inCGLContext ctx: CGLContextObj,
pixelFormat pf: CGLPixelFormatObj,
forLayerTime t: CFTimeInterval,
@@ -177,23 +179,15 @@ class VideoLayer: CAOpenGLLayer {
if err != kCGLNoError || pix == nil {
let errS = String(cString: CGLErrorString(err))
- print("Couldn't create CGL pixel format: \(errS) (\(err.rawValue))")
+ mpv.sendError("Couldn't create CGL pixel format: \(errS) (\(err.rawValue))")
exit(1)
}
return pix!
}
override func copyCGLContext(forPixelFormat pf: CGLPixelFormatObj) -> CGLContextObj {
- let ctx = super.copyCGLContext(forPixelFormat: pf)
- var i: GLint = 1
- CGLSetParameter(ctx, kCGLCPSwapInterval, &i)
- CGLSetCurrentContext(ctx)
- cglContext = ctx
-
- if let app = NSApp as? Application {
- app.initMPVCore()
- }
- return ctx
+ contentsScale = cocoaCB.window.backingScaleFactor
+ return cglContext!
}
let updateCallback: mpv_render_update_fn = { (ctx) in
diff --git a/video/out/cocoa-cb/window.swift b/video/out/cocoa-cb/window.swift
index b3db7aeb8f..907476fc09 100644
--- a/video/out/cocoa-cb/window.swift
+++ b/video/out/cocoa-cb/window.swift
@@ -78,28 +78,23 @@ class Window: NSWindow, NSWindowDelegate {
}
}
- convenience init(cocoaCB ccb: CocoaCB) {
- self.init(contentRect: NSMakeRect(0, 0, 960, 480),
- styleMask: [.titled, .closable, .miniaturizable, .resizable],
- backing: .buffered, defer: false, screen: NSScreen.main())
- cocoaCB = ccb
- title = "mpv"
- }
-
- convenience init(contentRect: NSRect, styleMask style: NSWindowStyleMask,
- screen: NSScreen?, cocoaCB ccb: CocoaCB)
- {
- self.init(contentRect: contentRect, styleMask: style,
+ convenience init(contentRect: NSRect, screen: NSScreen?, view: NSView, cocoaCB ccb: CocoaCB) {
+ self.init(contentRect: contentRect,
+ styleMask: [.titled, .closable, .miniaturizable, .resizable],
backing: .buffered, defer: false, screen: screen)
cocoaCB = ccb
+ title = cocoaCB.title
minSize = NSMakeSize(160, 90)
collectionBehavior = .fullScreenPrimary
delegate = self
+ contentView!.addSubview(view)
+ view.frame = contentView!.frame
unfsContentFrame = convertToScreen(contentView!.frame)
targetScreen = screen!
currentScreen = screen!
unfScreen = screen!
+ initTitleBar()
if let app = NSApp as? Application {
app.menuBar.register(#selector(setHalfWindowSize), for: MPM_H_SIZE)
@@ -123,14 +118,31 @@ class Window: NSWindow, NSWindowDelegate {
titleBarEffect!.blendingMode = .withinWindow
titleBarEffect!.autoresizingMask = [.viewWidthSizable, .viewMinYMargin]
- setTitleBarStyle(mpv.getStringProperty("macos-title-bar-style") ?? "dark")
+ setTitleBarStyle(Int(mpv.macOpts!.macos_title_bar_style))
contentView!.addSubview(titleBarEffect!, positioned: .above, relativeTo: nil)
-
- border = mpv.getBoolProperty("border")
}
- func setTitleBarStyle(_ style: String) {
- var effect = style
+ func setTitleBarStyle(_ style: Any) {
+ var effect: String
+
+ if style is Int {
+ switch style as! Int {
+ case 4:
+ effect = "auto"
+ case 3:
+ effect = "mediumlight"
+ case 2:
+ effect = "light"
+ case 1:
+ effect = "ultradark"
+ case 0: fallthrough
+ default:
+ effect = "dark"
+ }
+ } else {
+ effect = style as! String
+ }
+
if effect == "auto" {
let systemStyle = UserDefaults.standard.string(forKey: "AppleInterfaceStyle")
effect = systemStyle == nil ? "mediumlight" : "ultradark"
@@ -339,16 +351,26 @@ class Window: NSWindow, NSWindowDelegate {
}
}
- func setOnTop(_ state: Bool) {
+ func setOnTop(_ state: Bool, _ ontopLevel: Any) {
if state {
- let ontopLevel = mpv.getStringProperty("ontop-level") ?? "window"
- switch ontopLevel {
- case "window":
- level = Int(CGWindowLevelForKey(.floatingWindow))
- case "system":
- level = Int(CGWindowLevelForKey(.statusWindow))+1
- default:
- level = Int(ontopLevel)!
+ if ontopLevel is Int {
+ switch ontopLevel as! Int {
+ case -1:
+ level = Int(CGWindowLevelForKey(.floatingWindow))
+ case -2:
+ level = Int(CGWindowLevelForKey(.statusWindow))+1
+ default:
+ level = ontopLevel as! Int
+ }
+ } else {
+ switch ontopLevel as! String {
+ case "window":
+ level = Int(CGWindowLevelForKey(.floatingWindow))
+ case "system":
+ level = Int(CGWindowLevelForKey(.statusWindow))+1
+ default:
+ level = Int(ontopLevel as! String)!
+ }
}
collectionBehavior.remove(.transient)
collectionBehavior.insert(.managed)