diff options
author | Dudemanguy <random342@airmail.cc> | 2022-10-26 23:23:49 -0500 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2022-10-28 02:36:46 +0000 |
commit | adb556bf15e9b09afce6c9cb0a0911c53cf27feb (patch) | |
tree | 06761b1b1ae91f1d7433855f645480e28d96300b /video/out/gpu/context.c | |
parent | 31af37f87762e5e548fa234b30f6248d8d6c19e4 (diff) | |
download | mpv-adb556bf15e9b09afce6c9cb0a0911c53cf27feb.tar.bz2 mpv-adb556bf15e9b09afce6c9cb0a0911c53cf27feb.tar.xz |
vo_dmabuf_wayland: use special ra_ctx_create_by_name
vo_dmabuf_wayland has its own ra and context so it can handle all the
different hwdec correctly. Unfortunately, this API was pretty clearly
designed with vo_gpu/vo_gpu_next in mind and has a lot of concepts that
don't make sense for vo_dmabuf_wayland. We still want to bolt on a
ra_ctx, but instead let's rework the ra_ctx logic a little bit. First,
this introduces a hidden bool within the ra_ctx_fns that is used to hide
the wldmabuf context from users as an option (unlike the other usual
contexts). We also want to make sure that hidden contexts wouldn't be
autoprobed in the usual ra_ctx_create, so we be sure to skip those in
that function. Additionally, let's create a new ra_ctx_create_by_name
function which does exactly what says. It specifically selects a context
based on a passed string. This function has no probing or option logic
is simplified just for what vo_dmabuf_wayland needs. The api/context
validations functions are modified just a little bit to make sure hidden
contexts are skipped and the documentation is updated to remove this
entries. Fixes #10793.
Diffstat (limited to 'video/out/gpu/context.c')
-rw-r--r-- | video/out/gpu/context.c | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/video/out/gpu/context.c b/video/out/gpu/context.c index 052e3cdc80..a7bb4175cc 100644 --- a/video/out/gpu/context.c +++ b/video/out/gpu/context.c @@ -124,8 +124,10 @@ static int ra_ctx_api_help(struct mp_log *log, const struct m_option *opt, { mp_info(log, "GPU APIs (contexts):\n"); mp_info(log, " auto (autodetect)\n"); - for (int n = 0; n < MP_ARRAY_SIZE(contexts); n++) - mp_info(log, " %s (%s)\n", contexts[n]->type, contexts[n]->name); + for (int n = 0; n < MP_ARRAY_SIZE(contexts); n++) { + if (!contexts[n]->hidden) + mp_info(log, " %s (%s)\n", contexts[n]->type, contexts[n]->name); + } return M_OPT_EXIT; } @@ -136,7 +138,7 @@ static int ra_ctx_validate_api(struct mp_log *log, const struct m_option *opt, if (bstr_equals0(param, "auto")) return 1; for (int i = 0; i < MP_ARRAY_SIZE(contexts); i++) { - if (bstr_equals0(param, contexts[i]->type)) + if (bstr_equals0(param, contexts[i]->type) && !contexts[i]->hidden) return 1; } return M_OPT_INVALID; @@ -147,8 +149,10 @@ static int ra_ctx_context_help(struct mp_log *log, const struct m_option *opt, { mp_info(log, "GPU contexts (APIs):\n"); mp_info(log, " auto (autodetect)\n"); - for (int n = 0; n < MP_ARRAY_SIZE(contexts); n++) - mp_info(log, " %s (%s)\n", contexts[n]->name, contexts[n]->type); + for (int n = 0; n < MP_ARRAY_SIZE(contexts); n++) { + if (!contexts[n]->hidden) + mp_info(log, " %s (%s)\n", contexts[n]->name, contexts[n]->type); + } return M_OPT_EXIT; } @@ -159,7 +163,7 @@ static int ra_ctx_validate_context(struct mp_log *log, const struct m_option *op if (bstr_equals0(param, "auto")) return 1; for (int i = 0; i < MP_ARRAY_SIZE(contexts); i++) { - if (bstr_equals0(param, contexts[i]->name)) + if (bstr_equals0(param, contexts[i]->name) && !contexts[i]->hidden) return 1; } return M_OPT_INVALID; @@ -183,6 +187,8 @@ struct ra_ctx *ra_ctx_create(struct vo *vo, struct ra_ctx_opts opts) vo->probing = opts.probing; for (int i = 0; i < MP_ARRAY_SIZE(contexts); i++) { + if (contexts[i]->hidden) + continue; if (!opts.probing && strcmp(contexts[i]->name, opts.context_name) != 0) continue; if (!api_auto && strcmp(contexts[i]->type, opts.context_type) != 0) @@ -215,6 +221,28 @@ struct ra_ctx *ra_ctx_create(struct vo *vo, struct ra_ctx_opts opts) return NULL; } +struct ra_ctx *ra_ctx_create_by_name(struct vo *vo, const char *name) +{ + for (int i = 0; i < MP_ARRAY_SIZE(contexts); i++) { + if (strcmp(name, contexts[i]->name) != 0) + continue; + + struct ra_ctx *ctx = talloc_ptrtype(NULL, ctx); + *ctx = (struct ra_ctx) { + .vo = vo, + .global = vo->global, + .log = mp_log_new(ctx, vo->log, contexts[i]->type), + .fns = contexts[i], + }; + + MP_VERBOSE(ctx, "Initializing GPU context '%s'\n", ctx->fns->name); + if (contexts[i]->init(ctx)) + return ctx; + talloc_free(ctx); + } + return NULL; +} + void ra_ctx_destroy(struct ra_ctx **ctx_ptr) { struct ra_ctx *ctx = *ctx_ptr; |