67 if (*cache ==
nullptr) {
68 *cache = MEM_new<FinalImageCache>(__func__);
75 if (scene ==
nullptr || scene->
ed ==
nullptr) {
93 int(
math::round(timeline_frame)), view_id, display_channel, image_size};
99 if (cache ==
nullptr) {
102 res = cache->
map_.lookup_default(key,
nullptr);
112 float timeline_frame,
124 int(
math::round(timeline_frame)), view_id, display_channel, image_size};
131 cache->
map_.add_or_modify(
134 [&](
ImBuf **existing) {
143 const float timeline_frame_start,
144 const float timeline_frame_end)
148 if (cache ==
nullptr) {
152 const int key_start = int(
math::floor(timeline_frame_start));
153 const int key_end = int(
math::ceil(timeline_frame_end));
155 for (
auto it = cache->
map_.items().begin(); it != cache->
map_.items().end(); it++) {
156 const int key = (*it).key.timeline_frame;
157 if (key >= key_start && key <= key_end) {
159 cache->
map_.remove(it);
168 if (cache !=
nullptr) {
177 if (cache !=
nullptr) {
186 void callback_iter(
void *userdata,
int timeline_frame))
190 if (cache ==
nullptr) {
194 callback_iter(userdata, frame_view.timeline_frame);
202 if (cache ==
nullptr) {
206 for (
ImBuf *frame : cache->
map_.values()) {
216 if (cache ==
nullptr) {
219 return cache->
map_.size();
226 if (cache ==
nullptr) {
236 int cur_prefetch_start = std::numeric_limits<int>::min();
237 int cur_prefetch_end = std::numeric_limits<int>::min();
242 const bool prefetch_loops_around = cur_prefetch_start > cur_prefetch_end;
244 const int timeline_start = scene->playback_start();
245 const int timeline_end = scene->playback_end();
248 const int cur_frame = prefetch_loops_around ? timeline_start : scene->
r.cfra;
251 ImBuf *best_item =
nullptr;
253 for (
const auto &item : cache->
map_.items()) {
254 const int item_frame = item.key.timeline_frame;
255 if (prefetch_loops_around) {
256 if (item_frame >= timeline_start && item_frame <= cur_prefetch_end) {
259 if (item_frame >= cur_prefetch_start && item_frame <= timeline_end) {
263 else if (item_frame >= cur_prefetch_start && item_frame <= cur_prefetch_end) {
269 if (item_frame < cur_frame) {
270 score = (cur_frame - item_frame) * 2;
272 else if (item_frame > cur_frame) {
273 score = item_frame - cur_frame;
275 if (score > best_score) {
277 best_item = item.value;
283 if (best_item !=
nullptr) {
285 cache->
map_.remove(best_key);
ValueIterator values() const &
static Mutex final_image_cache_mutex
size_t final_image_cache_calc_memory_size(const Scene *scene)
static FinalImageCache * ensure_final_image_cache(Scene *scene)
void final_image_cache_invalidate_frame_range(Scene *scene, const float timeline_frame_start, const float timeline_frame_end)
void final_image_cache_iterate(Scene *scene, void *userdata, void callback_iter(void *userdata, int timeline_frame))
void final_image_cache_destroy(Scene *scene)
ImBuf * final_image_cache_get(Scene *scene, float timeline_frame, int view_id, int display_channel, int2 image_size, bool is_render)
void final_image_cache_clear(Scene *scene)
void final_image_cache_put(Scene *scene, float timeline_frame, int view_id, int display_channel, int2 image_size, bool is_render, ImBuf *image)
bool final_image_cache_evict(Scene *scene)
size_t final_image_cache_get_image_count(const Scene *scene)
static FinalImageCache * query_final_image_cache(const 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)
VecBase< int32_t, 2 > int2
@ SEQ_CACHE_STORE_FINAL_OUT
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
seq::EditingRuntime * runtime
eEditingCacheFlag cache_flag
FinalImageCache * final_image_cache
bool operator==(const Key &other) const