Changeset View
Changeset View
Standalone View
Standalone View
source/blender/sequencer/intern/image_cache.c
| Show First 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | typedef struct SeqCacheKey { | ||||
| float cost; /* In short: render time(s) divided by playback frame duration(s) */ | float cost; /* In short: render time(s) divided by playback frame duration(s) */ | ||||
| bool is_temp_cache; /* this cache entry will be freed before rendering next frame */ | bool is_temp_cache; /* this cache entry will be freed before rendering next frame */ | ||||
| /* ID of task for assigning temp cache entries to particular task(thread, etc.) */ | /* ID of task for assigning temp cache entries to particular task(thread, etc.) */ | ||||
| eSeqTaskId task_id; | eSeqTaskId task_id; | ||||
| int type; | int type; | ||||
| } SeqCacheKey; | } SeqCacheKey; | ||||
| static ThreadMutex cache_create_lock = BLI_MUTEX_INITIALIZER; | static ThreadMutex cache_create_lock = BLI_MUTEX_INITIALIZER; | ||||
| static float seq_cache_timeline_frame_to_frame_index(Sequence *seq, | static float seq_cache_timeline_frame_to_frame_index(Scene *scene, | ||||
| Sequence *seq, | |||||
| float timeline_frame, | float timeline_frame, | ||||
| int type); | int type); | ||||
| static float seq_cache_frame_index_to_timeline_frame(Sequence *seq, float frame_index); | static float seq_cache_frame_index_to_timeline_frame(Sequence *seq, float frame_index); | ||||
| static char *seq_disk_cache_base_dir(void) | static char *seq_disk_cache_base_dir(void) | ||||
| { | { | ||||
| return U.sequencer_disk_cache_dir; | return U.sequencer_disk_cache_dir; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 569 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| const SeqCacheKey *a = a_; | const SeqCacheKey *a = a_; | ||||
| const SeqCacheKey *b = b_; | const SeqCacheKey *b = b_; | ||||
| return ((a->seq != b->seq) || (a->frame_index != b->frame_index) || (a->type != b->type) || | return ((a->seq != b->seq) || (a->frame_index != b->frame_index) || (a->type != b->type) || | ||||
| seq_cmp_render_data(&a->context, &b->context)); | seq_cmp_render_data(&a->context, &b->context)); | ||||
| } | } | ||||
| static float seq_cache_timeline_frame_to_frame_index(Sequence *seq, float timeline_frame, int type) | static float seq_cache_timeline_frame_to_frame_index(Scene *scene, | ||||
| Sequence *seq, | |||||
| float timeline_frame, | |||||
| int type) | |||||
| { | { | ||||
| /* With raw images, map timeline_frame to strip input media frame range. This means that static | /* With raw images, map timeline_frame to strip input media frame range. This means that static | ||||
| * images or extended frame range of movies will only generate one cache entry. No special | * images or extended frame range of movies will only generate one cache entry. No special | ||||
| * treatment in converting frame index to timeline_frame is needed. */ | * treatment in converting frame index to timeline_frame is needed. */ | ||||
| if (type == SEQ_CACHE_STORE_RAW) { | if (type == SEQ_CACHE_STORE_RAW) { | ||||
| return seq_give_frame_index(seq, timeline_frame); | return seq_give_frame_index(scene, seq, timeline_frame); | ||||
| } | } | ||||
| return timeline_frame - seq->start; | return timeline_frame - seq->start; | ||||
| } | } | ||||
| static float seq_cache_frame_index_to_timeline_frame(Sequence *seq, float frame_index) | static float seq_cache_frame_index_to_timeline_frame(Sequence *seq, float frame_index) | ||||
| { | { | ||||
| return frame_index + seq->start; | return frame_index + seq->start; | ||||
| ▲ Show 20 Lines • Show All 366 Lines • ▼ Show 20 Lines | static void seq_cache_populate_key(SeqCacheKey *key, | ||||
| const SeqRenderData *context, | const SeqRenderData *context, | ||||
| Sequence *seq, | Sequence *seq, | ||||
| const float timeline_frame, | const float timeline_frame, | ||||
| const int type) | const int type) | ||||
| { | { | ||||
| key->cache_owner = seq_cache_get_from_scene(context->scene); | key->cache_owner = seq_cache_get_from_scene(context->scene); | ||||
| 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( | ||||
| context->scene, seq, timeline_frame, type); | |||||
| key->timeline_frame = timeline_frame; | key->timeline_frame = timeline_frame; | ||||
| key->type = type; | key->type = type; | ||||
| key->link_prev = NULL; | key->link_prev = NULL; | ||||
| key->link_next = NULL; | key->link_next = NULL; | ||||
| key->is_temp_cache = true; | key->is_temp_cache = true; | ||||
| key->task_id = context->task_id; | key->task_id = context->task_id; | ||||
| } | } | ||||
| Show All 23 Lines | void seq_cache_free_temp_cache(Scene *scene, short id, int timeline_frame) | ||||
| BLI_ghashIterator_init(&gh_iter, cache->hash); | BLI_ghashIterator_init(&gh_iter, cache->hash); | ||||
| while (!BLI_ghashIterator_done(&gh_iter)) { | while (!BLI_ghashIterator_done(&gh_iter)) { | ||||
| SeqCacheKey *key = BLI_ghashIterator_getKey(&gh_iter); | SeqCacheKey *key = BLI_ghashIterator_getKey(&gh_iter); | ||||
| BLI_ghashIterator_step(&gh_iter); | BLI_ghashIterator_step(&gh_iter); | ||||
| if (key->is_temp_cache && key->task_id == id) { | if (key->is_temp_cache && key->task_id == id) { | ||||
| /* Use frame_index here to avoid freeing raw images if they are used for multiple frames. */ | /* Use frame_index here to avoid freeing raw images if they are used for multiple frames. */ | ||||
| float frame_index = seq_cache_timeline_frame_to_frame_index( | float frame_index = seq_cache_timeline_frame_to_frame_index( | ||||
| key->seq, timeline_frame, key->type); | scene, key->seq, timeline_frame, key->type); | ||||
| if (frame_index != key->frame_index || timeline_frame > key->seq->enddisp || | if (frame_index != key->frame_index || timeline_frame > key->seq->enddisp || | ||||
| timeline_frame < key->seq->startdisp) { | timeline_frame < key->seq->startdisp) { | ||||
| BLI_ghash_remove(cache->hash, key, seq_cache_keyfree, seq_cache_valfree); | BLI_ghash_remove(cache->hash, key, seq_cache_keyfree, seq_cache_valfree); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| seq_cache_unlock(scene); | seq_cache_unlock(scene); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 286 Lines • Show Last 20 Lines | |||||