1
mirror of https://github.com/mpv-player/mpv synced 2024-11-07 01:47:00 +01:00

vo_opengl_cb: pass context directly

This is simpler than setting the context after VO creation, which
requires the code to check for the context on every entrypoint.
This commit is contained in:
wm4 2014-12-31 19:12:44 +01:00
parent 282e3202d5
commit 65f2c6c716
3 changed files with 43 additions and 62 deletions

View File

@ -269,6 +269,7 @@ int reinit_video_chain(struct MPContext *mpctx)
.input_ctx = mpctx->input,
.osd = mpctx->osd,
.encode_lavc_ctx = mpctx->encode_lavc_ctx,
.opengl_cb_context = mpctx->gl_cb_ctx,
};
mpctx->video_out = init_best_video_out(mpctx->global, &ex);
if (!mpctx->video_out) {
@ -278,9 +279,6 @@ int reinit_video_chain(struct MPContext *mpctx)
goto err_out;
}
mpctx->mouse_cursor_visible = true;
vo_control(mpctx->video_out, VOCTRL_SET_LIBMPV_OPENGL_CB_CONTEXT,
mpctx->gl_cb_ctx);
}
update_window_title(mpctx, true);

View File

@ -105,8 +105,6 @@ enum mp_voctrl {
VOCTRL_GET_RECENT_FLIP_TIME, // int64_t* (using mp_time_us())
VOCTRL_GET_PREF_DEINT, // int*
VOCTRL_SET_LIBMPV_OPENGL_CB_CONTEXT,// struct mpv_opengl_cb_context*
};
// VOCTRL_SET_EQUALIZER
@ -169,6 +167,7 @@ struct vo_extra {
struct input_ctx *input_ctx;
struct osd_state *osd;
struct encode_lavc_context *encode_lavc_ctx;
struct mpv_opengl_cb_context *opengl_cb_context;
};
struct vo_driver {

View File

@ -236,26 +236,24 @@ int mpv_opengl_cb_render(struct mpv_opengl_cb_context *ctx, int fbo, int vp[4])
static void draw_image(struct vo *vo, mp_image_t *mpi)
{
struct vo_priv *p = vo->priv;
if (p->ctx) {
pthread_mutex_lock(&p->ctx->lock);
mp_image_setrefp(&p->ctx->waiting_frame, mpi);
pthread_mutex_unlock(&p->ctx->lock);
}
pthread_mutex_lock(&p->ctx->lock);
mp_image_setrefp(&p->ctx->waiting_frame, mpi);
talloc_free(mpi);
pthread_mutex_unlock(&p->ctx->lock);
}
static void flip_page(struct vo *vo)
{
struct vo_priv *p = vo->priv;
if (p->ctx) {
pthread_mutex_lock(&p->ctx->lock);
mp_image_unrefp(&p->ctx->next_frame);
p->ctx->next_frame = p->ctx->waiting_frame;
p->ctx->waiting_frame = NULL;
if (p->ctx->update_cb)
p->ctx->update_cb(p->ctx->update_cb_ctx);
pthread_mutex_unlock(&p->ctx->lock);
}
pthread_mutex_lock(&p->ctx->lock);
mp_image_unrefp(&p->ctx->next_frame);
p->ctx->next_frame = p->ctx->waiting_frame;
p->ctx->waiting_frame = NULL;
if (p->ctx->update_cb)
p->ctx->update_cb(p->ctx->update_cb_ctx);
pthread_mutex_unlock(&p->ctx->lock);
}
static int query_format(struct vo *vo, uint32_t format)
@ -263,12 +261,10 @@ static int query_format(struct vo *vo, uint32_t format)
struct vo_priv *p = vo->priv;
bool ok = false;
if (p->ctx) {
pthread_mutex_lock(&p->ctx->lock);
if (format >= IMGFMT_START && format < IMGFMT_END)
ok = p->ctx->imgfmt_supported[format - IMGFMT_START];
pthread_mutex_unlock(&p->ctx->lock);
}
pthread_mutex_lock(&p->ctx->lock);
if (format >= IMGFMT_START && format < IMGFMT_END)
ok = p->ctx->imgfmt_supported[format - IMGFMT_START];
pthread_mutex_unlock(&p->ctx->lock);
return ok ? VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW : 0;
}
@ -276,15 +272,11 @@ static int reconfig(struct vo *vo, struct mp_image_params *params, int flags)
{
struct vo_priv *p = vo->priv;
if (p->ctx) {
pthread_mutex_lock(&p->ctx->lock);
mp_image_unrefp(&p->ctx->next_frame);
p->ctx->img_params = *params;
p->ctx->reconfigured = true;
pthread_mutex_unlock(&p->ctx->lock);
} else {
return -1;
}
pthread_mutex_lock(&p->ctx->lock);
mp_image_unrefp(&p->ctx->next_frame);
p->ctx->img_params = *params;
p->ctx->reconfigured = true;
pthread_mutex_unlock(&p->ctx->lock);
return 0;
}
@ -294,25 +286,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
struct vo_priv *p = vo->priv;
switch (request) {
case VOCTRL_SET_LIBMPV_OPENGL_CB_CONTEXT: {
if (p->ctx)
return VO_FALSE;
struct mpv_opengl_cb_context *nctx = data;
if (nctx) {
pthread_mutex_lock(&nctx->lock);
if (nctx->active) {
MP_FATAL(vo, "There is already a VO using the OpenGL context.\n");
} else {
nctx->active = vo;
nctx->reconfigured = true;
p->ctx = nctx;
assert(vo->osd == p->ctx->osd);
copy_vo_opts(vo);
}
pthread_mutex_unlock(&nctx->lock);
}
return VO_TRUE;
}
case VOCTRL_GET_PANSCAN:
return VO_TRUE;
case VOCTRL_SET_PANSCAN:
@ -341,21 +314,32 @@ static void uninit(struct vo *vo)
{
struct vo_priv *p = vo->priv;
if (p->ctx) {
pthread_mutex_lock(&p->ctx->lock);
mp_image_unrefp(&p->ctx->next_frame);
mp_image_unrefp(&p->ctx->waiting_frame);
p->ctx->img_params = (struct mp_image_params){0};
p->ctx->reconfigured = true;
p->ctx->active = NULL;
pthread_mutex_unlock(&p->ctx->lock);
}
pthread_mutex_lock(&p->ctx->lock);
mp_image_unrefp(&p->ctx->next_frame);
mp_image_unrefp(&p->ctx->waiting_frame);
p->ctx->img_params = (struct mp_image_params){0};
p->ctx->reconfigured = true;
p->ctx->active = NULL;
pthread_mutex_unlock(&p->ctx->lock);
}
static int preinit(struct vo *vo)
{
struct vo_priv *p = vo->priv;
p->vo = vo;
p->ctx = vo->extra.opengl_cb_context;
if (!p->ctx) {
MP_FATAL(vo, "No context set.\n");
return -1;
}
pthread_mutex_lock(&p->ctx->lock);
p->ctx->active = vo;
p->ctx->reconfigured = true;
assert(vo->osd == p->ctx->osd);
copy_vo_opts(vo);
pthread_mutex_unlock(&p->ctx->lock);
return 0;
}