Blender V5.0
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 "intra_frame_cache.hh"
17
18namespace blender::seq {
19
22 ImBuf *get(const Strip *strip) const;
23 void put(const Strip *strip, ImBuf *image);
24 void invalidate(const Strip *strip);
25 void clear();
26};
27
31 float timeline_frame = -1.0f;
32 int view_id = -1;
33 int width = -1;
34 int height = -1;
35
37 {
38 preprocessed.clear();
39 composite.clear();
40 }
41};
42
44{
45 if (scene == nullptr || scene->ed == nullptr) {
46 return nullptr;
47 }
48 return scene->ed->runtime.intra_frame_cache;
49}
50
52{
54 if (cache != nullptr) {
55 cache->preprocessed.clear();
56 cache->composite.clear();
57 cache->timeline_frame = -1.0f;
58 cache->view_id = -1;
59 cache->width = -1;
60 cache->height = -1;
61 }
62}
63
64void intra_frame_cache_invalidate(Scene *scene, const Strip *strip)
65{
66 if (strip == nullptr) {
67 return;
68 }
70 if (cache != nullptr) {
71 cache->preprocessed.invalidate(strip);
72 cache->composite.invalidate(strip);
73 }
74}
75
77{
78 /* Invalidate this strip, and all strips that are above it. */
79 for (auto it = this->map_.items().begin(); it != this->map_.items().end(); it++) {
80 const Strip *key = (*it).key;
81 if (key == strip || key->channel >= strip->channel) {
82 IMB_freeImBuf((*it).value);
83 this->map_.remove(it);
84 }
85 }
86}
87
88ImBuf *StripImageMap::get(const Strip *strip) const
89{
90 ImBuf *image = this->map_.lookup_default(strip, nullptr);
91 if (image != nullptr) {
92 IMB_refImBuf(image);
93 }
94 return image;
95}
96
97void StripImageMap::put(const Strip *strip, ImBuf *image)
98{
99 BLI_assert(strip != nullptr);
100 if (image == nullptr) {
101 return;
102 }
103 ImBuf *existing = this->map_.lookup_default(strip, nullptr);
104 if (existing != nullptr) {
105 IMB_freeImBuf(existing);
106 }
107 this->map_.add_overwrite(strip, image);
108 IMB_refImBuf(image);
109}
110
112{
113 for (const auto &item : this->map_.items()) {
114 IMB_freeImBuf(item.value);
115 }
116 this->map_.clear();
117}
118
120{
122 if (strip == nullptr || cache == nullptr) {
123 return nullptr;
124 }
125 return cache->preprocessed.get(strip);
126}
127
129{
131 if (strip == nullptr || cache == nullptr) {
132 return nullptr;
133 }
134 return cache->composite.get(strip);
135}
136
137void intra_frame_cache_put_preprocessed(Scene *scene, const Strip *strip, ImBuf *image)
138{
139 if (scene == nullptr || scene->ed == nullptr || strip == nullptr || image == nullptr) {
140 return;
141 }
143 if (cache == nullptr) {
144 cache = MEM_new<IntraFrameCache>(__func__);
145 }
146 cache->preprocessed.put(strip, image);
147}
148
149void intra_frame_cache_put_composite(Scene *scene, const Strip *strip, ImBuf *image)
150{
151 if (scene == nullptr || scene->ed == nullptr || strip == nullptr || image == nullptr) {
152 return;
153 }
155 if (cache == nullptr) {
156 cache = MEM_new<IntraFrameCache>(__func__);
157 }
158 cache->composite.put(strip, image);
159}
160
162{
164 if (cache != nullptr) {
165 MEM_SAFE_DELETE(scene->ed->runtime.intra_frame_cache);
166 }
167}
168
169void intra_frame_cache_set_cur_frame(Scene *scene, float frame, int view_id, int width, int height)
170{
172 if (cache != nullptr) {
173 if (cache->timeline_frame != frame || cache->view_id != view_id || cache->width != width ||
174 cache->height != height)
175 {
176 cache->timeline_frame = frame;
177 cache->view_id = view_id;
178 cache->width = width;
179 cache->height = height;
180 cache->preprocessed.clear();
181 cache->composite.clear();
182 }
183 }
184}
185
186} // namespace blender::seq
#define BLI_assert(a)
Definition BLI_assert.h:46
void IMB_freeImBuf(ImBuf *ibuf)
void IMB_refImBuf(ImBuf *ibuf)
SIMD_FORCE_INLINE void invalidate()
void intra_frame_cache_set_cur_frame(Scene *scene, float frame, int view_id, int width, int height)
void intra_frame_cache_invalidate(Scene *scene)
ImBuf * intra_frame_cache_get_composite(Scene *scene, const Strip *strip)
ImBuf * intra_frame_cache_get_preprocessed(Scene *scene, const Strip *strip)
void intra_frame_cache_destroy(Scene *scene)
void intra_frame_cache_put_composite(Scene *scene, const Strip *strip, ImBuf *image)
static IntraFrameCache * query_intra_frame_cache(Scene *scene)
void intra_frame_cache_put_preprocessed(Scene *scene, const Strip *strip, ImBuf *image)
IntraFrameCache * intra_frame_cache
EditingRuntime runtime
struct Editing * ed
void put(const Strip *strip, ImBuf *image)
void invalidate(const Strip *strip)
ImBuf * get(const Strip *strip) const
Map< const Strip *, ImBuf * > map_