Image cache rewrite to using generic movie cache
[blender.git] / source / blender / imbuf / intern / moviecache.c
index 90eea438c5e9bcb52cd86cb9fed0eb532f2e40cc..c287cf4c005623c82fb33b3f554528b2a95bfe38 100644 (file)
@@ -443,23 +443,18 @@ void IMB_moviecache_free(MovieCache *cache)
        MEM_freeN(cache);
 }
 
-void IMB_moviecache_cleanup(MovieCache *cache, int (cleanup_check_cb) (void *userkey, void *userdata), void *userdata)
+void IMB_moviecache_cleanup(MovieCache *cache, bool (cleanup_check_cb) (ImBuf *ibuf, void *userkey, void *userdata), void *userdata)
 {
        GHashIterator *iter;
 
        iter = BLI_ghashIterator_new(cache->hash);
        while (!BLI_ghashIterator_done(iter)) {
                MovieCacheKey *key = BLI_ghashIterator_getKey(iter);
-               int remove;
+               MovieCacheItem *item = BLI_ghashIterator_getValue(iter);
 
                BLI_ghashIterator_step(iter);
 
-               remove = cleanup_check_cb(key->userkey, userdata);
-
-               if (remove) {
-                       MovieCacheItem *item = BLI_ghashIterator_getValue(iter);
-                       (void) item;  /* silence unused variable when not using debug */
-
+               if (cleanup_check_cb(item->ibuf, key->userkey, userdata)) {
                        PRINT("%s: cache '%s' remove item %p\n", __func__, cache->name, item);
 
                        BLI_ghash_remove(cache->hash, key, moviecache_keyfree, moviecache_valfree);
@@ -556,3 +551,36 @@ void IMB_moviecache_get_cache_segments(MovieCache *cache, int proxy, int render_
                MEM_freeN(frames);
        }
 }
+
+struct MovieCacheIter *IMB_moviecacheIter_new(MovieCache *cache)
+{
+       GHashIterator *iter = BLI_ghashIterator_new(cache->hash);
+       return (struct MovieCacheIter *) iter;
+}
+
+void IMB_moviecacheIter_free(struct MovieCacheIter *iter)
+{
+       BLI_ghashIterator_free((GHashIterator *) iter);
+}
+
+bool IMB_moviecacheIter_done(struct MovieCacheIter *iter)
+{
+       return BLI_ghashIterator_done((GHashIterator *) iter);
+}
+
+void IMB_moviecacheIter_step(struct MovieCacheIter *iter)
+{
+       BLI_ghashIterator_step((GHashIterator *) iter);
+}
+
+ImBuf *IMB_moviecacheIter_getImBuf(struct MovieCacheIter *iter)
+{
+       MovieCacheItem *item = BLI_ghashIterator_getValue((GHashIterator *) iter);
+       return item->ibuf;
+}
+
+void *IMB_moviecacheIter_getUserKey(struct MovieCacheIter *iter)
+{
+       MovieCacheKey *key = BLI_ghashIterator_getKey((GHashIterator *) iter);
+       return key->userkey;
+}