osd: slightly simplify update logic

Remove the per-part force_redraw flags, and instead make the difference
between flagging dirty state and returning it to the player frontend
more explicit. The big issue is that 1. the OSD needs to know the dirty
state, and it should be cleared strictly when it is re-rendered
(force_redraw flag), and 2. the player core needs to be notified once,
and the notification must be reset (want_redraw flag).

The call in loadfile.c is replaced by making osd_set_sub() set the
change flag. Increasing the change flag on dirty state (the force_redraw
check in render_object()) should not be needed, because OSD part
renderers set it correctly (at least now).

Doing this just because someone pointed this out.
This commit is contained in:
wm4 2016-09-15 14:22:48 +02:00
parent 5968a307d5
commit 9c9cf125ad
6 changed files with 21 additions and 30 deletions

View File

@ -2911,7 +2911,7 @@ static int property_osd_helper(void *ctx, struct m_property *prop,
{
MPContext *mpctx = ctx;
if (action == M_PROPERTY_SET)
osd_changed_all(mpctx->osd);
osd_changed(mpctx->osd);
return mp_property_generic_option(mpctx, prop, action, arg);
}
@ -4909,7 +4909,7 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
if (sub_control(sub, SD_CTRL_SUB_STEP, a) > 0) {
if (cmd->id == MP_CMD_SUB_STEP) {
opts->sub_delay -= a[0];
osd_changed_all(mpctx->osd);
osd_changed(mpctx->osd);
show_property_osd(mpctx, "sub-delay", on_osd);
} else {
// We can easily get stuck by failing to seek to the video

View File

@ -473,7 +473,6 @@ void mp_switch_track_n(struct MPContext *mpctx, int order, enum stream_type type
}
mp_notify(mpctx, MPV_EVENT_TRACK_SWITCHED, NULL);
osd_changed_all(mpctx->osd);
talloc_free(mpctx->track_layout_hash);
mpctx->track_layout_hash = talloc_steal(mpctx, track_layout_hash(mpctx));

View File

@ -146,10 +146,10 @@ void osd_free(struct osd_state *osd)
talloc_free(osd);
}
void osd_changed_unlocked(struct osd_state *osd, int obj)
void osd_changed_unlocked(struct osd_state *osd)
{
osd->objs[obj]->force_redraw = true;
osd->want_redraw = true;
osd->want_redraw_notification = true;
}
void osd_set_text(struct osd_state *osd, const char *text)
@ -161,7 +161,7 @@ void osd_set_text(struct osd_state *osd, const char *text)
if (strcmp(osd_obj->text, text) != 0) {
talloc_free(osd_obj->text);
osd_obj->text = talloc_strdup(osd_obj, text);
osd_changed_unlocked(osd, osd_obj->type);
osd_changed_unlocked(osd);
}
pthread_mutex_unlock(&osd->lock);
}
@ -171,6 +171,7 @@ void osd_set_sub(struct osd_state *osd, int index, struct dec_sub *dec_sub)
pthread_mutex_lock(&osd->lock);
if (index >= 0 && index < 2)
osd->objs[OSDTYPE_SUB + index]->sub = dec_sub;
osd_changed_unlocked(osd);
pthread_mutex_unlock(&osd->lock);
}
@ -199,7 +200,7 @@ void osd_set_progbar(struct osd_state *osd, struct osd_progbar_state *s)
MP_TARRAY_GROW(osd_obj, osd_obj->progbar_state.stops, s->num_stops);
memcpy(osd_obj->progbar_state.stops, s->stops,
sizeof(osd_obj->progbar_state.stops[0]) * s->num_stops);
osd_changed_unlocked(osd, osd_obj->type);
osd_changed_unlocked(osd);
pthread_mutex_unlock(&osd->lock);
}
@ -207,7 +208,7 @@ void osd_set_external2(struct osd_state *osd, struct sub_bitmaps *imgs)
{
pthread_mutex_lock(&osd->lock);
osd->objs[OSDTYPE_EXTERNAL2]->external2 = imgs;
osd_changed_unlocked(osd, OSDTYPE_EXTERNAL2);
osd_changed_unlocked(osd);
pthread_mutex_unlock(&osd->lock);
}
@ -216,7 +217,7 @@ static void check_obj_resize(struct osd_state *osd, struct mp_osd_res res,
{
if (!osd_res_equals(res, obj->vo_res)) {
obj->vo_res = res;
obj->force_redraw = true;
osd->want_redraw = true;
mp_client_broadcast_event(mp_client_api_get_core(osd->global->client_api),
MP_EVENT_WIN_RESIZE, NULL);
}
@ -269,10 +270,6 @@ static void render_object(struct osd_state *osd, struct osd_object *obj,
osd_object_get_bitmaps(osd, obj, format, out_imgs);
}
if (obj->force_redraw)
out_imgs->change_id++;
obj->force_redraw = false;
obj->vo_change_id += out_imgs->change_id;
if (out_imgs->num_parts == 0)
@ -323,6 +320,9 @@ void osd_draw(struct osd_state *osd, struct mp_osd_res res,
sub_unlock(obj->sub);
}
if (!(draw_flags & OSD_DRAW_SUB_FILTER))
osd->want_redraw = osd->want_redraw_notification = false;
pthread_mutex_unlock(&osd->lock);
}
@ -379,24 +379,18 @@ struct mp_osd_res osd_res_from_image_params(const struct mp_image_params *p)
};
}
void osd_changed(struct osd_state *osd, int new_value)
void osd_changed(struct osd_state *osd)
{
pthread_mutex_lock(&osd->lock);
osd_changed_unlocked(osd, new_value);
osd_changed_unlocked(osd);
pthread_mutex_unlock(&osd->lock);
}
void osd_changed_all(struct osd_state *osd)
{
for (int n = 0; n < MAX_OSD_PARTS; n++)
osd_changed(osd, n);
}
bool osd_query_and_reset_want_redraw(struct osd_state *osd)
{
pthread_mutex_lock(&osd->lock);
bool r = osd->want_redraw;
osd->want_redraw = false;
bool r = osd->want_redraw_notification;
osd->want_redraw_notification = false;
pthread_mutex_unlock(&osd->lock);
return r;
}

