70 for (
const auto &frame : item.value.frames.values()) {
80 if (entry ==
nullptr) {
83 for (
const auto &frame : entry->
frames.values()) {
93 if (*cache ==
nullptr) {
94 *cache = MEM_new<SourceImageCache>(__func__);
101 if (scene ==
nullptr || scene->
ed ==
nullptr) {
113 frame_index = std::trunc(frame_index);
116 frame_index += strip->anim_startofs;
124 float timeline_frame)
129 draw_type =
eDrawType(scene->
r.seq_prev_type);
131 return {frame_index, context->view_id, draw_type};
136 float timeline_frame)
138 if (context->skip_cache || strip ==
nullptr) {
150 if (cache ==
nullptr) {
155 if (val ==
nullptr) {
161 if (frame !=
nullptr) {
170 if (res.
image->
x != context->rectx || res.
image->
y != context->recty) {
185 float timeline_frame,
188 if (context->skip_cache || strip ==
nullptr || !
image.is_valid()) {
203 if (val ==
nullptr) {
205 cache->
map_.add_new(strip, {});
206 val = cache->
map_.lookup_ptr(strip);
208 BLI_assert_msg(val !=
nullptr,
"Source image cache value should never be null here");
222 if (cache !=
nullptr) {
231 if (cache !=
nullptr) {
240 if (cache !=
nullptr) {
249 void callback_iter(
void *userdata,
255 if (cache ==
nullptr) {
259 for (
const auto &[strip, frames] : cache->
map_.items()) {
260 for (
const auto &[frame_key, frame] : frames.frames.items()) {
261 const float timeline_frame = strip->start + frame.strip_frame;
262 callback_iter(userdata, strip,
int(timeline_frame));
271 if (cache ==
nullptr) {
277 if (frame.image.is_valid()) {
289 if (cache ==
nullptr) {
294 count += entry.frames.size();
303 if (cache ==
nullptr) {
312 int cur_prefetch_start = std::numeric_limits<int>::min();
313 int cur_prefetch_end = std::numeric_limits<int>::min();
318 const bool prefetch_loops_around = cur_prefetch_start > cur_prefetch_end;
320 const int timeline_start = scene->playback_start();
321 const int timeline_end = scene->playback_end();
324 const int cur_frame = prefetch_loops_around ? timeline_start : scene->
r.cfra;
329 for (
const auto &strip : cache->
map_.items()) {
330 for (
const auto &entry : strip.value.frames.items()) {
331 const int item_frame = int(strip.key->start + entry.value.strip_frame);
332 if (prefetch_loops_around) {
333 if (item_frame >= timeline_start && item_frame <= cur_prefetch_end) {
336 if (item_frame >= cur_prefetch_start && item_frame <= timeline_end) {
340 else if (item_frame >= cur_prefetch_start && item_frame <= cur_prefetch_end) {
346 if (item_frame < cur_frame) {
347 score = (cur_frame - item_frame) * 2;
349 else if (item_frame > cur_frame) {
350 score = item_frame - cur_frame;
352 if (score > best_score) {
353 best_strip = &strip.value;
354 best_key = entry.key;
361 if (best_strip !=
nullptr) {
363 best_strip->
frames.remove(best_key);
#define BLI_assert_msg(a, msg)
const Value * lookup_ptr(const Key &key) const
void remove_contained(const Key &key)
ItemIterator items() const &
static SourceImageCache::Key get_key(const RenderData *context, const Scene *scene, const Strip *strip, float timeline_frame)
void source_image_cache_put(const RenderData *context, const Strip *strip, float timeline_frame, const SeqResult &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)
SeqResult source_image_cache_get(const RenderData *context, const Strip *strip, float timeline_frame)
static SourceImageCache * query_source_image_cache(const Scene *scene)
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)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
void IMB_refImBuf(ImBuf *ibuf)
size_t IMB_get_size_in_memory(const ImBuf *ibuf)
void IMB_freeImBuf(ImBuf *ibuf)
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
seq::EditingRuntime * runtime
eEditingCacheFlag cache_flag
SourceImageCache * source_image_cache
friend bool operator==(const Key &a, const Key &b)=default
eDrawType scene_draw_type
Map< Key, FrameEntry > frames
void remove_entry(const Strip *strip)
Map< const Strip *, StripEntry > map_