From baabd5fce33d4f85de30477e1aa60b2fc6c02abd Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 13 May 2020 20:07:59 +0200 Subject: draw_bmp: use command line options for any used scalers --- sub/draw_bmp.c | 29 ++++++++++++++++++++--------- sub/draw_bmp.h | 3 ++- sub/osd.c | 12 ++++++++++-- 3 files changed, 32 insertions(+), 12 deletions(-) (limited to 'sub') diff --git a/sub/draw_bmp.c b/sub/draw_bmp.c index ba6ea7e646..b208ec6ad5 100644 --- a/sub/draw_bmp.c +++ b/sub/draw_bmp.c @@ -60,6 +60,8 @@ struct slice { struct mp_draw_sub_cache { + struct mpv_global *global; + // Possibly cached parts. Also implies what's in the video_overlay. struct part parts[MAX_OSD_PARTS]; int64_t change_id; @@ -490,9 +492,16 @@ static void clear_rgba_overlay(struct mp_draw_sub_cache *p) p->any_osd = false; } +static struct mp_sws_context *alloc_scaler(struct mp_draw_sub_cache *p) +{ + struct mp_sws_context *s = mp_sws_alloc(p); + mp_sws_enable_cmdline_opts(s, p->global); + return s; +} + static void init_general(struct mp_draw_sub_cache *p) { - p->sub_scale = mp_sws_alloc(p); + p->sub_scale = alloc_scaler(p); p->s_w = MP_ALIGN_UP(p->rgba_overlay->w, SLICE_W) / SLICE_W; @@ -664,7 +673,7 @@ static bool reinit_to_video(struct mp_draw_sub_cache *p) if (p->scale_in_tiles) p->video_overlay->params.chroma_location = MP_CHROMA_CENTER; - p->rgba_to_overlay = mp_sws_alloc(p); + p->rgba_to_overlay = alloc_scaler(p); p->rgba_to_overlay->allow_zimg = true; if (!mp_sws_supports_formats(p->rgba_to_overlay, p->video_overlay->imgfmt, p->rgba_overlay->imgfmt)) @@ -729,7 +738,7 @@ static bool reinit_to_video(struct mp_draw_sub_cache *p) 0, p->calpha_overlay, NULL)) return false; - p->alpha_to_calpha = mp_sws_alloc(p); + p->alpha_to_calpha = alloc_scaler(p); if (!mp_sws_supports_formats(p->alpha_to_calpha, calpha_fmt, calpha_fmt)) return false; @@ -737,8 +746,8 @@ static bool reinit_to_video(struct mp_draw_sub_cache *p) } if (need_premul) { - p->premul = mp_sws_alloc(p); - p->unpremul = mp_sws_alloc(p); + p->premul = alloc_scaler(p); + p->unpremul = alloc_scaler(p); p->premul_tmp = mp_image_alloc(params->imgfmt, params->w, params->h); talloc_steal(p, p->premul_tmp); if (!p->premul_tmp) @@ -794,10 +803,10 @@ static bool check_reinit(struct mp_draw_sub_cache *p, { if (!mp_image_params_equal(&p->params, params) || !p->rgba_overlay) { talloc_free_children(p); - *p = (struct mp_draw_sub_cache){.params = *params}; + *p = (struct mp_draw_sub_cache){.global = p->global, .params = *params}; if (!(to_video ? reinit_to_video(p) : reinit_to_overlay(p))) { talloc_free_children(p); - *p = (struct mp_draw_sub_cache){0}; + *p = (struct mp_draw_sub_cache){.global = p->global}; return false; } } @@ -819,9 +828,11 @@ char *mp_draw_sub_get_dbg_info(struct mp_draw_sub_cache *p) mp_imgfmt_to_name(p->calpha_tmp ? p->calpha_tmp->imgfmt : 0)); } -struct mp_draw_sub_cache *mp_draw_sub_alloc(void *ta_parent) +struct mp_draw_sub_cache *mp_draw_sub_alloc(void *ta_parent, struct mpv_global *g) { - return talloc_zero(ta_parent, struct mp_draw_sub_cache); + struct mp_draw_sub_cache *c = talloc_zero(ta_parent, struct mp_draw_sub_cache); + c->global = g; + return c; } bool mp_draw_sub_bitmaps(struct mp_draw_sub_cache *p, struct mp_image *dst, diff --git a/sub/draw_bmp.h b/sub/draw_bmp.h index d54a1c7685..90e0ef6368 100644 --- a/sub/draw_bmp.h +++ b/sub/draw_bmp.h @@ -5,9 +5,10 @@ struct mp_rect; struct mp_image; +struct mpv_global; struct mp_draw_sub_cache; -struct mp_draw_sub_cache *mp_draw_sub_alloc(void *ta_parent); +struct mp_draw_sub_cache *mp_draw_sub_alloc(void *ta_parent, struct mpv_global *g); // Render the sub-bitmaps in sbs_list to dst. sbs_list must have been rendered // for an OSD resolution equivalent to dst's size (UB if not). diff --git a/sub/osd.c b/sub/osd.c index d6f284c398..c45668c3f4 100644 --- a/sub/osd.c +++ b/sub/osd.c @@ -196,7 +196,15 @@ bool osd_get_render_subs_in_filter(struct osd_state *osd) void osd_set_render_subs_in_filter(struct osd_state *osd, bool s) { pthread_mutex_lock(&osd->lock); - osd->render_subs_in_filter = s; + if (osd->render_subs_in_filter != s) { + osd->render_subs_in_filter = s; + + int change_id = 0; + for (int n = 0; n < MAX_OSD_PARTS; n++) + change_id = MPMAX(change_id, osd->objs[n]->vo_change_id); + for (int n = 0; n < MAX_OSD_PARTS; n++) + osd->objs[n]->vo_change_id = change_id + 1; + } pthread_mutex_unlock(&osd->lock); } @@ -426,7 +434,7 @@ void osd_draw_on_image_p(struct osd_state *osd, struct mp_osd_res res, pthread_mutex_lock(&osd->lock); if (!osd->draw_cache) - osd->draw_cache = mp_draw_sub_alloc(osd); + osd->draw_cache = mp_draw_sub_alloc(osd, osd->global); stats_time_start(osd->stats, "draw-bmp"); -- cgit v1.2.3