vo_gpu_next: improve updating overlays

fbe154831a added a new VOCTRL to signal
when the OSD changed for gpu-next's handling of subtitles, but this is
both not necessary and actually incomplete. The VOCTRL would signal OSD
changes, but not all subtitle changes (like selecting another
non-external sub track for example). VOCTRL_OSD_CHANGED was used to
increment p->osd_sync which would then redraw the blended subtitles if
the player was paused.

But there's already a VOCTRL_PAUSE and VOCTRL_RESUME. Plus, the
sub_bitmap_list object will have items in it if it changed in any way,
so we don't need the VOCTRL_OSD_CHANGED method at all. That can be
removed.

The check that fp->osd_sync < p->osd_sync stays in place since that's an
optimization while the video is playing, but we also check the pause
state as well since the VO can know this. If we're paused, then always
do update_overlays since core must be signalling a redraw to us if we
get a draw_frame call here. Additionally in update_overlays itself, the
p->osd_sync counter is incremented if we have any items since the frame
signature will need that. As for the actual bug that is fixed, changing
subtitle tracks while paused with blended subtitles now correctly works.
Previously, it was never updated so the old subtitle stayed there
forever until you deselected it (since VOCTRL_OSD_CHANGED triggered
there).

Also include some cosmetic code fixes that were noticed.
This commit is contained in:
Dudemanguy 2023-09-28 13:07:42 -05:00
parent 61aecfabfd
commit 07995f5d5f
4 changed files with 22 additions and 27 deletions

View File

@ -6930,8 +6930,6 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags,
}
}
osd_changed(mpctx->osd);
if (mpctx->video_out)
vo_control_async(mpctx->video_out, VOCTRL_OSD_CHANGED, NULL);
if (flags & (UPDATE_SUB_FILT | UPDATE_SUB_HARD))
mp_force_video_refresh(mpctx);
mp_wakeup_core(mpctx);

View File

@ -683,7 +683,6 @@ void vo_control_async(struct vo *vo, int request, void *data)
break;
case VOCTRL_KILL_SCREENSAVER:
case VOCTRL_RESTORE_SCREENSAVER:
case VOCTRL_OSD_CHANGED:
break;
default:
abort(); // requires explicit support

View File

@ -72,9 +72,6 @@ enum mp_voctrl {
// you could install your own listener.
VOCTRL_VO_OPTS_CHANGED,
// Triggered by any change to the OSD (e.g. OSD style changes)
VOCTRL_OSD_CHANGED,
/* private to vo_gpu */
VOCTRL_LOAD_HWDEC_API,

View File

@ -158,6 +158,7 @@ struct priv {
bool is_interpolated;
bool want_reset;
bool frame_pending;
bool paused;
pl_options pars;
struct m_config_cache *opts_cache;
@ -286,6 +287,9 @@ static void update_overlays(struct vo *vo, struct mp_osd_res res,
double pts = src ? src->pts : 0;
struct sub_bitmap_list *subs = osd_render(vo->osd, res, pts, flags, subfmt_all);
if (subs->num_items)
p->osd_sync++;
frame->overlays = state->overlays;
frame->num_overlays = 0;
@ -1081,10 +1085,8 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)
struct mp_image *mpi = image->user_data;
struct frame_priv *fp = mpi->priv;
apply_crop(image, p->src, vo->params->w, vo->params->h);
if (opts->blend_subs) {
if (fp->osd_sync < p->osd_sync) {
// Only update the overlays if the state has changed
if (p->paused || fp->osd_sync < p->osd_sync) {
float rx = pl_rect_w(p->dst) / pl_rect_w(image->crop);
float ry = pl_rect_h(p->dst) / pl_rect_h(image->crop);
struct mp_osd_res res = {
@ -1403,21 +1405,20 @@ static void video_screenshot(struct vo *vo, struct voctrl_screenshot *args)
const struct gl_video_opts *opts = p->opts_cache->opts;
struct frame_priv *fp = mpi->priv;
if (opts->blend_subs) {
// Only update the overlays if the state has changed
float rx = pl_rect_w(dst) / pl_rect_w(image.crop);
float ry = pl_rect_h(dst) / pl_rect_h(image.crop);
struct mp_osd_res res = {
.w = pl_rect_w(dst),
.h = pl_rect_h(dst),
.ml = -image.crop.x0 * rx,
.mr = (image.crop.x1 - vo->params->w) * rx,
.mt = -image.crop.y0 * ry,
.mb = (image.crop.y1 - vo->params->h) * ry,
.display_par = 1.0,
};
update_overlays(vo, res, osd_flags,
PL_OVERLAY_COORDS_DST_CROP,
&fp->subs, &image, mpi);
float rx = pl_rect_w(dst) / pl_rect_w(image.crop);
float ry = pl_rect_h(dst) / pl_rect_h(image.crop);
struct mp_osd_res res = {
.w = pl_rect_w(dst),
.h = pl_rect_h(dst),
.ml = -image.crop.x0 * rx,
.mr = (image.crop.x1 - vo->params->w) * rx,
.mt = -image.crop.y0 * ry,
.mb = (image.crop.y1 - vo->params->h) * ry,
.display_par = 1.0,
};
update_overlays(vo, res, osd_flags,
PL_OVERLAY_COORDS_DST_CROP,
&fp->subs, &image, mpi);
} else {
// Disable overlays when blend_subs is disabled
update_overlays(vo, osd, osd_flags, PL_OVERLAY_COORDS_DST_FRAME,
@ -1489,12 +1490,12 @@ static int control(struct vo *vo, uint32_t request, void *data)
return VO_TRUE;
case VOCTRL_SET_EQUALIZER:
case VOCTRL_PAUSE:
p->paused = true;
if (p->is_interpolated)
vo->want_redraw = true;
return VO_TRUE;
case VOCTRL_OSD_CHANGED:
p->osd_sync++;
case VOCTRL_RESUME:
p->paused = false;
return VO_TRUE;
case VOCTRL_UPDATE_RENDER_OPTS: {