diff options
author | wm4 <wm4@nowhere> | 2020-04-26 23:34:32 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-04-26 23:34:32 +0200 |
commit | e9e883e3b2a64867aae014fb8a1416d0177fe493 (patch) | |
tree | 429e0cf14f9177f6488647967bb858338b201563 /sub/osd.h | |
parent | 640db1ed3fa0f15763439ae331d78d88cd932ee5 (diff) | |
download | mpv-e9e883e3b2a64867aae014fb8a1416d0177fe493.tar.bz2 mpv-e9e883e3b2a64867aae014fb8a1416d0177fe493.tar.xz |
video: make OSD/subtitle bitmaps refcounted (sort of)
Making OSD/subtitle bitmaps refcounted was planend a longer time ago,
e.g. the sub_bitmaps.packed field (which refcounts the subtitle bitmap
data) was added in 2016. But nothing benefited much from it, because
struct sub_bitmaps was usually stack allocated, and there was this weird
callback stuff through osd_draw().
Make it possible to get actually refcounted subtitle bitmaps on the OSD
API level. For this, we just copy all subtitle data other than the
bitmaps with sub_bitmaps_copy(). At first, I had planned some fancy
refcount shit, but when that was a big mess and hard to debug and just
boiled to emulating malloc(), I made it a full allocation+copy. This
affects mostly the parts array. With crazy ASS subtitles, this parts
array can get pretty big (thousands of elements or more), in which case
the extra alloc/copy could become performance relevant. But then again
this is just pure bullshit, and I see no need to care. In practice, this
extra work most likely gets drowned out by libass murdering a single
core (while mpv is waiting for it) anyway. So fuck it.
I just wanted this so draw_bmp.c requires only a single call to render
everything. VOs also can benefit from this, because the weird callback
shit isn't necessary anymore (simpler code), but I haven't done anything
about it yet. In general I'd hope this will work towards simplifying the
OSD layer, which is prerequisite for making actual further improvements.
I haven't tested some cases such as the "overlay-add" command. Maybe it
crashes now? Who knows, who cares.
In addition, it might be worthwhile to reduce the code duplication
between all the things that output subtitle bitmaps (with repacking,
image allocation, etc.), but that's orthogonal.
Diffstat (limited to 'sub/osd.h')
-rw-r--r-- | sub/osd.h | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -76,6 +76,15 @@ struct sub_bitmaps { int change_id; // Incremented on each change }; +struct sub_bitmap_list { + struct sub_bitmaps **items; + int num_items; +}; + +struct sub_bitmap_copy_cache; +struct sub_bitmaps *sub_bitmaps_copy(struct sub_bitmap_copy_cache **cache, + struct sub_bitmaps *in); + struct mp_osd_res { int w, h; // screen dimensions, including black borders int mt, mb, ml, mr; // borders (top, bottom, left, right) @@ -183,8 +192,12 @@ void osd_draw(struct osd_state *osd, struct mp_osd_res res, const bool formats[SUBBITMAP_COUNT], void (*cb)(void *ctx, struct sub_bitmaps *imgs), void *cb_ctx); +struct sub_bitmap_list *osd_render(struct osd_state *osd, struct mp_osd_res res, + double video_pts, int draw_flags, + const bool formats[SUBBITMAP_COUNT]); + struct mp_image; -bool osd_draw_on_image(struct osd_state *osd, struct mp_osd_res res, +void osd_draw_on_image(struct osd_state *osd, struct mp_osd_res res, double video_pts, int draw_flags, struct mp_image *dest); struct mp_image_pool; |