Cleanup: VSE: Use cached meta lookup

Some old code used to iterate over all strips to find metas. Use
`seq::lookup_meta_by_strip` instead, since it is cached.

Pull Request: https://projects.blender.org/blender/blender/pulls/136406
This commit is contained in:
Richard Antalik
2025-03-24 19:11:44 +01:00
committed by Richard Antalik
parent 6624cc5634
commit dfea0628c4
14 changed files with 40 additions and 82 deletions

View File

@@ -112,9 +112,7 @@ static Strip *rna_Strip_split(
static Strip *rna_Strip_parent_meta(ID *id, Strip *strip_self)
{
Scene *scene = (Scene *)id;
Editing *ed = blender::seq::editing_get(scene);
return blender::seq::find_metastrip_by_sequence(&ed->seqbase, nullptr, strip_self);
return blender::seq::lookup_meta_by_strip(blender::seq::editing_get(scene), strip_self);
}
static Strip *rna_Strips_new_clip(ID *id,

View File

@@ -63,12 +63,6 @@ void cache_iterate(
void *userdata,
bool callback_init(void *userdata, size_t item_count),
bool callback_iter(void *userdata, Strip *strip, int timeline_frame, int cache_type));
/**
* Return immediate parent meta of sequence.
*/
Strip *find_metastrip_by_sequence(ListBase *seqbase /* = ed->seqbase */,
Strip *meta /* = NULL */,
Strip *strip);
bool exists_in_seqbase(const Strip *strip, const ListBase *seqbase);
} // namespace blender::seq

View File

@@ -132,7 +132,16 @@ Strip *lookup_strip_by_name(Editing *ed, const char *key);
* channel.
*/
Strip *lookup_strip_by_channel_owner(Editing *ed, const SeqTimelineChannel *channel);
/**
* Find meta strip, that contains strip `key`.
* If lookup hash doesn't exist, it will be created. If hash is tagged as invalid, it will be
* rebuilt.
*
* \param key: pointer to Strip inside of meta strip
*
* \return pointer to meta strip
*/
Strip *lookup_meta_by_strip(Editing *ed, const Strip *key);
/**
* Free lookup hash data.
*/

View File

@@ -13,6 +13,7 @@
#include "SEQ_render.hh"
#include "SEQ_time.hh"
#include "SEQ_utils.hh"
#include "SEQ_sequencer.hh"
#include "effects.hh"
#include "render.hh"
@@ -59,7 +60,7 @@ static ImBuf *do_adjustment_impl(const RenderData *context, Strip *strip, float
if (!i) {
Strip *meta;
meta = find_metastrip_by_sequence(&ed->seqbase, nullptr, strip);
meta = lookup_meta_by_strip(ed, strip);
if (meta) {
i = do_adjustment_impl(context, meta, timeline_frame);

View File

@@ -432,7 +432,7 @@ static MetaStack *seq_meta_stack_alloc(const Scene *scene, Strip *strip_meta)
ms->parseq = strip_meta;
/* Reference to previously displayed timeline data. */
Strip *higher_level_meta = SEQ_lookup_meta_by_strip(ed, strip_meta);
Strip *higher_level_meta = lookup_meta_by_strip(ed, strip_meta);
ms->oldbasep = higher_level_meta ? &higher_level_meta->seqbase : &ed->seqbase;
ms->old_channels = higher_level_meta ? &higher_level_meta->channels : &ed->channels;
@@ -460,7 +460,7 @@ void meta_stack_set(const Scene *scene, Strip *dst_seq)
/* Allocate meta stack in a way, that represents meta hierarchy in timeline. */
seq_meta_stack_alloc(scene, dst_seq);
Strip *meta_parent = dst_seq;
while ((meta_parent = SEQ_lookup_meta_by_strip(ed, meta_parent))) {
while ((meta_parent = lookup_meta_by_strip(ed, meta_parent))) {
seq_meta_stack_alloc(scene, meta_parent);
}

View File

@@ -22,16 +22,6 @@ namespace blender::seq {
*/
void seq_free_sequence_recurse(Scene *scene, Strip *strip, bool do_id_user);
StripProxy *seq_strip_proxy_alloc();
/**
* Find meta strip, that contains strip `key`.
* If lookup hash doesn't exist, it will be created. If hash is tagged as invalid, it will be
* rebuilt.
*
* \param key: pointer to Strip inside of meta strip
*
* \return pointer to meta strip
*/
Strip *SEQ_lookup_meta_by_strip(Editing *ed, const Strip *key);
/**
* Find effect strips, that use strip `strip` as one of inputs.
* If lookup hash doesn't exist, it will be created. If hash is tagged as invalid, it will be

View File

@@ -29,10 +29,10 @@
# include "AUD_Sound.h"
#endif
#include "SEQ_sequencer.hh"
#include "SEQ_sound.hh"
#include "SEQ_time.hh"
#include "sequencer.hh"
#include "strip_time.hh"
namespace blender::seq {
@@ -148,7 +148,7 @@ void sound_update(Scene *scene, bSound *sound)
float sound_pitch_get(const Scene *scene, const Strip *strip)
{
const Strip *meta_parent = SEQ_lookup_meta_by_strip(scene->ed, strip);
const Strip *meta_parent = lookup_meta_by_strip(scene->ed, strip);
if (meta_parent != nullptr) {
return strip->speed_factor * sound_pitch_get(scene, meta_parent);
}

View File

@@ -81,7 +81,7 @@ static void strip_add_generic_update(Scene *scene, Strip *strip)
relations_invalidate_cache_composite(scene, strip);
strip_lookup_invalidate(scene->ed);
strip_time_effect_range_set(scene, strip);
time_update_meta_strip_range(scene, SEQ_lookup_meta_by_strip(scene->ed, strip));
time_update_meta_strip_range(scene, lookup_meta_by_strip(scene->ed, strip));
}
static void strip_add_set_name(Scene *scene, Strip *strip, LoadData *load_data)

View File

@@ -129,7 +129,7 @@ Strip *lookup_strip_by_name(Editing *ed, const char *key)
return lookup->strip_by_name.lookup_default(key, nullptr);
}
Strip *SEQ_lookup_meta_by_strip(Editing *ed, const Strip *key)
Strip *lookup_meta_by_strip(Editing *ed, const Strip *key)
{
BLI_assert(ed != nullptr);
std::lock_guard lock(lookup_lock);

View File

@@ -32,6 +32,7 @@
#include "effects/effects.hh"
#include "image_cache.hh"
#include "sequencer.hh"
#include "utils.hh"
namespace blender::seq {
@@ -120,33 +121,14 @@ static void sequence_invalidate_cache(Scene *scene,
}
/* Find meta-strips that contain invalidated_seq and invalidate them. */
static bool strip_relations_find_and_invalidate_metas(Scene *scene,
Strip *invalidated_seq,
Strip *meta_seq)
static void strip_relations_find_and_invalidate_metas(Scene *scene, Strip *strip)
{
ListBase *seqbase;
if (meta_seq == nullptr) {
Editing *ed = editing_get(scene);
seqbase = &ed->seqbase;
}
else {
seqbase = &meta_seq->seqbase;
Strip *meta = lookup_meta_by_strip(editing_get(scene), strip);
if (meta == nullptr) {
return;
}
LISTBASE_FOREACH (Strip *, strip, seqbase) {
if (strip->type == STRIP_TYPE_META) {
if (strip_relations_find_and_invalidate_metas(scene, invalidated_seq, strip)) {
sequence_invalidate_cache(scene, strip, true, SEQ_CACHE_ALL_TYPES);
return true;
}
}
if (strip == invalidated_seq && meta_seq != nullptr) {
sequence_invalidate_cache(scene, meta_seq, true, SEQ_CACHE_ALL_TYPES);
return true;
}
}
return false;
relations_invalidate_cache_raw(scene, meta);
}
void relations_invalidate_cache_in_range(Scene *scene,
@@ -155,13 +137,13 @@ void relations_invalidate_cache_in_range(Scene *scene,
int invalidate_types)
{
seq_cache_cleanup_sequence(scene, strip, range_mask, invalidate_types, true);
strip_relations_find_and_invalidate_metas(scene, strip, nullptr);
strip_relations_find_and_invalidate_metas(scene, strip);
}
void relations_invalidate_cache_raw(Scene *scene, Strip *strip)
{
sequence_invalidate_cache(scene, strip, true, SEQ_CACHE_ALL_TYPES);
strip_relations_find_and_invalidate_metas(scene, strip, nullptr);
strip_relations_find_and_invalidate_metas(scene, strip);
}
void relations_invalidate_cache_preprocessed(Scene *scene, Strip *strip)
@@ -171,7 +153,7 @@ void relations_invalidate_cache_preprocessed(Scene *scene, Strip *strip)
true,
SEQ_CACHE_STORE_PREPROCESSED | SEQ_CACHE_STORE_COMPOSITE |
SEQ_CACHE_STORE_FINAL_OUT);
strip_relations_find_and_invalidate_metas(scene, strip, nullptr);
strip_relations_find_and_invalidate_metas(scene, strip);
}
void relations_invalidate_cache_composite(Scene *scene, Strip *strip)
@@ -182,7 +164,7 @@ void relations_invalidate_cache_composite(Scene *scene, Strip *strip)
sequence_invalidate_cache(
scene, strip, true, SEQ_CACHE_STORE_COMPOSITE | SEQ_CACHE_STORE_FINAL_OUT);
strip_relations_find_and_invalidate_metas(scene, strip, nullptr);
strip_relations_find_and_invalidate_metas(scene, strip);
}
void relations_invalidate_dependent(Scene *scene, Strip *strip)
@@ -193,7 +175,7 @@ void relations_invalidate_dependent(Scene *scene, Strip *strip)
sequence_invalidate_cache(
scene, strip, false, SEQ_CACHE_STORE_COMPOSITE | SEQ_CACHE_STORE_FINAL_OUT);
strip_relations_find_and_invalidate_metas(scene, strip, nullptr);
strip_relations_find_and_invalidate_metas(scene, strip);
}
static void invalidate_scene_strips(Scene *scene, Scene *scene_target, ListBase *seqbase)
@@ -451,22 +433,6 @@ void relations_check_uids_unique_and_report(const Scene *scene)
BLI_gset_free(used_uids, nullptr);
}
Strip *find_metastrip_by_sequence(ListBase *seqbase, Strip *meta, Strip *strip)
{
LISTBASE_FOREACH (Strip *, iseq, seqbase) {
Strip *rval;
if (strip == iseq) {
return meta;
}
if (iseq->seqbase.first && (rval = find_metastrip_by_sequence(&iseq->seqbase, iseq, strip))) {
return rval;
}
}
return nullptr;
}
bool exists_in_seqbase(const Strip *strip, const ListBase *seqbase)
{
LISTBASE_FOREACH (Strip *, strip_test, seqbase) {

View File

@@ -150,7 +150,7 @@ void retiming_reset(Scene *scene, Strip *strip)
blender::Span<Strip *> effects = SEQ_lookup_effects_by_strip(scene->ed, strip);
strip_time_update_effects_strip_range(scene, effects);
time_update_meta_strip_range(scene, SEQ_lookup_meta_by_strip(scene->ed, strip));
time_update_meta_strip_range(scene, lookup_meta_by_strip(scene->ed, strip));
retiming_key_overlap(scene, strip);
}
@@ -776,7 +776,7 @@ void retiming_key_timeline_frame_set(const Scene *scene,
blender::Span<Strip *> effects = SEQ_lookup_effects_by_strip(scene->ed, strip);
strip_time_update_effects_strip_range(scene, effects);
time_update_meta_strip_range(scene, SEQ_lookup_meta_by_strip(scene->ed, strip));
time_update_meta_strip_range(scene, lookup_meta_by_strip(scene->ed, strip));
}
float retiming_key_speed_get(const Strip *strip, const SeqRetimingKey *key)
@@ -1036,7 +1036,7 @@ static RetimingRangeData strip_retiming_range_data_get(const Scene *scene, const
{
RetimingRangeData strip_retiming_data = RetimingRangeData(strip);
const Strip *meta_parent = SEQ_lookup_meta_by_strip(scene->ed, strip);
const Strip *meta_parent = lookup_meta_by_strip(scene->ed, strip);
if (meta_parent == nullptr) {
return strip_retiming_data;
}

View File

@@ -185,7 +185,7 @@ void time_update_meta_strip_range(const Scene *scene, Strip *strip_meta)
strip_update_sound_bounds_recursive(scene, strip_meta);
blender::Span<Strip *> effects = SEQ_lookup_effects_by_strip(scene->ed, strip_meta);
strip_time_update_effects_strip_range(scene, effects);
time_update_meta_strip_range(scene, SEQ_lookup_meta_by_strip(scene->ed, strip_meta));
time_update_meta_strip_range(scene, lookup_meta_by_strip(scene->ed, strip_meta));
}
void strip_time_effect_range_set(const Scene *scene, Strip *strip)
@@ -470,7 +470,7 @@ void time_start_frame_set(const Scene *scene, Strip *strip, int timeline_frame)
strip->start = timeline_frame;
blender::Span<Strip *> effects = SEQ_lookup_effects_by_strip(scene->ed, strip);
strip_time_update_effects_strip_range(scene, effects);
time_update_meta_strip_range(scene, SEQ_lookup_meta_by_strip(scene->ed, strip));
time_update_meta_strip_range(scene, lookup_meta_by_strip(scene->ed, strip));
}
float time_content_end_frame_get(const Scene *scene, const Strip *strip)
@@ -520,7 +520,7 @@ void time_left_handle_frame_set(const Scene *scene, Strip *strip, int timeline_f
blender::Span<Strip *> effects = SEQ_lookup_effects_by_strip(scene->ed, strip);
strip_time_update_effects_strip_range(scene, effects);
time_update_meta_strip_range(scene, SEQ_lookup_meta_by_strip(scene->ed, strip));
time_update_meta_strip_range(scene, lookup_meta_by_strip(scene->ed, strip));
}
void time_right_handle_frame_set(const Scene *scene, Strip *strip, int timeline_frame)
@@ -536,7 +536,7 @@ void time_right_handle_frame_set(const Scene *scene, Strip *strip, int timeline_
blender::Span<Strip *> effects = SEQ_lookup_effects_by_strip(scene->ed, strip);
strip_time_update_effects_strip_range(scene, effects);
time_update_meta_strip_range(scene, SEQ_lookup_meta_by_strip(scene->ed, strip));
time_update_meta_strip_range(scene, lookup_meta_by_strip(scene->ed, strip));
}
void strip_time_translate_handles(const Scene *scene, Strip *strip, const int offset)
@@ -548,7 +548,7 @@ void strip_time_translate_handles(const Scene *scene, Strip *strip, const int of
blender::Span<Strip *> effects = SEQ_lookup_effects_by_strip(scene->ed, strip);
strip_time_update_effects_strip_range(scene, effects);
time_update_meta_strip_range(scene, SEQ_lookup_meta_by_strip(scene->ed, strip));
time_update_meta_strip_range(scene, lookup_meta_by_strip(scene->ed, strip));
}
static void strip_time_slip_strip_ex(

View File

@@ -92,7 +92,7 @@ void transform_translate_sequence(Scene *evil_scene, Strip *strip, int delta)
offset_animdata(evil_scene, strip, delta);
blender::Span<Strip *> effects = SEQ_lookup_effects_by_strip(evil_scene->ed, strip);
strip_time_update_effects_strip_range(evil_scene, effects);
time_update_meta_strip_range(evil_scene, SEQ_lookup_meta_by_strip(evil_scene->ed, strip));
time_update_meta_strip_range(evil_scene, lookup_meta_by_strip(evil_scene->ed, strip));
}
bool transform_seqbase_shuffle_ex(ListBase *seqbasep,

View File

@@ -367,7 +367,7 @@ ListBase *get_seqbase_by_seq(const Scene *scene, Strip *strip)
{
Editing *ed = editing_get(scene);
ListBase *main_seqbase = &ed->seqbase;
Strip *strip_meta = SEQ_lookup_meta_by_strip(ed, strip);
Strip *strip_meta = lookup_meta_by_strip(ed, strip);
if (strip_meta != nullptr) {
return &strip_meta->seqbase;