31# define PRINT(format, args...) printf(format, ##args)
33# define PRINT(format, ...) printf(__VA_ARGS__)
36# define PRINT(format, ...)
114 PRINT(
"%s: cache '%s' free item %p buffer %p\n", __func__, cache->
name, item, item->
ibuf);
153 bool remove = !item->
ibuf;
156 PRINT(
"%s: cache '%s' remove item %p without buffer\n", __func__, cache->
name, item);
167 const int *a =
static_cast<int *
>(
const_cast<void *
>(av));
168 const int *
b =
static_cast<int *
>(
const_cast<void *
>(bv));
181 PRINT(
"%s: cache '%s' destroy item %p buffer %p\n", __func__, cache->
name, item, item->
ibuf);
185 item->
ibuf =
nullptr;
188 MEM_SAFE_DELETE(cache->
points);
221 PRINT(
"%s: cache '%s' item %p use default priority %d\n",
227 return default_priority;
232 PRINT(
"%s: cache '%s' item %p priority %d\n", __func__, cache->
name, item, priority);
240 if (item->
ibuf ==
nullptr) {
274 PRINT(
"%s: cache '%s' create\n", __func__, name);
288 cache->
cmpfp = cmpfp;
320 if (ibuf !=
nullptr) {
331 PRINT(
"%s: cache '%s' put %p, item %p\n", __func__, cache->
name, ibuf, item);
366 MEM_SAFE_DELETE(cache->
points);
376 size_t mem_in_use, mem_limit, elem_size;
385 if (mem_in_use + elem_size <= mem_limit) {
412 if (r_is_cached_empty) {
413 *r_is_cached_empty =
false;
427 *r_is_cached_empty =
true;
443 return item !=
nullptr;
448 PRINT(
"%s: cache '%s' free\n", __func__, cache->
name);
457 MEM_delete(cache->
points);
468 bool(cleanup_check_cb)(
ImBuf *ibuf,
void *userkey,
void *userdata),
483 if (cleanup_check_cb(item->
ibuf, key->
userkey, userdata)) {
484 PRINT(
"%s: cache '%s' remove item %p\n", __func__, cache->
name, item);
492 ImBufCache *cache,
int proxy,
int render_flags,
int *r_totseg,
int **r_points)
502 MEM_SAFE_DELETE(cache->
points);
506 *r_totseg = cache->
totseg;
507 *r_points = cache->
points;
519 int framenr, curproxy, curflags;
524 if (curproxy == proxy && curflags == render_flags) {
525 frames[a++] = framenr;
533 for (a = 0; a < totframe; a++) {
534 if (a && frames[a] - frames[a - 1] != 1) {
538 if (a == totframe - 1) {
549 for (a = 0,
b = 0; a < totframe; a++) {
551 points[
b++] = frames[a];
554 if (a && frames[a] - frames[a - 1] != 1) {
555 points[
b++] = frames[a - 1];
556 points[
b++] = frames[a];
559 if (a == totframe - 1) {
560 points[
b++] = frames[a];
569 cache->
proxy = proxy;
584 return reinterpret_cast<ImBufCacheIter *
>(iter);
#define GHASH_ITER(gh_iter_, ghash_)
void MEM_CacheLimiter_ItemPriority_Func_set(MEM_CacheLimiterC *This, MEM_CacheLimiter_ItemPriority_Func item_priority_func)
void MEM_CacheLimiter_enforce_limits(MEM_CacheLimiterC *This)
void MEM_CacheLimiter_touch(MEM_CacheLimiterHandleC *handle)
void MEM_CacheLimiter_unref(MEM_CacheLimiterHandleC *handle)
void delete_MEM_CacheLimiter(MEM_CacheLimiterC *This)
void MEM_CacheLimiter_ItemDestroyable_Func_set(MEM_CacheLimiterC *This, MEM_CacheLimiter_ItemDestroyable_Func item_destroyable_func)
size_t MEM_CacheLimiter_get_memory_in_use(MEM_CacheLimiterC *This)
size_t MEM_CacheLimiter_get_maximum()
MEM_CacheLimiterC * new_MEM_CacheLimiter(MEM_CacheLimiter_Destruct_Func data_destructor, MEM_CacheLimiter_DataSize_Func data_size)
MEM_CacheLimiterHandleC * MEM_CacheLimiter_insert(MEM_CacheLimiterC *This, void *data)
void MEM_CacheLimiter_ref(MEM_CacheLimiterHandleC *handle)
void MEM_CacheLimiter_unmanage(MEM_CacheLimiterHandleC *handle)
struct MEM_CacheLimiter_s MEM_CacheLimiterC
struct MEM_CacheLimiterHandle_s MEM_CacheLimiterHandleC
Read Blender memory allocation and freeing.
#define PRINT(format,...)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void IMB_cacheIter_step(ImBufCacheIter *iter)
void * IMB_cacheIter_getUserKey(ImBufCacheIter *iter)
static size_t get_size_in_memory(ImBuf *ibuf)
BLI_INLINE void * BLI_ghashIterator_getKey(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
char * STRNCPY(char(&dst)[N], const char *src)
static int get_item_priority(void *item_v, int default_priority)
void IMB_cache_get_cache_segments(ImBufCache *cache, int proxy, int render_flags, int *r_totseg, int **r_points)
unsigned int(*) GHashHashFP(const void *key)
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
void IMB_cache_free(ImBufCache *cache)
static uint imbufcache_hashhash(const void *keyv)
static void check_unused_keys(ImBufCache *cache)
static std::recursive_mutex limitor_lock
ImBuf * IMB_cacheIter_getImBuf(ImBufCacheIter *iter)
void IMB_refImBuf(ImBuf *ibuf)
ImBufCache * IMB_cache_create(const char *name, int keysize, GHashHashFP hashfp, GHashCmpFP cmpfp)
void IMB_cache_put(ImBufCache *cache, void *userkey, ImBuf *ibuf)
void MEM_delete_void(void *vmemh)
void(*)(void *priority_data) ImBufCachePriorityDeleterFP
size_t IMB_get_size_in_memory(const ImBuf *ibuf)
ImBuf * IMB_cache_get(ImBufCache *cache, void *userkey, bool *r_is_cached_empty)
bool(*) GHashCmpFP(const void *a, const void *b)
void BLI_mempool_free(BLI_mempool *pool, void *addr) ATTR_NONNULL(1
BLI_INLINE void * BLI_ghashIterator_getValue(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
static void imbufcache_keyfree(void *val)
void IMB_cache_cleanup(ImBufCache *cache, bool(cleanup_check_cb)(ImBuf *ibuf, void *userkey, void *userdata), void *userdata)
static int compare_int(const void *av, const void *bv)
void BLI_mempool_destroy(BLI_mempool *pool) ATTR_NONNULL(1)
void BLI_ghashIterator_step(GHashIterator *ghi)
void IMB_freeImBuf(ImBuf *ibuf)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
ImBufCacheIter * IMB_cacheIter_new(ImBufCache *cache)
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
BLI_mempool * BLI_mempool_create(unsigned int esize, unsigned int elem_num, unsigned int pchunk, unsigned int flag) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
void *(*)(void *userkey) ImBufCacheGetPriorityDataFP
static bool get_item_destroyable(void *item_v)
static void do_imbufcache_put(ImBufCache *cache, void *userkey, ImBuf *ibuf, bool need_lock)
static void imbufcache_valfree(void *val)
unsigned int BLI_ghash_len(const GHash *gh) ATTR_WARN_UNUSED_RESULT
bool IMB_cacheIter_done(ImBufCacheIter *iter)
void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh)
static void imbufcache_destructor(void *p)
int(*)(void *last_userkey, void *priority_data) ImBufCacheGetItemPriorityFP
void IMB_cache_set_priority_callback(ImBufCache *cache, ImBufCacheGetPriorityDataFP getprioritydatafp, ImBufCacheGetItemPriorityFP getitempriorityfp, ImBufCachePriorityDeleterFP prioritydeleterfp)
bool IMB_cache_has_frame(ImBufCache *cache, void *userkey)
void IMB_cache_set_getdata_callback(ImBufCache *cache, ImBufCacheGetKeyDataFP getdatafp)
static size_t get_item_size(void *p)
bool IMB_cache_put_if_possible(ImBufCache *cache, void *userkey, ImBuf *ibuf)
void IMB_cache_destruct()
GHashIterator * BLI_ghashIterator_new(GHash *gh) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
bool BLI_ghash_remove(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
static bool imbufcache_hashcmp(const void *av, const void *bv)
void(*)(void *userkey, int *framenr, int *proxy, int *render_flags) ImBufCacheGetKeyDataFP
void * BLI_mempool_alloc(BLI_mempool *pool) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1)
GHash * BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void IMB_cache_remove(ImBufCache *cache, void *userkey)
BLI_INLINE bool BLI_ghashIterator_done(const GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
bool BLI_ghash_reinsert(GHash *gh, void *key, void *val, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
void IMB_cacheIter_free(ImBufCacheIter *iter)
static MEM_CacheLimiterC * limitor
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BLI_ghashIterator_free(GHashIterator *ghi)
MEM_CacheLimiterHandleC * c_handle
ImBufCachePriorityDeleterFP prioritydeleterfp
ImBufCacheGetKeyDataFP getdatafp
ImBufCacheGetItemPriorityFP getitempriorityfp
ImBufCacheGetPriorityDataFP getprioritydatafp
BLI_mempool * userkeys_pool