summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2022-10-26 23:23:49 -0500
committerDudemanguy <random342@airmail.cc>2022-10-28 02:36:46 +0000
commitadb556bf15e9b09afce6c9cb0a0911c53cf27feb (patch)
tree06761b1b1ae91f1d7433855f645480e28d96300b
parent31af37f87762e5e548fa234b30f6248d8d6c19e4 (diff)
downloadmpv-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.
-rw-r--r--DOCS/man/options.rst5
-rw-r--r--video/out/gpu/context.c40
-rw-r--r--video/out/gpu/context.h5
-rw-r--r--video/out/vo_dmabuf_wayland.c6
-rw-r--r--video/out/wldmabuf/context_wldmabuf.c1
5 files changed, 41 insertions, 16 deletions
diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst
index ed55dbfeae..278a5e4d87 100644
--- a/DOCS/man/options.rst
+++ b/DOCS/man/options.rst
@@ -6150,8 +6150,6 @@ them.
X11/EGL
android
Android/EGL. Requires ``--wid`` be set to an ``android.view.Surface``.
- wldmabuf
- dmabuf buffers are rendered directly by Wayland compositor
``--gpu-api=<type>``
Controls which type of graphics APIs will be accepted:
@@ -6164,9 +6162,6 @@ them.
Allow only Vulkan (requires a valid/working ``--spirv-compiler``)
d3d11
Allow only ``--gpu-context=d3d11``
- none
- No graphics API is used - Wayland alone is used for rendering
- (requires Wayland compositor)
``--opengl-es=<mode>``
Controls which type of OpenGL context will be accepted:
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;
diff --git a/video/out/gpu/context.h b/video/out/gpu/context.h
index 7ad37f0d61..72ad65f470 100644
--- a/video/out/gpu/context.h
+++ b/video/out/gpu/context.h
@@ -36,6 +36,8 @@ struct ra_ctx_fns {
const char *type; // API type (for --gpu-api)
const char *name; // name (for --gpu-context)
+ bool hidden; // hide the ra_ctx from users
+
// Resize the window, or create a new window if there isn't one yet.
// Currently, there is an unfortunate interaction with ctx->vo, and
// display size etc. are determined by it.
@@ -101,3 +103,6 @@ struct ra_swapchain_fns {
// the underlying `struct ra`, and perhaps the underlying VO backend.
struct ra_ctx *ra_ctx_create(struct vo *vo, struct ra_ctx_opts opts);
void ra_ctx_destroy(struct ra_ctx **ctx);
+
+// Special case of creating a ra_ctx while specifiying a specific context by name.
+struct ra_ctx *ra_ctx_create_by_name(struct vo *vo, const char *name);
diff --git a/video/out/vo_dmabuf_wayland.c b/video/out/vo_dmabuf_wayland.c
index eb658b43d7..fe320de884 100644
--- a/video/out/vo_dmabuf_wayland.c
+++ b/video/out/vo_dmabuf_wayland.c
@@ -320,14 +320,10 @@ static void uninit(struct vo *vo)
static int preinit(struct vo *vo)
{
struct priv *p = vo->priv;
- struct ra_ctx_opts ctx_opts;
p->log = vo->log;
p->global = vo->global;
- ctx_opts.context_name = "wldmabuf";
- ctx_opts.context_type = "none";
- ctx_opts.probing = false;
- p->ctx = ra_ctx_create(vo, ctx_opts);
+ p->ctx = ra_ctx_create_by_name(vo, "wldmabuf");
if (!p->ctx)
goto err_out;
assert(p->ctx->ra);
diff --git a/video/out/wldmabuf/context_wldmabuf.c b/video/out/wldmabuf/context_wldmabuf.c
index a22cb2bf44..0a5999ad73 100644
--- a/video/out/wldmabuf/context_wldmabuf.c
+++ b/video/out/wldmabuf/context_wldmabuf.c
@@ -39,6 +39,7 @@ static bool init(struct ra_ctx *ctx)
const struct ra_ctx_fns ra_ctx_wldmabuf = {
.type = "none",
.name = "wldmabuf",
+ .hidden = true,
.init = init,
.uninit = uninit,
};