summaryrefslogtreecommitdiffstats
path: root/video/mp_image_pool.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-01-12 01:40:01 +0100
committerKevin Mitchell <kevmitch@gmail.com>2018-01-13 03:26:45 -0800
commit83ab873497e8b295d32ee364ef64c4533db5a048 (patch)
tree1185a249ac7c49d8b5859830c98b25abae6a63ae /video/mp_image_pool.c
parentd53c0604ca796020e5ac26f08c0d6fd0c8201718 (diff)
downloadmpv-83ab873497e8b295d32ee364ef64c4533db5a048.tar.bz2
mpv-83ab873497e8b295d32ee364ef64c4533db5a048.tar.xz
video: change some mp_image_pool semantics
Remove the max_count creation parameter, because it's pointless and rarely ever did anything. Add a talloc parent parameter instead (which is something completely different, but convenient, and all callers needs to be changed anyway). Instead of clearing the pool when the now removed maximum is reached, clear it on image parameter changes instead.
Diffstat (limited to 'video/mp_image_pool.c')
-rw-r--r--video/mp_image_pool.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/video/mp_image_pool.c b/video/mp_image_pool.c
index 809b4f3352..c526772981 100644
--- a/video/mp_image_pool.c
+++ b/video/mp_image_pool.c
@@ -43,11 +43,11 @@ static pthread_mutex_t pool_mutex = PTHREAD_MUTEX_INITIALIZER;
// destructors are thread-safe.)
struct mp_image_pool {
- int max_count;
-
struct mp_image **images;
int num_images;
+ int fmt, w, h;
+
mp_image_allocator allocator;
void *allocator_ctx;
@@ -70,13 +70,12 @@ static void image_pool_destructor(void *ptr)
mp_image_pool_clear(pool);
}
-struct mp_image_pool *mp_image_pool_new(int max_count)
+// If tparent!=NULL, set it as talloc parent for the pool.
+struct mp_image_pool *mp_image_pool_new(void *tparent)
{
- struct mp_image_pool *pool = talloc_ptrtype(NULL, pool);
+ struct mp_image_pool *pool = talloc_ptrtype(tparent, pool);
talloc_set_destructor(pool, image_pool_destructor);
- *pool = (struct mp_image_pool) {
- .max_count = max_count,
- };
+ *pool = (struct mp_image_pool) {0};
return pool;
}
@@ -188,8 +187,11 @@ struct mp_image *mp_image_pool_get(struct mp_image_pool *pool, int fmt,
return mp_image_alloc(fmt, w, h);
struct mp_image *new = mp_image_pool_get_no_alloc(pool, fmt, w, h);
if (!new) {
- if (pool->num_images >= pool->max_count)
+ if (fmt != pool->fmt || w != pool->w || h != pool->h)
mp_image_pool_clear(pool);
+ pool->fmt = fmt;
+ pool->w = w;
+ pool->h = h;
if (pool->allocator) {
new = pool->allocator(pool->allocator_ctx, fmt, w, h);
} else {