From f645e8921c8f8704ce8b41bc2d7ae80bdcfd6590 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 5 Jun 2014 09:18:57 +0200 Subject: cocoa: add fallback for automatic GPU switching Not all the hardware supports kCGLPFASupportsAutomaticGraphicsSwitching (apparently all Mid-2010 and before MacBooks do not work with it), so fallback to not asking for this attribute in the GL pixel format. --- video/out/cocoa_common.m | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'video') diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m index 5385460792..1e0b7abda5 100644 --- a/video/out/cocoa_common.m +++ b/video/out/cocoa_common.m @@ -349,6 +349,8 @@ static int create_gl_context(struct vo *vo, int gl3profile) kCGLPFADoubleBuffer, kCGLPFAAccelerated, #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8 + // leave this as the last entry of the array to not break the fallback + // code kCGLPFASupportsAutomaticGraphicsSwitching, #endif 0 @@ -356,7 +358,18 @@ static int create_gl_context(struct vo *vo, int gl3profile) CGLPixelFormatObj pix; GLint npix; - if ((err = CGLChoosePixelFormat(attrs, &pix, &npix)) != kCGLNoError) { + + err = CGLChoosePixelFormat(attrs, &pix, &npix); + if (err == kCGLBadAttribute) { + // kCGLPFASupportsAutomaticGraphicsSwitching is probably not supported + // by the current hardware. Falling back to not using it. + MP_ERR(vo, "error creating CGL pixel format with automatic GPU " + "switching. falling back\n"); + attrs[MP_ARRAY_SIZE(attrs) - 2] = 0; + err = CGLChoosePixelFormat(attrs, &pix, &npix); + } + + if (err != kCGLNoError) { MP_FATAL(s, "error creating CGL pixel format: %s (%d)\n", CGLErrorString(err), err); } -- cgit v1.2.3