From 5865086aa84cae5e5505698ccf115a53a1b6b4fa Mon Sep 17 00:00:00 2001 From: Akemi Date: Wed, 6 Jun 2018 17:04:40 +0200 Subject: 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. --- video/out/cocoa-cb/video_layer.swift | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 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 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 -- cgit v1.2.3