summaryrefslogtreecommitdiffstats
path: root/video/out/gpu
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-03-22 17:05:01 +0100
committerwm4 <wm4@nowhere>2018-03-26 19:47:08 +0200
commit52dd38a48a4a94d1c477b62cebcd67b911eb27fa (patch)
treeff2449de78ae1a30af5fbb7c6e399172403549b4 /video/out/gpu
parent0b4120919aa1e4e70b49dd3f93af0acddd7ea4d3 (diff)
downloadmpv-52dd38a48a4a94d1c477b62cebcd67b911eb27fa.tar.bz2
mpv-52dd38a48a4a94d1c477b62cebcd67b911eb27fa.tar.xz
client API: add a new way to pass X11 Display etc. to render API
Hardware decoding things often need access to additional handles from the windowing system, such as the X11 or Wayland display when using vaapi. The opengl-cb had nothing dedicated for this, and used the weird GL_MP_MPGetNativeDisplay GL extension (which was mpv specific and not officially registered with OpenGL). This was awkward, and a pain due to having to emulate GL context behavior (like needing a TLS variable to store context for the pseudo GL extension function). In addition (and not inherently due to this), we could pass only one resource from mpv builtin context backends to hwdecs. It was also all GL specific. Replace this with a newer mechanism. It works for all RA backends, not just GL. the API user can explicitly pass the objects at init time via mpv_render_context_create(). Multiple resources are naturally possible. The API uses MPV_RENDER_PARAM_* defines, but internally we use strings. This is done for 2 reasons: 1. trying to leave libmpv and internal mechanisms decoupled, 2. not having to add public API for some of the internal resource types (especially D3D/GL interop stuff). To remain sane, drop support for obscure half-working opengl-cb things, like the DRM interop (was missing necessary things), the RPI window thing (nobody used it), and obscure D3D interop things (not needed with ANGLE, others were undocumented). In order not to break ABI and the C API, we don't remove the associated structs from opengl_cb.h. The parts which are still needed (in particular DRM interop) needs to be ported to the render API.
Diffstat (limited to 'video/out/gpu')
-rw-r--r--video/out/gpu/libmpv_gpu.c15
-rw-r--r--video/out/gpu/libmpv_gpu.h2
-rw-r--r--video/out/gpu/ra.c20
-rw-r--r--video/out/gpu/ra.h21
4 files changed, 58 insertions, 0 deletions
diff --git a/video/out/gpu/libmpv_gpu.c b/video/out/gpu/libmpv_gpu.c
index bd597c302a..cc0ff85376 100644
--- a/video/out/gpu/libmpv_gpu.c
+++ b/video/out/gpu/libmpv_gpu.c
@@ -17,6 +17,11 @@ struct priv {
struct gl_video *renderer;
};
+static const char *const native_resource_map[] = {
+ [MPV_RENDER_PARAM_X11_DISPLAY] = "x11",
+ [MPV_RENDER_PARAM_WL_DISPLAY] = "wl",
+};
+
static int init(struct render_backend *ctx, mpv_render_param *params)
{
ctx->priv = talloc_zero(NULL, struct priv);
@@ -46,6 +51,16 @@ static int init(struct render_backend *ctx, mpv_render_param *params)
if (err < 0)
return err;
+ for (int n = 0; params && params[n].type; n++) {
+ if (params[n].type > 0 &&
+ params[n].type < MP_ARRAY_SIZE(native_resource_map) &&
+ native_resource_map[params[n].type])
+ {
+ ra_add_native_resource(p->context->ra,
+ native_resource_map[params[n].type], params[n].data);
+ }
+ }
+
p->renderer = gl_video_init(p->context->ra, ctx->log, ctx->global);
ctx->hwdec_devs = hwdec_devices_create();
diff --git a/video/out/gpu/libmpv_gpu.h b/video/out/gpu/libmpv_gpu.h
index 5b41116f14..2c9f712fce 100644
--- a/video/out/gpu/libmpv_gpu.h
+++ b/video/out/gpu/libmpv_gpu.h
@@ -2,6 +2,8 @@
#include "video/out/libmpv.h"
+struct ra_tex;
+
struct libmpv_gpu_context {
struct mpv_global *global;
struct mp_log *log;
diff --git a/video/out/gpu/ra.c b/video/out/gpu/ra.c
index fdb20fe1d5..0c1565149f 100644
--- a/video/out/gpu/ra.c
+++ b/video/out/gpu/ra.c
@@ -4,6 +4,26 @@
#include "ra.h"
+void ra_add_native_resource(struct ra *ra, const char *name, void *data)
+{
+ struct ra_native_resource r = {
+ .name = name,
+ .data = data,
+ };
+ MP_TARRAY_APPEND(ra, ra->native_resources, ra->num_native_resources, r);
+}
+
+void *ra_get_native_resource(struct ra *ra, const char *name)
+{
+ for (int n = 0; n < ra->num_native_resources; n++) {
+ struct ra_native_resource *r = &ra->native_resources[n];
+ if (strcmp(r->name, name) == 0)
+ return r->data;
+ }
+
+ return NULL;
+}
+
struct ra_tex *ra_tex_create(struct ra *ra, const struct ra_tex_params *params)
{
return ra->fns->tex_create(ra, params);
diff --git a/video/out/gpu/ra.h b/video/out/gpu/ra.h
index 05a7c54a66..79caacc919 100644
--- a/video/out/gpu/ra.h
+++ b/video/out/gpu/ra.h
@@ -39,8 +39,29 @@ struct ra {
// RA_CAP_DIRECT_UPLOAD is supported. This is basically only relevant for
// OpenGL. Set by the RA user.
bool use_pbo;
+
+ // Array of native resources. For the most part an "escape" mechanism, and
+ // usually does not contain parameters required for basic functionality.
+ struct ra_native_resource *native_resources;
+ int num_native_resources;
+};
+
+// For passing through windowing system specific parameters and such. The
+// names are always internal (except for legacy opengl-cb uses; the libmpv
+// render API uses mpv_render_param_type and maps them to names internally).
+// For example, a name="x11" entry has a X11 display as (Display*)data.
+struct ra_native_resource {
+ const char *name;
+ void *data;
};
+// Add a ra_native_resource entry. Both name and data pointers must stay valid
+// until ra termination.
+void ra_add_native_resource(struct ra *ra, const char *name, void *data);
+
+// Search ra->native_resources, returns NULL on failure.
+void *ra_get_native_resource(struct ra *ra, const char *name);
+
enum {
RA_CAP_TEX_1D = 1 << 0, // supports 1D textures (as shader inputs)
RA_CAP_TEX_3D = 1 << 1, // supports 3D textures (as shader inputs)