diff --git a/osdep/macosx_application.h b/osdep/macosx_application.h index 7e233987fd..19babc5458 100644 --- a/osdep/macosx_application.h +++ b/osdep/macosx_application.h @@ -27,6 +27,7 @@ struct macos_opts { int macos_title_bar_material; struct m_color macos_title_bar_color; int macos_fs_animation_duration; + int macos_force_dedicated_gpu; int cocoa_cb_sw_renderer; int cocoa_cb_10bit_context; }; @@ -35,4 +36,6 @@ struct macos_opts { int cocoa_main(int argc, char *argv[]); void cocoa_register_menu_item_action(MPMenuKey key, void* action); +extern const struct m_sub_options macos_conf; + #endif /* MPV_MACOSX_APPLICATION */ diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m index d553c69158..7bf0737af9 100644 --- a/osdep/macosx_application.m +++ b/osdep/macosx_application.m @@ -62,6 +62,7 @@ const struct m_sub_options macos_conf = { OPT_CHOICE_OR_INT("macos-fs-animation-duration", macos_fs_animation_duration, 0, 0, 1000, ({"default", -1})), + OPT_FLAG("macos-force-dedicated-gpu", macos_force_dedicated_gpu, 0), OPT_CHOICE("cocoa-cb-sw-renderer", cocoa_cb_sw_renderer, 0, ({"auto", -1}, {"no", 0}, {"yes", 1})), OPT_FLAG("cocoa-cb-10bit-context", cocoa_cb_10bit_context, 0), diff --git a/player/lua/console.lua b/player/lua/console.lua index f14d7f9362..d026d4e528 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -34,7 +34,7 @@ function detect_platform() -- Kind of a dumb way of detecting the platform but whatever if mp.get_property_native('options/vo-mmcss-profile', o) ~= o then return 'windows' - elseif mp.get_property_native('options/cocoa-force-dedicated-gpu', o) ~= o then + elseif mp.get_property_native('options/macos-force-dedicated-gpu', o) ~= o then return 'macos' end return 'x11' diff --git a/video/out/cocoa-cb/video_layer.swift b/video/out/cocoa-cb/video_layer.swift index 90a37ae0c5..f9a195b554 100644 --- a/video/out/cocoa-cb/video_layer.swift +++ b/video/out/cocoa-cb/video_layer.swift @@ -39,8 +39,7 @@ let glFormatSoftwareBase: [CGLPixelFormatAttribute] = [ let glFormatOptional: [[CGLPixelFormatAttribute]] = [ [kCGLPFABackingStore], - [kCGLPFAAllowOfflineRenderers], - [kCGLPFASupportsAutomaticGraphicsSwitching] + [kCGLPFAAllowOfflineRenderers] ] let glFormat10Bit: [CGLPixelFormatAttribute] = [ @@ -49,6 +48,10 @@ let glFormat10Bit: [CGLPixelFormatAttribute] = [ kCGLPFAColorFloat ] +let glFormatAutoGPU: [CGLPixelFormatAttribute] = [ + kCGLPFASupportsAutomaticGraphicsSwitching +] + let attributeLookUp: [UInt32:String] = [ kCGLOGLPVersion_3_2_Core.rawValue: "kCGLOGLPVersion_3_2_Core", kCGLOGLPVersion_Legacy.rawValue: "kCGLOGLPVersion_Legacy", @@ -272,6 +275,10 @@ class VideoLayer: CAOpenGLLayer { } glFormat += glFormatOptional + if (libmpv.macOpts.macos_force_dedicated_gpu == 0) { + glFormat += [glFormatAutoGPU] + } + for index in stride(from: glFormat.count-1, through: 0, by: -1) { let format = glFormat.flatMap { $0 } + [_CGLPixelFormatAttribute(rawValue: 0)] err = CGLChoosePixelFormat(format, &pix, &npix) diff --git a/video/out/opengl/context_cocoa.c b/video/out/opengl/context_cocoa.c index b73ca9d9a2..d0fcd63d62 100644 --- a/video/out/opengl/context_cocoa.c +++ b/video/out/opengl/context_cocoa.c @@ -20,15 +20,15 @@ #include "options/m_config.h" #include "video/out/cocoa_common.h" #include "context.h" +#include "osdep/macosx_application.h" struct cocoa_opts { - int cocoa_force_dedicated_gpu; }; #define OPT_BASE_STRUCT struct cocoa_opts const struct m_sub_options cocoa_conf = { .opts = (const struct m_option[]) { - OPT_FLAG("cocoa-force-dedicated-gpu", cocoa_force_dedicated_gpu, 0), + OPT_REPLACED("cocoa-force-dedicated-gpu", "macos-force-dedicated-gpu"), {0} }, .size = sizeof(struct cocoa_opts), @@ -41,6 +41,7 @@ struct priv { CGLContextObj ctx; struct cocoa_opts *opts; + struct macos_opts *macos_opts; }; static int set_swap_interval(int enabled) @@ -85,7 +86,7 @@ static CGLError test_gl_version(struct ra_ctx *ctx, CGLOpenGLProfile ver) CGLError err; int supported_attribute = MP_ARRAY_SIZE(attrs)-1; - if (p->opts->cocoa_force_dedicated_gpu) + if (p->macos_opts->macos_force_dedicated_gpu) attrs[--supported_attribute] = 0; err = CGLChoosePixelFormat(attrs, &p->pix, &npix); @@ -169,6 +170,7 @@ static bool cocoa_init(struct ra_ctx *ctx) struct priv *p = ctx->priv = talloc_zero(ctx, struct priv); GL *gl = &p->gl; p->opts = mp_get_config_group(ctx, ctx->global, &cocoa_conf); + p->macos_opts = mp_get_config_group(ctx, ctx->global, &macos_conf); vo_cocoa_init(ctx->vo); MP_WARN(ctx->vo, "opengl cocoa backend is deprecated, use vo=libmpv instead\n");