Blender V5.3
intra_frame_cache.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_map.hh"
10
11#include "DNA_scene_types.h"
12#include "DNA_sequence_types.h"
13
14#include "IMB_imbuf.hh"
15
16#include "SEQ_sequencer.hh"
17
18#include "intra_frame_cache.hh"
19
20namespace blender::seq {
21
24 SeqResult get(const Strip *strip) const;
25 void put(const Strip *strip, const SeqResult &result);
26 void invalidate(const Strip *strip);
27 void clear();
28};
29
45
47{
48 if (scene == nullptr || scene->ed == nullptr) {
49 return nullptr;
50 }
51 return scene->ed->runtime->intra_frame_cache;
52}
53
55{
57 if (cache != nullptr) {
58 cache->preprocessed.clear();
59 cache->composite.clear();
60 cache->timeline_frame = -1.0f;
61 cache->view_id = -1;
62 cache->width = -1;
63 cache->height = -1;
64 cache->is_render = false;
65 }
66}
67
68void intra_frame_cache_invalidate(Scene *scene, const Strip *strip)
69{
70 if (strip == nullptr) {
71 return;
72 }
74 if (cache != nullptr) {
75 cache->preprocessed.invalidate(strip);
76 cache->composite.invalidate(strip);
77 }
78}
79
81{
82 /* Invalidate this strip, and all strips that are above it. */
83 for (auto it = this->map_.items().begin(); it != this->map_.items().end(); it++) {
84 const Strip *key = (*it).key;
85 if (key == strip || key->channel >= strip->channel) {
86 IMB_freeImBuf((*it).value.image);
87 this->map_.remove(it);
88 }
89 }
90}
91
93{
94 SeqResult result = this->map_.lookup_default(strip, {});
95 if (result.is_valid()) {
96 IMB_refImBuf(result.image);
97 }
98 return result;
99}
100
101void StripImageMap::put(const Strip *strip, const SeqResult &result)
102{
103 BLI_assert(strip != nullptr);
104 if (!result.is_valid()) {
105 return;
106 }
107 SeqResult existing = this->map_.lookup_default(strip, {});
108 if (existing.is_valid()) {
109 IMB_freeImBuf(existing.image);
110 }
111 this->map_.add_overwrite(strip, result);
112 IMB_refImBuf(result.image);
113}
114
116{
117 for (const auto &item : this->map_.items()) {
118 IMB_freeImBuf(item.value.image);
119 }
120 this->map_.clear();
121}
122
124{
126 if (strip == nullptr || cache == nullptr) {
127 return {};
128 }
129 return cache->preprocessed.get(strip);
130}
131
133{
135 if (strip == nullptr || cache == nullptr) {
136 return {};
137 }
138 return cache->composite.get(strip);
139}
140
142{
143 if (scene == nullptr || scene->ed == nullptr || strip == nullptr || !result.is_valid()) {
144 return;
145 }
146 IntraFrameCache *&cache = scene->ed->runtime->intra_frame_cache;
147 if (cache == nullptr) {
148 cache = MEM_new<IntraFrameCache>(__func__);
149 }
150 cache->preprocessed.put(strip, result);
151}
152
154{
155 if (scene == nullptr || scene->ed == nullptr || strip == nullptr || !result.is_valid()) {
156 return;
157 }
158 IntraFrameCache *&cache = scene->ed->runtime->intra_frame_cache;
159 if (cache == nullptr) {
160 cache = MEM_new<IntraFrameCache>(__func__);
161 }
162 cache->composite.put(strip, result);
163}
164
166{
168 if (cache != nullptr) {
169 MEM_SAFE_DELETE(scene->ed->runtime->intra_frame_cache);
170 }
171}
172
174 Scene *scene, float frame, int view_id, int width, int height, bool is_render)
175{
177 if (cache != nullptr) {
178 if (cache->timeline_frame != frame || cache->view_id != view_id || cache->width != width ||
179 cache->height != height || cache->is_render != is_render)
180 {
181 cache->timeline_frame = frame;
182 cache->view_id = view_id;
183 cache->width = width;
184 cache->height = height;
185 cache->is_render = is_render;
186 cache->preprocessed.clear();
187 cache->composite.clear();
188 }
189 }
190}
191
192} // namespace blender::seq
SeqResult intra_frame_cache_get_preprocessed(Scene *scene, const Strip *strip)
void intra_frame_cache_invalidate(Scene *scene)
void intra_frame_cache_put_composite(Scene *scene, const Strip *strip, const SeqResult &result)
void intra_frame_cache_set_cur_frame(Scene *scene, float frame, int view_id, int width, int height, bool is_render)
void intra_frame_cache_put_preprocessed(Scene *scene, const Strip *strip, const SeqResult &result)
void intra_frame_cache_destroy(Scene *scene)
static IntraFrameCache * query_intra_frame_cache(Scene *scene)
SeqResult intra_frame_cache_get_composite(Scene *scene, const Strip *strip)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void IMB_refImBuf(ImBuf *ibuf)
void IMB_freeImBuf(ImBuf *ibuf)
seq::EditingRuntime * runtime
struct Editing * ed
IntraFrameCache * intra_frame_cache
bool is_valid() const
Definition render.hh:54
SeqResult get(const Strip *strip) const
Map< const Strip *, SeqResult > map_
void put(const Strip *strip, const SeqResult &result)
void invalidate(const Strip *strip)