diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-10-24 21:12:28 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-10-24 21:12:28 +0400 |
commit | 3cbadbf895f4775290d626bed00e97f997b8a962 (patch) | |
tree | 6c7bf02b67120dd96074e0d80e137481b2c30d1c /source/blender/imbuf/intern | |
parent | 8afc509be42c6422b1600d9dab133a8d5b025aad (diff) |
MovieCache implementation
Implementation of cache for general movie-related areas
such as sequencer and clip editor (in the future)
Some changes in limiter were necessary:
- Limiter counted mapped memory twice when was checking how many memory is used.
- It was using "global" memory usage not memory usage by cached elements.
It will cause big problems when there's large mesh or plenty of undo steps are
in memory nothing would be cached in sequencer.
- To solve this problem introduced "callback" to measure cached element size.
It could be not very accurate in general, but it works well for image buffers.
And if this callback isn't set old-school memory usage check would be used.
- The whole cache used to get freed when memory limit exceeded, now it'll drop only
as much elements as necessary to reduce memory usage.
Seqcache is switched to use this new cache code.
Diffstat (limited to 'source/blender/imbuf/intern')
-rw-r--r-- | source/blender/imbuf/intern/allocimbuf.c | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c index 1d82c862dbd..da08671341a 100644 --- a/source/blender/imbuf/intern/allocimbuf.c +++ b/source/blender/imbuf/intern/allocimbuf.c @@ -164,9 +164,8 @@ void IMB_freeImBuf(ImBuf *ibuf) IMB_freezbufImBuf(ibuf); IMB_freezbuffloatImBuf(ibuf); freeencodedbufferImBuf(ibuf); + IMB_cache_limiter_unmanage(ibuf); IMB_metadata_free(ibuf); - if (ibuf->dds_data.data != NULL) - free(ibuf->dds_data.data); MEM_freeN(ibuf); } } @@ -472,3 +471,56 @@ static MEM_CacheLimiterC **get_imbuf_cache_limiter(void) return &c; } + +void IMB_free_cache_limiter(void) +{ + delete_MEM_CacheLimiter(*get_imbuf_cache_limiter()); + *get_imbuf_cache_limiter() = NULL; +} + +void IMB_cache_limiter_insert(ImBuf *i) +{ + if(!i->c_handle) { + i->c_handle = MEM_CacheLimiter_insert( + *get_imbuf_cache_limiter(), i); + MEM_CacheLimiter_ref(i->c_handle); + MEM_CacheLimiter_enforce_limits( + *get_imbuf_cache_limiter()); + MEM_CacheLimiter_unref(i->c_handle); + } +} + +void IMB_cache_limiter_unmanage(ImBuf *i) +{ + if(i->c_handle) { + MEM_CacheLimiter_unmanage(i->c_handle); + i->c_handle = NULL; + } +} + +void IMB_cache_limiter_touch(ImBuf *i) +{ + if(i->c_handle) + MEM_CacheLimiter_touch(i->c_handle); +} + +void IMB_cache_limiter_ref(ImBuf *i) +{ + if(i->c_handle) + MEM_CacheLimiter_ref(i->c_handle); +} + +void IMB_cache_limiter_unref(ImBuf *i) +{ + if(i->c_handle) + MEM_CacheLimiter_unref(i->c_handle); +} + +int IMB_cache_limiter_get_refcount(ImBuf *i) +{ + if(i->c_handle) + return MEM_CacheLimiter_get_refcount(i->c_handle); + + return 0; +} + |