diff options
author | wm4 <wm4@nowhere> | 2020-05-11 19:51:32 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-05-11 19:57:34 +0200 |
commit | 55e1f15cdb9d73af56715ffe030a626697c1b917 (patch) | |
tree | b5c8a68ccbcc6fb0b4f7555f10d31ce1236196d0 /sub/draw_bmp.h | |
parent | 6db890ebab2839443ddbfc34a4a0246d464bd14f (diff) | |
download | mpv-55e1f15cdb9d73af56715ffe030a626697c1b917.tar.bz2 mpv-55e1f15cdb9d73af56715ffe030a626697c1b917.tar.xz |
draw_bmp: add a function to return a single-texture OSD overlay
Maybe this is useful for some of the lesser VOs. It's preferable over
bad ad-hoc solutions based on the more complex sub_bitmap data
structures (as observed e.g. in vo_vaapi.c), and does not use that much
more code since draw_bmp already created such an overlay internally.
But I still wanted something that avoids having to upload/render a full
screen-sized overlay if for example there's only a tiny subtitle line on
the bottom of the screen. So the new API can return a list of modified
pixels (for upload) and non-transparent pixels (for display). The way
these pixel rectangles are computed is a bit dumb and returns dumb
results, but it should be usable, and the implementation can change.
Diffstat (limited to 'sub/draw_bmp.h')
-rw-r--r-- | sub/draw_bmp.h | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/sub/draw_bmp.h b/sub/draw_bmp.h index 6833d42cf7..d54a1c7685 100644 --- a/sub/draw_bmp.h +++ b/sub/draw_bmp.h @@ -3,12 +3,53 @@ #include "osd.h" +struct mp_rect; struct mp_image; struct mp_draw_sub_cache; -bool mp_draw_sub_bitmaps(struct mp_draw_sub_cache **cache, struct mp_image *dst, + +struct mp_draw_sub_cache *mp_draw_sub_alloc(void *ta_parent); + +// Render the sub-bitmaps in sbs_list to dst. sbs_list must have been rendered +// for an OSD resolution equivalent to dst's size (UB if not). +// Warning: if dst is a format with alpha, and dst is not set to MP_ALPHA_PREMUL +// (not done by default), this will be extremely slow. +// Warning: the caller is responsible for ensuring that dst is writable. +// cache: allocated instance; caches non-changing OSD parts etc. +// dst: image to draw to +// sbs_list: source sub-bitmaps +// returns: success +bool mp_draw_sub_bitmaps(struct mp_draw_sub_cache *cache, struct mp_image *dst, struct sub_bitmap_list *sbs_list); + char *mp_draw_sub_get_dbg_info(struct mp_draw_sub_cache *c); +// Return a RGBA overlay with subtitles. The returned image uses IMGFMT_BGRA and +// premultiplied alpha, and the size specified by sbs_list.w/h. +// This can return a list of active (act_) and modified (mod_) rectangles. +// Active rectangles are regions that contain visible OSD pixels. Modified +// rectangles are regions that were changed since the last call. This function +// always makes the act region a subset of the mod region. Rectangles within a +// list never overlap with rectangles within the same list. +// If the user-provided lists are too small (max_*_rcs too small), multiple +// rectangles are merged until they fit in the list. +// You can pass max_act_rcs=0, which implies you render the whole overlay. +// cache: allocated instance; keeps track of changed regions +// sbs_list: source sub-bitmaps +// act_rcs: caller allocated list of non-transparent rectangles +// max_act_rcs: number of allocated items in act_rcs +// num_act_rcs: set to the number of valid items in act_rcs +// mod_rcs, max_mod_rcs, num_mod_rcs: modified rectangles +// returns: internal OSD overlay owned by cache, NULL on error +// read only, valid until the next call on cache +struct mp_image *mp_draw_sub_overlay(struct mp_draw_sub_cache *cache, + struct sub_bitmap_list *sbs_list, + struct mp_rect *act_rcs, + int max_act_rcs, + int *num_act_rcs, + struct mp_rect *mod_rcs, + int max_mod_rcs, + int *num_mod_rcs); + extern const bool mp_draw_sub_formats[SUBBITMAP_COUNT]; #endif /* MPLAYER_DRAW_BMP_H */ |