summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/screenshot.c2
-rw-r--r--sub/sub.c21
-rw-r--r--sub/sub.h5
-rw-r--r--video/filter/vf_sub.c8
-rw-r--r--video/out/vo_lavc.c1
5 files changed, 29 insertions, 8 deletions
diff --git a/core/screenshot.c b/core/screenshot.c
index 0f397f2dd7..ae259fcbc0 100644
--- a/core/screenshot.c
+++ b/core/screenshot.c
@@ -235,8 +235,6 @@ static char *gen_fname(screenshot_ctx *ctx, const char *file_ext)
static void add_subs(struct MPContext *mpctx, struct mp_image *image)
{
- mp_image_make_writeable(image);
-
int d_w = image->display_w ? image->display_w : image->w;
int d_h = image->display_h ? image->display_h : image->h;
diff --git a/sub/sub.c b/sub/sub.c
index 1365d3c844..4baf4f1487 100644
--- a/sub/sub.c
+++ b/sub/sub.c
@@ -39,6 +39,8 @@
#include "draw_bmp.h"
#include "spudec.h"
#include "subreader.h"
+#include "video/mp_image.h"
+#include "video/mp_image_pool.h"
char * const sub_osd_names[]={
@@ -274,6 +276,7 @@ struct draw_on_image_closure {
struct osd_state *osd;
struct mp_image *dest;
struct mp_draw_sub_backup *bk;
+ struct mp_image_pool *pool;
bool changed;
};
@@ -283,11 +286,17 @@ static void draw_on_image(void *ctx, struct sub_bitmaps *imgs)
struct osd_state *osd = closure->osd;
if (closure->bk)
mp_draw_sub_backup_add(closure->bk, closure->dest, imgs);
+ if (closure->pool) {
+ mp_image_pool_make_writeable(closure->pool, closure->dest);
+ } else {
+ mp_image_make_writeable(closure->dest);
+ }
mp_draw_sub_bitmaps(&osd->draw_cache, closure->dest, imgs);
talloc_steal(osd, osd->draw_cache);
closure->changed = true;
}
+// Calls mp_image_make_writeable() on the dest image if something is drawn.
// Returns whether anything was drawn.
bool osd_draw_on_image(struct osd_state *osd, struct mp_osd_res res,
double video_pts, int draw_flags, struct mp_image *dest)
@@ -298,6 +307,18 @@ bool osd_draw_on_image(struct osd_state *osd, struct mp_osd_res res,
return closure.changed;
}
+// Like osd_draw_on_image(), but if dest needs to be copied to make it
+// writeable, allocate images from the given pool. (This is a minor
+// optimization to reduce "real" image sized memory allocations.)
+void osd_draw_on_image_p(struct osd_state *osd, struct mp_osd_res res,
+ double video_pts, int draw_flags,
+ struct mp_image_pool *pool, struct mp_image *dest)
+{
+ struct draw_on_image_closure closure = {osd, dest, .pool = pool};
+ osd_draw(osd, res, video_pts, draw_flags, mp_draw_sub_formats,
+ &draw_on_image, &closure);
+}
+
void osd_draw_on_image_bk(struct osd_state *osd, struct mp_osd_res res,
double video_pts, int draw_flags,
struct mp_draw_sub_backup *bk, struct mp_image *dest)
diff --git a/sub/sub.h b/sub/sub.h
index ed4401cacf..38b7b29f34 100644
--- a/sub/sub.h
+++ b/sub/sub.h
@@ -222,6 +222,11 @@ struct mp_image;
bool 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;
+void osd_draw_on_image_p(struct osd_state *osd, struct mp_osd_res res,
+ double video_pts, int draw_flags,
+ struct mp_image_pool *pool, struct mp_image *dest);
+
struct mp_draw_sub_backup;
void osd_draw_on_image_bk(struct osd_state *osd, struct mp_osd_res res,
double video_pts, int draw_flags,
diff --git a/video/filter/vf_sub.c b/video/filter/vf_sub.c
index 8cda9f5e79..c9d22995c1 100644
--- a/video/filter/vf_sub.c
+++ b/video/filter/vf_sub.c
@@ -155,9 +155,7 @@ static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi)
struct vf_priv_s *priv = vf->priv;
struct osd_state *osd = priv->osd;
- if (vf->priv->opt_top_margin || vf->priv->opt_bottom_margin ||
- !mp_image_is_writeable(mpi))
- {
+ if (vf->priv->opt_top_margin || vf->priv->opt_bottom_margin) {
struct mp_image *dmpi = vf_alloc_out_image(vf);
mp_image_copy_attributes(dmpi, mpi);
prepare_image(vf, dmpi, mpi);
@@ -167,8 +165,8 @@ static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi)
mp_image_set_colorspace_details(mpi, &priv->csp);
- if (mpi->pts != MP_NOPTS_VALUE)
- osd_draw_on_image(osd, priv->dim, mpi->pts, OSD_DRAW_SUB_FILTER, mpi);
+ osd_draw_on_image_p(osd, priv->dim, mpi->pts, OSD_DRAW_SUB_FILTER,
+ vf->out_pool, mpi);
return mpi;
}
diff --git a/video/out/vo_lavc.c b/video/out/vo_lavc.c
index 35041c7f63..2aced9351a 100644
--- a/video/out/vo_lavc.c
+++ b/video/out/vo_lavc.c
@@ -487,7 +487,6 @@ static void draw_osd(struct vo *vo, struct osd_state *osd)
};
mp_image_set_colorspace_details(vc->lastimg, &vc->colorspace);
- mp_image_make_writeable(vc->lastimg);
osd_draw_on_image(osd, dim, osd->vo_pts, OSD_DRAW_SUB_ONLY, vc->lastimg);
}