client API: clarify that Display pointers etc. need to stay valid

Normally, MPV_RENDER_PARAM* arguments are copied, unless documented
otherwise. Of course we can't copy X11 Display or Wayland wl_display
types, but for arguments that are "summarized" in a struct (like
MPV_RENDER_PARAM_OPENGL_FBO), a copy is expected.

Also add some unused infrastructure to make this explicit, and to make
it easier to add parameter types that require a copy.

Untested.
This commit is contained in:
wm4 2018-04-15 12:31:07 +02:00 committed by Jan Ekström
parent 7bfb240309
commit f9bcb5c42c
2 changed files with 25 additions and 8 deletions

View File

@ -154,13 +154,15 @@ typedef enum mpv_render_param_type {
MPV_RENDER_PARAM_AMBIENT_LIGHT = 7,
/**
* X11 Display, sometimes used for hwdec. Valid for
* mpv_render_context_create().
* mpv_render_context_create(). The Display must stay valid for the lifetime
* of the mpv_render_context.
* Type: Display*
*/
MPV_RENDER_PARAM_X11_DISPLAY = 8,
/**
* Wayland display, sometimes used for hwdec. Valid for
* mpv_render_context_create().
* mpv_render_context_create(). The wl_display must stay valid for the
* lifetime of the mpv_render_context.
* Type: struct wl_display*
*/
MPV_RENDER_PARAM_WL_DISPLAY = 9,

View File

@ -17,9 +17,20 @@ 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",
struct native_resource_entry {
const char *name; // ra_add_native_resource() internal name argument
size_t size; // size of struct pointed to (0 for no copy)
};
static const struct native_resource_entry native_resource_map[] = {
[MPV_RENDER_PARAM_X11_DISPLAY] = {
.name = "x11",
.size = 0,
},
[MPV_RENDER_PARAM_WL_DISPLAY] = {
.name = "wl",
.size = 0,
},
};
static int init(struct render_backend *ctx, mpv_render_param *params)
@ -54,10 +65,14 @@ static int init(struct render_backend *ctx, mpv_render_param *params)
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])
native_resource_map[params[n].type].name)
{
ra_add_native_resource(p->context->ra,
native_resource_map[params[n].type], params[n].data);
const struct native_resource_entry *entry =
&native_resource_map[params[n].type];
void *data = params[n].data;
if (entry->size)
data = talloc_memdup(p, data, entry->size);
ra_add_native_resource(p->context->ra, entry->name, data);
}
}