1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-01 20:52:05 +00:00

cocoa-cb: add Apple Software Renderer support

by default the pixel format creation falls back to software renderer
when everything fails. this is mostly needed for VMs. additionally one
can directly request an sw renderer or exclude it entirely.
This commit is contained in:
Akemi 2018-07-22 23:07:32 +02:00 committed by Jan Ekström
parent 44e49aee3c
commit 8d2d0f0640
5 changed files with 42 additions and 3 deletions

View File

@ -4881,6 +4881,15 @@ The following video options are currently all specific to ``--vo=gpu`` and
OS X only. OS X only.
``--cocoa-cb-sw-renderer=<yes|no|auto>``
Use the Apple Software Renderer when using cocoa-cb (default: auto). If set
to ``no`` the software renderer is never used and instead fails when a the
usual pixel format could not be created, ``yes`` will always only use the
software renderer, and ``auto`` only falls back to the software renderer
when the usual pixel format couldn't be created.
OS X only.
``--macos-title-bar-style=<dark|ultradark|light|mediumlight|auto>`` ``--macos-title-bar-style=<dark|ultradark|light|mediumlight|auto>``
Sets the styling of the title bar (default: dark). Sets the styling of the title bar (default: dark).
OS X and cocoa-cb only OS X and cocoa-cb only

View File

@ -23,6 +23,7 @@
struct macos_opts { struct macos_opts {
int macos_title_bar_style; int macos_title_bar_style;
int macos_fs_animation_duration; int macos_fs_animation_duration;
int cocoa_cb_sw_renderer;
}; };
// multithreaded wrapper for mpv_main // multithreaded wrapper for mpv_main

View File

@ -49,11 +49,14 @@ const struct m_sub_options macos_conf = {
OPT_CHOICE_OR_INT("macos-fs-animation-duration", OPT_CHOICE_OR_INT("macos-fs-animation-duration",
macos_fs_animation_duration, 0, 0, 1000, macos_fs_animation_duration, 0, 0, 1000,
({"default", -1})), ({"default", -1})),
OPT_CHOICE("cocoa-cb-sw-renderer", cocoa_cb_sw_renderer, 0,
({"auto", -1}, {"no", 0}, {"yes", 1})),
{0} {0}
}, },
.size = sizeof(struct macos_opts), .size = sizeof(struct macos_opts),
.defaults = &(const struct macos_opts){ .defaults = &(const struct macos_opts){
.macos_fs_animation_duration = -1, .macos_fs_animation_duration = -1,
.cocoa_cb_sw_renderer = -1,
}, },
}; };

View File

