1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-18 21:06:00 +00:00

sub: simplify OSD redrawing logic

Normally, we can redraw the OSD any time. But some drivers don't support
OSD redrawing (vo_null etc.), or only "sometimes" (vo_xv). For that,
some additional logic is needed. Simplify that logic. This might also
fix subtle bugs with the OSD not updating or endless frame stepping in
unforseen corner cases.

Do this by adding a new flag, which tells whether the OSD should be
redrawn.

Remove some minor code duplication.
This commit is contained in:
wm4 2012-10-21 14:58:46 +02:00
parent 796e5638ac
commit 0c49ddc818
3 changed files with 16 additions and 25 deletions

View File

@ -2544,15 +2544,22 @@ void unpause_player(struct MPContext *mpctx)
(void)get_relative_time(mpctx); // ignore time that passed during pause
}
static void draw_osd(struct MPContext *mpctx)
{
struct vo *vo = mpctx->video_out;
mpctx->osd->vo_pts = mpctx->video_pts;
vo_draw_osd(vo, mpctx->osd);
mpctx->osd->want_redraw = false;
}
static int redraw_osd(struct MPContext *mpctx)
{
struct vo *vo = mpctx->video_out;
if (vo_redraw_frame(vo) < 0)
return -1;
mpctx->osd->vo_pts = mpctx->video_pts;
vo_draw_osd(vo, mpctx->osd);
osd_reset_changed(mpctx->osd);
draw_osd(mpctx);
vo_flip_page(vo, 0, -1);
return 0;
@ -3158,10 +3165,7 @@ static void run_playloop(struct MPContext *mpctx)
mpctx->video_pts = sh_video->pts;
update_subtitles(mpctx, sh_video->pts);
update_osd_msg(mpctx);
mpctx->osd->vo_pts = mpctx->video_pts;
vo_draw_osd(vo, mpctx->osd);
osd_reset_changed(mpctx->osd);
draw_osd(mpctx);
mpctx->time_frame -= get_relative_time(mpctx);
mpctx->time_frame -= vo->flip_queue_offset;
@ -3303,7 +3307,8 @@ static void run_playloop(struct MPContext *mpctx)
if (sleeptime > 0) {
if (!mpctx->sh_video)
goto novideo;
if (osd_has_changed(mpctx->osd) || mpctx->video_out->want_redraw) {
if (mpctx->osd->want_redraw || mpctx->video_out->want_redraw) {
mpctx->osd->want_redraw = false;
if (redraw_osd(mpctx) < 0) {
if (mpctx->paused && video_left)
add_step_frame(mpctx);

View File

@ -280,21 +280,7 @@ void vo_osd_changed(int new_value)
if (osd->objs[n]->type == new_value)
osd->objs[n]->force_redraw = true;
}
}
bool osd_has_changed(struct osd_state *osd)
{
for (int n = 0; n < MAX_OSD_PARTS; n++) {
if (osd->objs[n]->force_redraw)
return true;
}
return false;
}
void osd_reset_changed(struct osd_state *osd)
{
for (int n = 0; n < MAX_OSD_PARTS; n++)
osd->objs[n]->force_redraw = false;
osd->want_redraw = true;
}
bool sub_bitmaps_bb(struct sub_bitmaps *imgs, int *x1, int *y1,

View File

@ -126,6 +126,8 @@ struct osd_state {
bool render_subs_in_filter;
bool want_redraw;
char *osd_text; // OSDTYPE_OSD
int progbar_type, progbar_value; // OSDTYPE_PROGBAR
@ -203,8 +205,6 @@ extern int sub_justify;
struct osd_state *osd_create(struct MPOpts *opts, struct ass_library *asslib);
void osd_set_text(struct osd_state *osd, const char *text);
void vo_osd_changed(int new_value);
void osd_reset_changed(struct osd_state *osd);
bool osd_has_changed(struct osd_state *osd);
void osd_free(struct osd_state *osd);
enum mp_osd_draw_flags {