mirror of
https://github.com/mpv-player/mpv
synced 2025-01-01 20:32:13 +00:00
osd: minor simplification of vo_osd_changed()
vo_osd_changed() was a weird function: it was used both to query and mutate state, which is a bad combination. The VOs used it to query and reset the state, and the mplayer frontend mostly used it to set the state. In some cases, the frontend did both (that code used a variable "int hack" to backup the state and set it again). Simplify it and make the VOs use a vo_osd_has_changed() function to query whether the OSD bitmaps have to be recreated. vo_osd_changed() on the other hand is now used to update state only. The OSD change state is reset when osd_draw_text() is called. Update vo_corevideo.m to use vo_osd_resized() as well (forgotten change from libass-OSD merge). Simplify osd_set_text() and its usages.
This commit is contained in:
parent
59b938c8aa
commit
168293e0ae
@ -99,7 +99,7 @@ static void resize(struct vo *vo, int width, int height)
|
|||||||
gl->MatrixMode(GL_MODELVIEW);
|
gl->MatrixMode(GL_MODELVIEW);
|
||||||
gl->LoadIdentity();
|
gl->LoadIdentity();
|
||||||
|
|
||||||
vo_osd_changed(OSDTYPE_OSD);
|
vo_osd_resized();
|
||||||
|
|
||||||
gl->Clear(GL_COLOR_BUFFER_BIT);
|
gl->Clear(GL_COLOR_BUFFER_BIT);
|
||||||
vo->want_redraw = true;
|
vo->want_redraw = true;
|
||||||
@ -232,7 +232,7 @@ static void draw_osd(struct vo *vo, struct osd_state *osd_s)
|
|||||||
struct osd_p *osd = p->osd;
|
struct osd_p *osd = p->osd;
|
||||||
GL *gl = p->mpglctx->gl;
|
GL *gl = p->mpglctx->gl;
|
||||||
|
|
||||||
if (vo_osd_changed(0)) {
|
if (vo_osd_has_changed()) {
|
||||||
clearOSD(vo);
|
clearOSD(vo);
|
||||||
osd_draw_text_ext(osd_s, vo->dwidth, vo->dheight, 0, 0, 0, 0,
|
osd_draw_text_ext(osd_s, vo->dwidth, vo->dheight, 0, 0, 0, 0,
|
||||||
p->image_width, p->image_height, create_osd_texture,
|
p->image_width, p->image_height, create_osd_texture,
|
||||||
|
@ -1991,7 +1991,7 @@ static void draw_osd(struct vo *vo, struct osd_state *osd)
|
|||||||
if (!priv->d3d_device)
|
if (!priv->d3d_device)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (vo_osd_changed(0)) {
|
if (vo_osd_has_changed()) {
|
||||||
struct draw_osd_closure ctx = { priv };
|
struct draw_osd_closure ctx = { priv };
|
||||||
|
|
||||||
/* clear the OSD */
|
/* clear the OSD */
|
||||||
|
@ -785,7 +785,7 @@ static void draw_osd(struct vo *vo, struct osd_state *osd)
|
|||||||
|
|
||||||
if (!p->use_osd)
|
if (!p->use_osd)
|
||||||
return;
|
return;
|
||||||
if (vo_osd_changed(0)) {
|
if (vo_osd_has_changed(osd)) {
|
||||||
int osd_h, osd_w;
|
int osd_h, osd_w;
|
||||||
clearOSD(vo);
|
clearOSD(vo);
|
||||||
osd_w = p->scaled_osd ? p->image_width : vo->dwidth;
|
osd_w = p->scaled_osd ? p->image_width : vo->dwidth;
|
||||||
|
@ -1439,7 +1439,7 @@ static void draw_osd(struct vo *vo, struct osd_state *osd)
|
|||||||
struct gl_priv *p = vo->priv;
|
struct gl_priv *p = vo->priv;
|
||||||
GL *gl = p->gl;
|
GL *gl = p->gl;
|
||||||
|
|
||||||
if (vo_osd_changed(0)) {
|
if (vo_osd_has_changed(osd)) {
|
||||||
clear_osd(p);
|
clear_osd(p);
|
||||||
osd_draw_text_ext(osd, vo->dwidth, vo->dheight, p->border_x,
|
osd_draw_text_ext(osd, vo->dwidth, vo->dheight, p->border_x,
|
||||||
p->border_y, p->border_x,
|
p->border_y, p->border_x,
|
||||||
|
18
mplayer.c
18
mplayer.c
@ -1457,10 +1457,7 @@ static void update_osd_msg(struct MPContext *mpctx)
|
|||||||
// Look if we have a msg
|
// Look if we have a msg
|
||||||
if ((msg = get_osd_msg(mpctx))) {
|
if ((msg = get_osd_msg(mpctx))) {
|
||||||
if (mpctx->sh_video && opts->term_osd != 1) {
|
if (mpctx->sh_video && opts->term_osd != 1) {
|
||||||
if (strcmp(osd->osd_text, msg->msg)) {
|
osd_set_text(osd, msg->msg);
|
||||||
osd_set_text(osd, msg->msg);
|
|
||||||
vo_osd_changed(OSDTYPE_OSD);
|
|
||||||
}
|
|
||||||
} else if (opts->term_osd) {
|
} else if (opts->term_osd) {
|
||||||
if (strcmp(mpctx->terminal_osd_text, msg->msg)) {
|
if (strcmp(mpctx->terminal_osd_text, msg->msg)) {
|
||||||
talloc_free(mpctx->terminal_osd_text);
|
talloc_free(mpctx->terminal_osd_text);
|
||||||
@ -1480,10 +1477,7 @@ static void update_osd_msg(struct MPContext *mpctx)
|
|||||||
if (opts->osd_level >= 2)
|
if (opts->osd_level >= 2)
|
||||||
sadd_osd_status(text, len, mpctx, opts->osd_level == 3);
|
sadd_osd_status(text, len, mpctx, opts->osd_level == 3);
|
||||||
|
|
||||||
if (strcmp(osd->osd_text, text)) {
|
osd_set_text(osd, text);
|
||||||
osd_set_text(osd, text);
|
|
||||||
vo_osd_changed(OSDTYPE_OSD);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3349,16 +3343,14 @@ static void run_playloop(struct MPContext *mpctx)
|
|||||||
if (sleeptime > 0) {
|
if (sleeptime > 0) {
|
||||||
if (!mpctx->sh_video)
|
if (!mpctx->sh_video)
|
||||||
goto novideo;
|
goto novideo;
|
||||||
int hack = vo_osd_changed(0);
|
if (vo_osd_has_changed(mpctx->osd) || mpctx->video_out->want_redraw)
|
||||||
vo_osd_changed(hack);
|
{
|
||||||
if (hack || mpctx->video_out->want_redraw) {
|
|
||||||
if (redraw_osd(mpctx) < 0) {
|
if (redraw_osd(mpctx) < 0) {
|
||||||
if (mpctx->paused && video_left)
|
if (mpctx->paused && video_left)
|
||||||
add_step_frame(mpctx);
|
add_step_frame(mpctx);
|
||||||
else
|
else
|
||||||
goto novideo;
|
goto novideo;
|
||||||
} else
|
}
|
||||||
vo_osd_changed(0);
|
|
||||||
} else {
|
} else {
|
||||||
novideo:
|
novideo:
|
||||||
mp_input_get_cmd(mpctx->input, sleeptime * 1000, true);
|
mp_input_get_cmd(mpctx->input, sleeptime * 1000, true);
|
||||||
|
28
sub/sub.c
28
sub/sub.c
@ -332,17 +332,20 @@ struct osd_state *osd_create(struct MPOpts *opts, struct ass_library *asslib)
|
|||||||
#endif
|
#endif
|
||||||
new_osd_obj(OSDTYPE_TELETEXT);
|
new_osd_obj(OSDTYPE_TELETEXT);
|
||||||
osd_font_invalidate();
|
osd_font_invalidate();
|
||||||
osd_set_text(osd, NULL);
|
osd->osd_text = talloc_strdup(osd, "");
|
||||||
osd_init_backend(osd);
|
osd_init_backend(osd);
|
||||||
return osd;
|
return osd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void osd_set_text(struct osd_state *osd, const char *text) {
|
void osd_set_text(struct osd_state *osd, const char *text)
|
||||||
talloc_free(osd->osd_text);
|
{
|
||||||
//osd->text must never be NULL
|
|
||||||
if (!text)
|
if (!text)
|
||||||
text = "";
|
text = "";
|
||||||
|
if (strcmp(osd->osd_text, text) == 0)
|
||||||
|
return;
|
||||||
|
talloc_free(osd->osd_text);
|
||||||
osd->osd_text = talloc_strdup(osd, text);
|
osd->osd_text = talloc_strdup(osd, text);
|
||||||
|
vo_osd_changed(OSDTYPE_OSD);
|
||||||
}
|
}
|
||||||
|
|
||||||
void osd_draw_text_ext(struct osd_state *osd, int dxs, int dys,
|
void osd_draw_text_ext(struct osd_state *osd, int dxs, int dys,
|
||||||
@ -390,20 +393,25 @@ void osd_draw_text(struct osd_state *osd, int dxs, int dys,
|
|||||||
osd_draw_text_ext(osd, dxs, dys, 0, 0, 0, 0, dxs, dys, draw_alpha, ctx);
|
osd_draw_text_ext(osd, dxs, dys, 0, 0, 0, 0, dxs, dys, draw_alpha, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vo_osd_changed_status = 0;
|
void vo_osd_changed(int new_value)
|
||||||
|
|
||||||
int vo_osd_changed(int new_value)
|
|
||||||
{
|
{
|
||||||
mp_osd_obj_t* obj=vo_osd_list;
|
mp_osd_obj_t* obj=vo_osd_list;
|
||||||
int ret = vo_osd_changed_status;
|
|
||||||
vo_osd_changed_status = new_value;
|
|
||||||
|
|
||||||
while(obj){
|
while(obj){
|
||||||
if(obj->type==new_value) obj->flags|=OSDFLAG_FORCE_UPDATE;
|
if(obj->type==new_value) obj->flags|=OSDFLAG_FORCE_UPDATE;
|
||||||
obj=obj->next;
|
obj=obj->next;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
bool vo_osd_has_changed(struct osd_state *osd)
|
||||||
|
{
|
||||||
|
mp_osd_obj_t* obj = vo_osd_list;
|
||||||
|
while (obj) {
|
||||||
|
if (obj->flags & OSDFLAG_FORCE_UPDATE)
|
||||||
|
return true;
|
||||||
|
obj = obj->next;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vo_osd_resized()
|
void vo_osd_resized()
|
||||||
|
@ -170,7 +170,8 @@ void osd_draw_text_ext(struct osd_state *osd, int dxs, int dys,
|
|||||||
struct osd_state *osd_create(struct MPOpts *opts, struct ass_library *asslib);
|
struct osd_state *osd_create(struct MPOpts *opts, struct ass_library *asslib);
|
||||||
void osd_set_text(struct osd_state *osd, const char *text);
|
void osd_set_text(struct osd_state *osd, const char *text);
|
||||||
int osd_update(struct osd_state *osd, int dxs, int dys);
|
int osd_update(struct osd_state *osd, int dxs, int dys);
|
||||||
int vo_osd_changed(int new_value);
|
void vo_osd_changed(int new_value);
|
||||||
|
bool vo_osd_has_changed(struct osd_state *osd);
|
||||||
void vo_osd_resized(void);
|
void vo_osd_resized(void);
|
||||||
int vo_osd_check_range_update(int,int,int,int);
|
int vo_osd_check_range_update(int,int,int,int);
|
||||||
void osd_free(struct osd_state *osd);
|
void osd_free(struct osd_state *osd);
|
||||||
|
Loading…
Reference in New Issue
Block a user