mirror of https://github.com/mpv-player/mpv
vo_opengl_cb: simplify reconfigure, render transparent if unconfigured
I think that's expected; mpv shouldn't draw anything while no video is active. This doesn't blend transparently, though. Also document the vo_opengl_cb thing.
This commit is contained in:
parent
0125fb6714
commit
273565c525
|
@ -931,3 +931,6 @@ Available video output drivers are:
|
||||||
Use 3 buffers instead of 2. This can lead to more fluid playback, but
|
Use 3 buffers instead of 2. This can lead to more fluid playback, but
|
||||||
uses more memory.
|
uses more memory.
|
||||||
|
|
||||||
|
``opengl-cb``
|
||||||
|
For use with libmpv direct OpenGL embedding; useless in any other contexts.
|
||||||
|
(See ``<mpv/opengl_cb.h>``.)
|
||||||
|
|
|
@ -2387,6 +2387,7 @@ void gl_video_config(struct gl_video *p, struct mp_image_params *params)
|
||||||
|
|
||||||
if (!mp_image_params_equal(&p->image_params, params)) {
|
if (!mp_image_params_equal(&p->image_params, params)) {
|
||||||
uninit_video(p);
|
uninit_video(p);
|
||||||
|
if (params->imgfmt)
|
||||||
init_video(p, params);
|
init_video(p, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ struct mpv_opengl_cb_context {
|
||||||
void *update_cb_ctx;
|
void *update_cb_ctx;
|
||||||
struct mp_image *next_frame;
|
struct mp_image *next_frame;
|
||||||
struct mp_image_params img_params;
|
struct mp_image_params img_params;
|
||||||
struct mp_image_params *new_params;
|
bool reconfigured;
|
||||||
struct mp_rect wnd;
|
struct mp_rect wnd;
|
||||||
bool flip;
|
bool flip;
|
||||||
bool force_update;
|
bool force_update;
|
||||||
|
@ -175,12 +175,7 @@ int mpv_opengl_cb_render(struct mpv_opengl_cb_context *ctx, int fbo, int vp[4])
|
||||||
|
|
||||||
struct vo *vo = ctx->active;
|
struct vo *vo = ctx->active;
|
||||||
|
|
||||||
struct mp_image_params *new_params = ctx->new_params;
|
ctx->force_update |= ctx->reconfigured;
|
||||||
ctx->new_params = NULL;
|
|
||||||
if (new_params) {
|
|
||||||
ctx->img_params = *new_params;
|
|
||||||
ctx->force_update = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int h = vp[3];
|
int h = vp[3];
|
||||||
bool flip = h < 0 && h > INT_MIN;
|
bool flip = h < 0 && h > INT_MIN;
|
||||||
|
@ -205,9 +200,12 @@ int mpv_opengl_cb_render(struct mpv_opengl_cb_context *ctx, int fbo, int vp[4])
|
||||||
gl_video_resize(ctx->renderer, &wnd, &src, &dst, &osd, !ctx->flip);
|
gl_video_resize(ctx->renderer, &wnd, &src, &dst, &osd, !ctx->flip);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new_params) {
|
if (ctx->reconfigured) {
|
||||||
gl_video_config(ctx->renderer, new_params);
|
ctx->reconfigured = false;
|
||||||
talloc_free(new_params);
|
gl_video_config(ctx->renderer, &ctx->img_params);
|
||||||
|
struct gl_video_opts opts = gl_video_opts_def;
|
||||||
|
opts.background.a = 0; // transparent
|
||||||
|
gl_video_set_options(ctx->renderer, &opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mp_image *mpi = ctx->next_frame;
|
struct mp_image *mpi = ctx->next_frame;
|
||||||
|
@ -268,8 +266,8 @@ static int reconfig(struct vo *vo, struct mp_image_params *params, int flags)
|
||||||
if (p->ctx) {
|
if (p->ctx) {
|
||||||
pthread_mutex_lock(&p->ctx->lock);
|
pthread_mutex_lock(&p->ctx->lock);
|
||||||
mp_image_unrefp(&p->ctx->next_frame);
|
mp_image_unrefp(&p->ctx->next_frame);
|
||||||
talloc_free(p->ctx->new_params);
|
p->ctx->img_params = *params;
|
||||||
p->ctx->new_params = talloc_memdup(NULL, params, sizeof(*params));
|
p->ctx->reconfigured = true;
|
||||||
pthread_mutex_unlock(&p->ctx->lock);
|
pthread_mutex_unlock(&p->ctx->lock);
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -293,6 +291,7 @@ static int control(struct vo *vo, uint32_t request, void *data)
|
||||||
MP_FATAL(vo, "There is already a VO using the OpenGL context.\n");
|
MP_FATAL(vo, "There is already a VO using the OpenGL context.\n");
|
||||||
} else {
|
} else {
|
||||||
nctx->active = vo;
|
nctx->active = vo;
|
||||||
|
nctx->reconfigured = true;
|
||||||
p->ctx = nctx;
|
p->ctx = nctx;
|
||||||
assert(vo->osd == p->ctx->osd);
|
assert(vo->osd == p->ctx->osd);
|
||||||
copy_vo_opts(vo);
|
copy_vo_opts(vo);
|
||||||
|
@ -332,8 +331,8 @@ static void uninit(struct vo *vo)
|
||||||
if (p->ctx) {
|
if (p->ctx) {
|
||||||
pthread_mutex_lock(&p->ctx->lock);
|
pthread_mutex_lock(&p->ctx->lock);
|
||||||
mp_image_unrefp(&p->ctx->next_frame);
|
mp_image_unrefp(&p->ctx->next_frame);
|
||||||
talloc_free(p->ctx->new_params);
|
p->ctx->img_params = (struct mp_image_params){0};
|
||||||
p->ctx->new_params = NULL;
|
p->ctx->reconfigured = true;
|
||||||
p->ctx->active = NULL;
|
p->ctx->active = NULL;
|
||||||
pthread_mutex_unlock(&p->ctx->lock);
|
pthread_mutex_unlock(&p->ctx->lock);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue