Changeset View
Changeset View
Standalone View
Standalone View
source/blender/sequencer/intern/image_cache.c
| Show First 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | |||||
| #define COLORSPACE_NAME_MAX 64 /* XXX: defined in imb intern */ | #define COLORSPACE_NAME_MAX 64 /* XXX: defined in imb intern */ | ||||
| typedef struct DiskCacheHeaderEntry { | typedef struct DiskCacheHeaderEntry { | ||||
| unsigned char encoding; | unsigned char encoding; | ||||
| uint64_t frameno; | uint64_t frameno; | ||||
| uint64_t size_compressed; | uint64_t size_compressed; | ||||
| uint64_t size_raw; | uint64_t size_raw; | ||||
| uint64_t offset; | uint64_t offset; | ||||
| uint64_t downscale_index; | |||||
| char colorspace_name[COLORSPACE_NAME_MAX]; | char colorspace_name[COLORSPACE_NAME_MAX]; | ||||
| } DiskCacheHeaderEntry; | } DiskCacheHeaderEntry; | ||||
| typedef struct DiskCacheHeader { | typedef struct DiskCacheHeader { | ||||
| DiskCacheHeaderEntry entry[DCACHE_IMAGES_PER_FILE]; | DiskCacheHeaderEntry entry[DCACHE_IMAGES_PER_FILE]; | ||||
| } DiskCacheHeader; | } DiskCacheHeader; | ||||
| typedef struct SeqDiskCache { | typedef struct SeqDiskCache { | ||||
| Show All 20 Lines | |||||
| typedef struct SeqCache { | typedef struct SeqCache { | ||||
| Main *bmain; | Main *bmain; | ||||
| struct GHash *hash; | struct GHash *hash; | ||||
| ThreadMutex iterator_mutex; | ThreadMutex iterator_mutex; | ||||
| struct BLI_mempool *keys_pool; | struct BLI_mempool *keys_pool; | ||||
| struct BLI_mempool *items_pool; | struct BLI_mempool *items_pool; | ||||
| struct SeqCacheKey *last_key; | struct SeqCacheKey *last_key; | ||||
| size_t memory_used; | |||||
| SeqDiskCache *disk_cache; | SeqDiskCache *disk_cache; | ||||
| } SeqCache; | } SeqCache; | ||||
| typedef struct SeqCacheItem { | typedef struct SeqCacheItem { | ||||
| struct SeqCache *cache_owner; | struct SeqCache *cache_owner; | ||||
| struct ImBuf *ibuf; | struct ImBuf *ibuf; | ||||
| IMB_Downscale downscale_index; /* Used downscale for RAW images, so we have information about | |||||
| original size. */ | |||||
| } SeqCacheItem; | } SeqCacheItem; | ||||
| typedef struct SeqCacheKey { | typedef struct SeqCacheKey { | ||||
| struct SeqCache *cache_owner; | struct SeqCache *cache_owner; | ||||
| void *userkey; | void *userkey; | ||||
| struct SeqCacheKey *link_prev; /* Used for linking intermediate items to final frame. */ | struct SeqCacheKey *link_prev; /* Used for linking intermediate items to final frame. */ | ||||
| struct SeqCacheKey *link_next; /* Used for linking intermediate items to final frame. */ | struct SeqCacheKey *link_next; /* Used for linking intermediate items to final frame. */ | ||||
| struct Sequence *seq; | struct Sequence *seq; | ||||
| ▲ Show 20 Lines • Show All 362 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static size_t seq_disk_cache_write_header(FILE *file, DiskCacheHeader *header) | static size_t seq_disk_cache_write_header(FILE *file, DiskCacheHeader *header) | ||||
| { | { | ||||
| fseek(file, 0, 0); | fseek(file, 0, 0); | ||||
| return fwrite(header, sizeof(*header), 1, file); | return fwrite(header, sizeof(*header), 1, file); | ||||
| } | } | ||||
| static int seq_disk_cache_add_header_entry(SeqCacheKey *key, ImBuf *ibuf, DiskCacheHeader *header) | static int seq_disk_cache_add_header_entry(SeqCacheKey *key, | ||||
| ImBuf *ibuf, | |||||
| IMB_Downscale downscale_index, | |||||
| DiskCacheHeader *header) | |||||
| { | { | ||||
| int i; | int i; | ||||
| uint64_t offset = sizeof(*header); | uint64_t offset = sizeof(*header); | ||||
| /* Lookup free entry, get offset for new data. */ | /* Lookup free entry, get offset for new data. */ | ||||
| for (i = 0; i < DCACHE_IMAGES_PER_FILE; i++) { | for (i = 0; i < DCACHE_IMAGES_PER_FILE; i++) { | ||||
| if (header->entry[i].size_compressed == 0) { | if (header->entry[i].size_compressed == 0) { | ||||
| break; | break; | ||||
| Show All 17 Lines | if (ENDIAN_ORDER == B_ENDIAN) { | ||||
| header->entry[i].encoding = 255; | header->entry[i].encoding = 255; | ||||
| } | } | ||||
| else { | else { | ||||
| header->entry[i].encoding = 0; | header->entry[i].encoding = 0; | ||||
| } | } | ||||
| header->entry[i].offset = offset; | header->entry[i].offset = offset; | ||||
| header->entry[i].frameno = key->frame_index; | header->entry[i].frameno = key->frame_index; | ||||
| header->entry[i].downscale_index = downscale_index; | |||||
| /* Store colorspace name of ibuf. */ | /* Store colorspace name of ibuf. */ | ||||
| const char *colorspace_name; | const char *colorspace_name; | ||||
| if (ibuf->rect) { | if (ibuf->rect) { | ||||
| header->entry[i].size_raw = ibuf->x * ibuf->y * ibuf->channels; | header->entry[i].size_raw = ibuf->x * ibuf->y * ibuf->channels; | ||||
| colorspace_name = IMB_colormanagement_get_rect_colorspace(ibuf); | colorspace_name = IMB_colormanagement_get_rect_colorspace(ibuf); | ||||
| } | } | ||||
| else { | else { | ||||
| Show All 12 Lines | for (int i = 0; i < DCACHE_IMAGES_PER_FILE; i++) { | ||||
| if (header->entry[i].frameno == key->frame_index) { | if (header->entry[i].frameno == key->frame_index) { | ||||
| return i; | return i; | ||||
| } | } | ||||
| } | } | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| static bool seq_disk_cache_write_file(SeqDiskCache *disk_cache, SeqCacheKey *key, ImBuf *ibuf) | static bool seq_disk_cache_write_file(SeqDiskCache *disk_cache, | ||||
| SeqCacheKey *key, | |||||
| ImBuf *ibuf, | |||||
| IMB_Downscale downscale_index) | |||||
| { | { | ||||
| char path[FILE_MAX]; | char path[FILE_MAX]; | ||||
| seq_disk_cache_get_file_path(disk_cache, key, path, sizeof(path)); | seq_disk_cache_get_file_path(disk_cache, key, path, sizeof(path)); | ||||
| BLI_make_existing_file(path); | BLI_make_existing_file(path); | ||||
| FILE *file = BLI_fopen(path, "rb+"); | FILE *file = BLI_fopen(path, "rb+"); | ||||
| if (!file) { | if (!file) { | ||||
| file = BLI_fopen(path, "wb+"); | file = BLI_fopen(path, "wb+"); | ||||
| if (!file) { | if (!file) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| seq_disk_cache_add_file_to_list(disk_cache, path); | seq_disk_cache_add_file_to_list(disk_cache, path); | ||||
| } | } | ||||
| DiskCacheHeader header; | DiskCacheHeader header; | ||||
| memset(&header, 0, sizeof(header)); | memset(&header, 0, sizeof(header)); | ||||
| seq_disk_cache_read_header(file, &header); | seq_disk_cache_read_header(file, &header); | ||||
| int entry_index = seq_disk_cache_add_header_entry(key, ibuf, &header); | int entry_index = seq_disk_cache_add_header_entry(key, ibuf, downscale_index, &header); | ||||
| size_t bytes_written = deflate_imbuf_to_file( | size_t bytes_written = deflate_imbuf_to_file( | ||||
| ibuf, file, seq_disk_cache_compression_level(), &header.entry[entry_index]); | ibuf, file, seq_disk_cache_compression_level(), &header.entry[entry_index]); | ||||
| if (bytes_written != 0) { | if (bytes_written != 0) { | ||||
| /* Last step is writing header, as image data can be overwritten, | /* Last step is writing header, as image data can be overwritten, | ||||
| * but missing data would cause problems. | * but missing data would cause problems. | ||||
| */ | */ | ||||
| header.entry[entry_index].size_compressed = bytes_written; | header.entry[entry_index].size_compressed = bytes_written; | ||||
| seq_disk_cache_write_header(file, &header); | seq_disk_cache_write_header(file, &header); | ||||
| seq_disk_cache_update_file(disk_cache, path); | seq_disk_cache_update_file(disk_cache, path); | ||||
| fclose(file); | fclose(file); | ||||
| return true; | return true; | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| static ImBuf *seq_disk_cache_read_file(SeqDiskCache *disk_cache, SeqCacheKey *key) | static ImBuf *seq_disk_cache_read_file(SeqDiskCache *disk_cache, | ||||
| SeqCacheKey *key, | |||||
| IMB_Downscale *downscale_index) | |||||
| { | { | ||||
| char path[FILE_MAX]; | char path[FILE_MAX]; | ||||
| DiskCacheHeader header; | DiskCacheHeader header; | ||||
| seq_disk_cache_get_file_path(disk_cache, key, path, sizeof(path)); | seq_disk_cache_get_file_path(disk_cache, key, path, sizeof(path)); | ||||
| BLI_make_existing_file(path); | BLI_make_existing_file(path); | ||||
| FILE *file = BLI_fopen(path, "rb"); | FILE *file = BLI_fopen(path, "rb"); | ||||
| Show All 37 Lines | if (bytes_read != expected_size) { | ||||
| fclose(file); | fclose(file); | ||||
| IMB_freeImBuf(ibuf); | IMB_freeImBuf(ibuf); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| BLI_file_touch(path); | BLI_file_touch(path); | ||||
| seq_disk_cache_update_file(disk_cache, path); | seq_disk_cache_update_file(disk_cache, path); | ||||
| fclose(file); | fclose(file); | ||||
| if (downscale_index != NULL) { | |||||
| *downscale_index = header.entry[entry_index].downscale_index; | |||||
| } | |||||
| return ibuf; | return ibuf; | ||||
| } | } | ||||
| #undef DCACHE_FNAME_FORMAT | #undef DCACHE_FNAME_FORMAT | ||||
| #undef DCACHE_IMAGES_PER_FILE | #undef DCACHE_IMAGES_PER_FILE | ||||
| #undef COLORSPACE_NAME_MAX | #undef COLORSPACE_NAME_MAX | ||||
| #undef DCACHE_CURRENT_VERSION | #undef DCACHE_CURRENT_VERSION | ||||
| ▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| SeqCacheKey *key = val; | SeqCacheKey *key = val; | ||||
| BLI_mempool_free(key->cache_owner->keys_pool, key); | BLI_mempool_free(key->cache_owner->keys_pool, key); | ||||
| } | } | ||||
| static void seq_cache_valfree(void *val) | static void seq_cache_valfree(void *val) | ||||
| { | { | ||||
| SeqCacheItem *item = (SeqCacheItem *)val; | SeqCacheItem *item = (SeqCacheItem *)val; | ||||
| SeqCache *cache = item->cache_owner; | |||||
| if (item->ibuf) { | if (item->ibuf) { | ||||
| cache->memory_used -= IMB_get_size_in_memory(item->ibuf); | |||||
| IMB_freeImBuf(item->ibuf); | IMB_freeImBuf(item->ibuf); | ||||
| } | } | ||||
| BLI_mempool_free(item->cache_owner->items_pool, item); | BLI_mempool_free(item->cache_owner->items_pool, item); | ||||
| } | } | ||||
| static void seq_cache_put(SeqCache *cache, SeqCacheKey *key, ImBuf *ibuf) | static void seq_cache_put(SeqCache *cache, | ||||
| SeqCacheKey *key, | |||||
| ImBuf *ibuf, | |||||
| IMB_Downscale downscale_index) | |||||
| { | { | ||||
| SeqCacheItem *item; | SeqCacheItem *item; | ||||
| item = BLI_mempool_alloc(cache->items_pool); | item = BLI_mempool_alloc(cache->items_pool); | ||||
| item->cache_owner = cache; | item->cache_owner = cache; | ||||
| item->ibuf = ibuf; | item->ibuf = ibuf; | ||||
| item->downscale_index = downscale_index; | |||||
| if (BLI_ghash_reinsert(cache->hash, key, item, seq_cache_keyfree, seq_cache_valfree)) { | if (BLI_ghash_reinsert(cache->hash, key, item, seq_cache_keyfree, seq_cache_valfree)) { | ||||
| IMB_refImBuf(ibuf); | IMB_refImBuf(ibuf); | ||||
| cache->last_key = key; | cache->last_key = key; | ||||
| cache->memory_used += IMB_get_size_in_memory(ibuf); | |||||
| } | } | ||||
| } | } | ||||
| static ImBuf *seq_cache_get(SeqCache *cache, SeqCacheKey *key) | static ImBuf *seq_cache_get(SeqCache *cache, SeqCacheKey *key, IMB_Downscale *downscale_index) | ||||
| { | { | ||||
| SeqCacheItem *item = BLI_ghash_lookup(cache->hash, key); | SeqCacheItem *item = BLI_ghash_lookup(cache->hash, key); | ||||
| if (item && item->ibuf) { | if (item && item->ibuf) { | ||||
| IMB_refImBuf(item->ibuf); | IMB_refImBuf(item->ibuf); | ||||
| if (downscale_index != NULL) { | |||||
| *downscale_index = item->downscale_index; | |||||
| } | |||||
| return item->ibuf; | return item->ibuf; | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| static void seq_cache_relink_keys(SeqCacheKey *link_next, SeqCacheKey *link_prev) | static void seq_cache_relink_keys(SeqCacheKey *link_next, SeqCacheKey *link_prev) | ||||
| ▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | static SeqCacheKey *seq_cache_get_item_for_removal(Scene *scene) | ||||
| return finalkey; | return finalkey; | ||||
| } | } | ||||
| /* Find only "base" keys. | /* Find only "base" keys. | ||||
| * Sources(other types) for a frame must be freed all at once. | * Sources(other types) for a frame must be freed all at once. | ||||
| */ | */ | ||||
| bool BKE_sequencer_cache_recycle_item(Scene *scene) | bool BKE_sequencer_cache_recycle_item(Scene *scene) | ||||
| { | { | ||||
| size_t memory_total = seq_cache_get_mem_total(); | |||||
| SeqCache *cache = seq_cache_get_from_scene(scene); | SeqCache *cache = seq_cache_get_from_scene(scene); | ||||
| if (!cache) { | if (!cache) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| seq_cache_lock(scene); | seq_cache_lock(scene); | ||||
| while (cache->memory_used > memory_total) { | while (BKE_sequencer_cache_is_full()) { | ||||
| SeqCacheKey *finalkey = seq_cache_get_item_for_removal(scene); | SeqCacheKey *finalkey = seq_cache_get_item_for_removal(scene); | ||||
| if (finalkey) { | if (finalkey) { | ||||
| seq_cache_recycle_linked(scene, finalkey); | seq_cache_recycle_linked(scene, finalkey); | ||||
| } | } | ||||
| else { | else { | ||||
| seq_cache_unlock(scene); | seq_cache_unlock(scene); | ||||
| return false; | return false; | ||||
| ▲ Show 20 Lines • Show All 213 Lines • ▼ Show 20 Lines | void BKE_sequencer_cache_cleanup_sequence(Scene *scene, | ||||
| cache->last_key = NULL; | cache->last_key = NULL; | ||||
| seq_cache_unlock(scene); | seq_cache_unlock(scene); | ||||
| } | } | ||||
| struct ImBuf *BKE_sequencer_cache_get(const SeqRenderData *context, | struct ImBuf *BKE_sequencer_cache_get(const SeqRenderData *context, | ||||
| Sequence *seq, | Sequence *seq, | ||||
| float timeline_frame, | float timeline_frame, | ||||
| int type, | int type, | ||||
| IMB_Downscale *downscale_index, | |||||
| bool skip_disk_cache) | bool skip_disk_cache) | ||||
| { | { | ||||
| if (context->skip_cache || context->is_proxy_render || !seq) { | if (context->skip_cache || context->is_proxy_render || !seq) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| Scene *scene = context->scene; | Scene *scene = context->scene; | ||||
| Show All 19 Lines | struct ImBuf *BKE_sequencer_cache_get(const SeqRenderData *context, | ||||
| /* Try RAM cache: */ | /* Try RAM cache: */ | ||||
| if (cache && seq) { | if (cache && seq) { | ||||
| key.seq = seq; | key.seq = seq; | ||||
| key.context = *context; | key.context = *context; | ||||
| key.frame_index = seq_cache_timeline_frame_to_frame_index(seq, timeline_frame, type); | key.frame_index = seq_cache_timeline_frame_to_frame_index(seq, timeline_frame, type); | ||||
| key.type = type; | key.type = type; | ||||
| ibuf = seq_cache_get(cache, &key); | ibuf = seq_cache_get(cache, &key, downscale_index); | ||||
| } | } | ||||
| seq_cache_unlock(scene); | seq_cache_unlock(scene); | ||||
| if (ibuf) { | if (ibuf) { | ||||
| return ibuf; | return ibuf; | ||||
| } | } | ||||
| /* Try disk cache: */ | /* Try disk cache: */ | ||||
| if (!skip_disk_cache && seq_disk_cache_is_enabled(context->bmain)) { | if (!skip_disk_cache && seq_disk_cache_is_enabled(context->bmain)) { | ||||
| if (cache->disk_cache == NULL) { | if (cache->disk_cache == NULL) { | ||||
| seq_disk_cache_create(context->bmain, context->scene); | seq_disk_cache_create(context->bmain, context->scene); | ||||
| } | } | ||||
| BLI_mutex_lock(&cache->disk_cache->read_write_mutex); | BLI_mutex_lock(&cache->disk_cache->read_write_mutex); | ||||
| ibuf = seq_disk_cache_read_file(cache->disk_cache, &key); | ibuf = seq_disk_cache_read_file(cache->disk_cache, &key, downscale_index); | ||||
| BLI_mutex_unlock(&cache->disk_cache->read_write_mutex); | BLI_mutex_unlock(&cache->disk_cache->read_write_mutex); | ||||
| if (ibuf) { | if (ibuf) { | ||||
| if (key.type == SEQ_CACHE_STORE_FINAL_OUT) { | if (key.type == SEQ_CACHE_STORE_FINAL_OUT) { | ||||
| BKE_sequencer_cache_put_if_possible(context, seq, timeline_frame, type, ibuf, 0.0f, true); | BKE_sequencer_cache_put_if_possible(context, seq, timeline_frame, type, ibuf, 0.0f, true); | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_sequencer_cache_put(context, seq, timeline_frame, type, ibuf, 0.0f, true); | BKE_sequencer_cache_put( | ||||
| context, seq, timeline_frame, type, ibuf, 0.0f, IMB_DOWNSCALE_NONE, true); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return ibuf; | return ibuf; | ||||
| } | } | ||||
| bool BKE_sequencer_cache_put_if_possible(const SeqRenderData *context, | bool BKE_sequencer_cache_put_if_possible(const SeqRenderData *context, | ||||
| Show All 12 Lines | if (context->is_prefetch_render) { | ||||
| seq = BKE_sequencer_prefetch_get_original_sequence(seq, scene); | seq = BKE_sequencer_prefetch_get_original_sequence(seq, scene); | ||||
| } | } | ||||
| if (!seq) { | if (!seq) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (BKE_sequencer_cache_recycle_item(scene)) { | if (BKE_sequencer_cache_recycle_item(scene)) { | ||||
| BKE_sequencer_cache_put(context, seq, timeline_frame, type, ibuf, cost, skip_disk_cache); | BKE_sequencer_cache_put( | ||||
| context, seq, timeline_frame, type, ibuf, cost, skip_disk_cache, IMB_DOWNSCALE_NONE); | |||||
| return true; | return true; | ||||
| } | } | ||||
| seq_cache_set_temp_cache_linked(scene, scene->ed->cache->last_key); | seq_cache_set_temp_cache_linked(scene, scene->ed->cache->last_key); | ||||
| scene->ed->cache->last_key = NULL; | scene->ed->cache->last_key = NULL; | ||||
| return false; | return false; | ||||
| } | } | ||||
| void BKE_sequencer_cache_put(const SeqRenderData *context, | void BKE_sequencer_cache_put(const SeqRenderData *context, | ||||
| Sequence *seq, | Sequence *seq, | ||||
| float timeline_frame, | float timeline_frame, | ||||
| int type, | int type, | ||||
| ImBuf *i, | ImBuf *i, | ||||
| float cost, | float cost, | ||||
| IMB_Downscale downscale_index, | |||||
| bool skip_disk_cache) | bool skip_disk_cache) | ||||
| { | { | ||||
| if (i == NULL || context->skip_cache || context->is_proxy_render || !seq) { | if (i == NULL || context->skip_cache || context->is_proxy_render || !seq) { | ||||
| return; | return; | ||||
| } | } | ||||
| Scene *scene = context->scene; | Scene *scene = context->scene; | ||||
| if (context->is_prefetch_render) { | if (context->is_prefetch_render) { | ||||
| context = BKE_sequencer_prefetch_get_original_context(context); | context = BKE_sequencer_prefetch_get_original_context(context); | ||||
| scene = context->scene; | scene = context->scene; | ||||
| seq = BKE_sequencer_prefetch_get_original_sequence(seq, scene); | seq = BKE_sequencer_prefetch_get_original_sequence(seq, scene); | ||||
| BLI_assert(seq != NULL); | BLI_assert(seq != NULL); | ||||
| } | } | ||||
| /* Prevent reinserting, it breaks cache key linking. */ | /* Prevent reinserting, it breaks cache key linking. */ | ||||
| ImBuf *test = BKE_sequencer_cache_get(context, seq, timeline_frame, type, true); | ImBuf *test = BKE_sequencer_cache_get(context, seq, timeline_frame, type, NULL, true); | ||||
| if (test) { | if (test) { | ||||
| IMB_freeImBuf(test); | IMB_freeImBuf(test); | ||||
| return; | return; | ||||
| } | } | ||||
| if (!scene->ed->cache) { | if (!scene->ed->cache) { | ||||
| seq_cache_create(context->bmain, scene); | seq_cache_create(context->bmain, scene); | ||||
| } | } | ||||
| Show All 34 Lines | void BKE_sequencer_cache_put(const SeqRenderData *context, | ||||
| /* Item stored for later use */ | /* Item stored for later use */ | ||||
| if (flag & type) { | if (flag & type) { | ||||
| key->is_temp_cache = false; | key->is_temp_cache = false; | ||||
| key->link_prev = cache->last_key; | key->link_prev = cache->last_key; | ||||
| } | } | ||||
| SeqCacheKey *temp_last_key = cache->last_key; | SeqCacheKey *temp_last_key = cache->last_key; | ||||
| seq_cache_put(cache, key, i); | seq_cache_put(cache, key, i, downscale_index); | ||||
| /* Restore pointer to previous item as this one will be freed when stack is rendered. */ | /* Restore pointer to previous item as this one will be freed when stack is rendered. */ | ||||
| if (key->is_temp_cache) { | if (key->is_temp_cache) { | ||||
| cache->last_key = temp_last_key; | cache->last_key = temp_last_key; | ||||
| } | } | ||||
| /* Set last_key's reference to this key so we can look up chain backwards. | /* Set last_key's reference to this key so we can look up chain backwards. | ||||
| * Item is already put in cache, so cache->last_key points to current key. | * Item is already put in cache, so cache->last_key points to current key. | ||||
| Show All 11 Lines | void BKE_sequencer_cache_put(const SeqRenderData *context, | ||||
| if (!key->is_temp_cache && !skip_disk_cache) { | if (!key->is_temp_cache && !skip_disk_cache) { | ||||
| if (seq_disk_cache_is_enabled(context->bmain)) { | if (seq_disk_cache_is_enabled(context->bmain)) { | ||||
| if (cache->disk_cache == NULL) { | if (cache->disk_cache == NULL) { | ||||
| seq_disk_cache_create(context->bmain, context->scene); | seq_disk_cache_create(context->bmain, context->scene); | ||||
| } | } | ||||
| BLI_mutex_lock(&cache->disk_cache->read_write_mutex); | BLI_mutex_lock(&cache->disk_cache->read_write_mutex); | ||||
| seq_disk_cache_write_file(cache->disk_cache, key, i); | seq_disk_cache_write_file(cache->disk_cache, key, i, downscale_index); | ||||
| BLI_mutex_unlock(&cache->disk_cache->read_write_mutex); | BLI_mutex_unlock(&cache->disk_cache->read_write_mutex); | ||||
| seq_disk_cache_enforce_limits(cache->disk_cache); | seq_disk_cache_enforce_limits(cache->disk_cache); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void BKE_sequencer_cache_iterate(struct Scene *scene, | void BKE_sequencer_cache_iterate(struct Scene *scene, | ||||
| void *userdata, | void *userdata, | ||||
| Show All 23 Lines | void BKE_sequencer_cache_iterate(struct Scene *scene, | ||||
| } | } | ||||
| cache->last_key = NULL; | cache->last_key = NULL; | ||||
| seq_cache_unlock(scene); | seq_cache_unlock(scene); | ||||
| } | } | ||||
| bool BKE_sequencer_cache_is_full(Scene *scene) | bool BKE_sequencer_cache_is_full(Scene *scene) | ||||
| { | { | ||||
| size_t memory_total = seq_cache_get_mem_total(); | return seq_cache_get_mem_total() < MEM_get_memory_in_use(); | ||||
| SeqCache *cache = seq_cache_get_from_scene(scene); | |||||
| if (!cache) { | |||||
| return false; | |||||
| } | |||||
| return memory_total < cache->memory_used; | |||||
| } | } | ||||