summaryrefslogtreecommitdiffstats
path: root/sub
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-09-15 14:22:48 +0200
committerwm4 <wm4@nowhere>2016-09-15 14:50:38 +0200
commit9c9cf125ad71aeff7fe6979b7b5d1f44f2d1a6ac (patch)
treeb9e03cb03c32950fd4d2436f755ffea1c368b4ce /sub
parent5968a307d5c05d1b4604be4fddd416b0aecb534e (diff)
downloadmpv-9c9cf125ad71aeff7fe6979b7b5d1f44f2d1a6ac.tar.bz2
mpv-9c9cf125ad71aeff7fe6979b7b5d1f44f2d1a6ac.tar.xz
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.
Diffstat (limited to 'sub')
-rw-r--r--sub/osd.c34
-rw-r--r--sub/osd.h3
-rw-r--r--sub/osd_libass.c4
-rw-r--r--sub/osd_state.h5
4 files changed, 19 insertions, 27 deletions
diff --git a/sub/osd.c b/sub/osd.c
index 381fa8892d..220c1d9c0d 100644
--- a/sub/osd.c
+++ b/sub/osd.c
@@ -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;
}
diff --git a/sub/osd.h b/sub/osd.h
index 6bfa6dd525..cf66392904 100644
--- a/sub/osd.h
+++ b/sub/osd.h
@@ -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);
diff --git a/sub/osd_libass.c b/sub/osd_libass.c
index a9ab7eabd2..9b634f5214 100644
--- a/sub/osd_libass.c
+++ b/sub/osd_libass.c
@@ -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)
diff --git a/sub/osd_state.h b/sub/osd_state.h
index 81bdbd633a..d054f3d06d 100644
--- a/sub/osd_state.h
+++ b/sub/osd_state.h
@@ -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