View File

@ -145,8 +145,7 @@ struct mpv_global;
struct dec_sub;
struct osd_state *osd_create(struct mpv_global *global);
void osd_changed(struct osd_state *osd, int new_value);
void osd_changed_all(struct osd_state *osd);
void osd_changed(struct osd_state *osd);
void osd_free(struct osd_state *osd);
bool osd_query_and_reset_want_redraw(struct osd_state *osd);

View File

@ -501,7 +501,7 @@ void osd_set_external(struct osd_state *osd, void *id, int res_x, int res_y,
entry->res_y = res_y;
update_external(osd, obj, entry);
obj->changed = true;
osd_changed_unlocked(osd, obj->type);
osd_changed_unlocked(osd);
}
done:
@ -527,7 +527,7 @@ static void append_ass(struct ass_state *ass, struct mp_osd_res *res,
void osd_object_get_bitmaps(struct osd_state *osd, struct osd_object *obj,
int format, struct sub_bitmaps *out_imgs)
{
if (obj->force_redraw && obj->type == OSDTYPE_OSD)
if (osd->want_redraw && obj->type == OSDTYPE_OSD)
update_osd(osd, obj);
if (!obj->ass_packer)

View File

@ -28,8 +28,6 @@ struct osd_object {
int type; // OSDTYPE_*
bool is_sub;
bool force_redraw;
// OSDTYPE_OSD
char *text;
@ -72,6 +70,7 @@ struct osd_state {
bool render_subs_in_filter;
bool want_redraw;
bool want_redraw_notification;
struct MPOpts *opts;
struct mpv_global *global;
@ -80,6 +79,6 @@ struct osd_state {
struct mp_draw_sub_cache *draw_cache;
};
void osd_changed_unlocked(struct osd_state *osd, int obj);
void osd_changed_unlocked(struct osd_state *osd);
#endif