cocoa-cb: add support for forcing the dedicated GPU for rendering

this deprecates the old cocoa backend only option and moves it to the
general macos ones. add support for the new option in the cocoa-cb
layer creation and use the new option in the olde cocoa backend.

Fixes #7272
This commit is contained in:
der richter 2020-01-19 16:23:59 +01:00
parent 465f48fb0c
commit 3275cd04b7
5 changed files with 19 additions and 6 deletions

View File

@ -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 */

View File

@ -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),

View File

@ -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'

View File

@ -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)

View File

@ -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");