55 for (
const auto &item :
map_.items()) {
56 for (
const auto &frame : item.value.frames.values()) {
66 if (entry ==
nullptr) {
69 for (
const auto &frame : entry->
frames.values()) {
72 map_.remove_contained(strip);
79 if (*cache ==
nullptr) {
80 *cache = MEM_new<SourceImageCache>(__func__);
87 if (scene ==
nullptr || scene->
ed ==
nullptr) {
99 frame_index = std::trunc(frame_index);
109 if (context->skip_cache || context->is_proxy_render || strip ==
nullptr) {
116 const int view_id = context->view_id;
118 ImBuf *res =
nullptr;
122 if (cache ==
nullptr) {
126 SourceImageCache::StripEntry *val = cache->
map_.lookup_ptr(strip);
127 if (val ==
nullptr) {
132 SourceImageCache::FrameEntry *frame = val->frames.lookup_ptr({frame_index, view_id});
133 if (frame !=
nullptr) {
140 if (res->
x != context->rectx || res->
y != context->recty) {
155 float timeline_frame,
158 if (context->skip_cache || context->is_proxy_render || strip ==
nullptr || image ==
nullptr) {
166 const int view_id = context->view_id;
173 SourceImageCache::StripEntry *val = cache->
map_.lookup_ptr(strip);
175 if (val ==
nullptr) {
177 cache->
map_.add_new(strip, {});
178 val = cache->
map_.lookup_ptr(strip);
180 BLI_assert_msg(val !=
nullptr,
"Source image cache value should never be null here");
182 SourceImageCache::FrameEntry &frame = val->frames.lookup_or_add_default({frame_index, view_id});
183 if (frame.image !=
nullptr) {
186 frame.strip_frame = timeline_frame - strip->
start;
194 if (cache !=
nullptr) {
203 if (cache !=
nullptr) {
212 if (cache !=
nullptr) {
221 void callback_iter(
void *userdata,
227 if (cache ==
nullptr) {
231 for (
const auto &[strip, frames] : cache->
map_.items()) {
232 for (
const auto &[frame_key, frame] : frames.frames.items()) {
233 const float timeline_frame = strip->
start + frame.strip_frame;
234 callback_iter(userdata, strip,
int(timeline_frame));
243 if (cache ==
nullptr) {
247 for (
const SourceImageCache::StripEntry &entry : cache->
map_.values()) {
248 for (
const SourceImageCache::FrameEntry &frame : entry.frames.values()) {
259 if (cache ==
nullptr) {
263 for (
const SourceImageCache::StripEntry &entry : cache->
map_.values()) {
264 count += entry.frames.size();
273 if (cache ==
nullptr) {
282 int cur_prefetch_start = std::numeric_limits<int>::min();
283 int cur_prefetch_end = std::numeric_limits<int>::min();
288 const bool prefetch_loops_around = cur_prefetch_start > cur_prefetch_end;
290 const int timeline_start =
PSFRA;
291 const int timeline_end =
PEFRA;
294 const int cur_frame = prefetch_loops_around ? timeline_start : scene->
r.cfra;
296 SourceImageCache::StripEntry *best_strip =
nullptr;
297 std::pair<float, int> best_key = {};
299 for (
const auto &strip : cache->
map_.items()) {
300 for (
const auto &entry : strip.value.frames.items()) {
301 const int item_frame = int(strip.key->start + entry.value.strip_frame);
302 if (prefetch_loops_around) {
303 if (item_frame >= timeline_start && item_frame <= cur_prefetch_end) {
306 if (item_frame >= cur_prefetch_start && item_frame <= timeline_end) {
310 else if (item_frame >= cur_prefetch_start && item_frame <= cur_prefetch_end) {
316 if (item_frame < cur_frame) {
317 score = (cur_frame - item_frame) * 2;
319 else if (item_frame > cur_frame) {
320 score = item_frame - cur_frame;
322 if (score > best_score) {
323 best_strip = &strip.value;
324 best_key = entry.key;
331 if (best_strip !=
nullptr) {
333 best_strip->frames.remove(best_key);
#define BLI_assert_msg(a, msg)
void IMB_freeImBuf(ImBuf *ibuf)
void IMB_refImBuf(ImBuf *ibuf)
size_t IMB_get_size_in_memory(const ImBuf *ibuf)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void source_image_cache_put(const RenderData *context, const Strip *strip, float timeline_frame, ImBuf *image)
static float give_cache_frame_index(const Scene *scene, const Strip *strip, float timeline_frame)
void source_image_cache_iterate(Scene *scene, void *userdata, void callback_iter(void *userdata, const Strip *strip, int timeline_frame))
float give_frame_index(const Scene *scene, const Strip *strip, float timeline_frame)
bool source_image_cache_evict(Scene *scene)
void source_image_cache_clear(Scene *scene)
void source_image_cache_invalidate_strip(Scene *scene, const Strip *strip)
size_t source_image_cache_get_image_count(const Scene *scene)
static SourceImageCache * query_source_image_cache(const Scene *scene)
ImBuf * source_image_cache_get(const RenderData *context, const Strip *strip, float timeline_frame)
Scene * prefetch_get_original_scene_and_strip(const RenderData *context, const Strip *&strip)
void source_image_cache_destroy(Scene *scene)
static Mutex source_image_cache_mutex
size_t source_image_cache_calc_memory_size(const Scene *scene)
static SourceImageCache * ensure_source_image_cache(Scene *scene)
void seq_prefetch_get_time_range(Scene *scene, int *r_start, int *r_end)
SourceImageCache * source_image_cache
Map< std::pair< float, int >, FrameEntry > frames
void remove_entry(const Strip *strip)
Map< const Strip *, StripEntry > map_