@ -32,6 +32,7 @@ class VideoLayer: CAOpenGLLayer {
var needsFlip: Bool = false var needsFlip: Bool = false
var canDrawOffScreen: Bool = false var canDrawOffScreen: Bool = false
var cglContext: CGLContextObj? = nil var cglContext: CGLContextObj? = nil
var cglPixelFormat: CGLPixelFormatObj? = nil
var surfaceSize: NSSize? var surfaceSize: NSSize?
enum Draw: Int { case normal = 1, atomic, atomicEnd } enum Draw: Int { case normal = 1, atomic, atomicEnd }
@ -62,7 +63,8 @@ class VideoLayer: CAOpenGLLayer {
autoresizingMask = [.layerWidthSizable, .layerHeightSizable] autoresizingMask = [.layerWidthSizable, .layerHeightSizable]
backgroundColor = NSColor.black.cgColor backgroundColor = NSColor.black.cgColor
CGLCreateContext(copyCGLPixelFormat(forDisplayMask: 0), nil, &cglContext) cglPixelFormat = copyCGLPixelFormat(forDisplayMask: 0)
CGLCreateContext(cglPixelFormat!, nil, &cglContext)
var i: GLint = 1 var i: GLint = 1
CGLSetParameter(cglContext!, kCGLCPSwapInterval, &i) CGLSetParameter(cglContext!, kCGLCPSwapInterval, &i)
CGLSetCurrentContext(cglContext!) CGLSetCurrentContext(cglContext!)
@ -147,6 +149,8 @@ class VideoLayer: CAOpenGLLayer {
} }
override func copyCGLPixelFormat(forDisplayMask mask: UInt32) -> CGLPixelFormatObj { override func copyCGLPixelFormat(forDisplayMask mask: UInt32) -> CGLPixelFormatObj {
if cglPixelFormat != nil { return cglPixelFormat! }
let glVersions: [CGLOpenGLProfile] = [ let glVersions: [CGLOpenGLProfile] = [
kCGLOGLPVersion_3_2_Core, kCGLOGLPVersion_3_2_Core,
kCGLOGLPVersion_Legacy kCGLOGLPVersion_Legacy
@ -157,6 +161,8 @@ class VideoLayer: CAOpenGLLayer {
var npix: GLint = 0 var npix: GLint = 0
verLoop : for ver in glVersions { verLoop : for ver in glVersions {
if mpv.macOpts!.cocoa_cb_sw_renderer == 1 { break }
var glAttributes: [CGLPixelFormatAttribute] = [ var glAttributes: [CGLPixelFormatAttribute] = [
kCGLPFAOpenGLProfile, CGLPixelFormatAttribute(ver.rawValue), kCGLPFAOpenGLProfile, CGLPixelFormatAttribute(ver.rawValue),
kCGLPFAAccelerated, kCGLPFAAccelerated,
@ -177,9 +183,28 @@ class VideoLayer: CAOpenGLLayer {
} }
} }
if (err != kCGLNoError || pix == nil) && mpv.macOpts!.cocoa_cb_sw_renderer != 0 {
if mpv.macOpts!.cocoa_cb_sw_renderer == -1 {
let errS = String(cString: CGLErrorString(err))
mpv.sendWarning("Couldn't create hardware accelerated CGL " +
"pixel format, falling back to software " +
"renderer: \(errS) (\(err.rawValue))")
}
let glAttributes: [CGLPixelFormatAttribute] = [
kCGLPFAOpenGLProfile, CGLPixelFormatAttribute(kCGLOGLPVersion_3_2_Core.rawValue),
kCGLPFARendererID, CGLPixelFormatAttribute(UInt32(kCGLRendererGenericFloatID)),
kCGLPFADoubleBuffer,
kCGLPFABackingStore,
_CGLPixelFormatAttribute(rawValue: 0)
]
err = CGLChoosePixelFormat(glAttributes, &pix, &npix)
}
if err != kCGLNoError || pix == nil { if err != kCGLNoError || pix == nil {
let errS = String(cString: CGLErrorString(err)) let errS = String(cString: CGLErrorString(err))
mpv.sendError("Couldn't create CGL pixel format: \(errS) (\(err.rawValue))") mpv.sendError("Couldn't create any CGL pixel format: \(errS) (\(err.rawValue))")
exit(1) exit(1)
} }
return pix! return pix!

View File

@ -42,7 +42,8 @@ static bool is_software_gl(GL *gl)
strcmp(renderer, "Software Rasterizer") == 0 || strcmp(renderer, "Software Rasterizer") == 0 ||
strstr(renderer, "llvmpipe") || strstr(renderer, "llvmpipe") ||
strcmp(vendor, "Microsoft Corporation") == 0 || strcmp(vendor, "Microsoft Corporation") == 0 ||
strcmp(renderer, "Mesa X11") == 0; strcmp(renderer, "Mesa X11") == 0 ||
strcmp(renderer, "Apple Software Renderer") == 0;
} }
static void GLAPIENTRY dummy_glBindFramebuffer(GLenum target, GLuint framebuffer) static void GLAPIENTRY dummy_glBindFramebuffer(GLenum target, GLuint framebuffer)