[Bf-blender-cvs] [1a5fa2b319e] master: VSE: Improve animation evaluation performance
Richard Antalik
noreply at git.blender.org
Wed Jun 16 00:33:06 CEST 2021
Commit: 1a5fa2b319e06ebbd2666987aa11240a371dcc09
Author: Richard Antalik
Date: Wed Jun 16 00:29:17 2021 +0200
Branches: master
https://developer.blender.org/rB1a5fa2b319e06ebbd2666987aa11240a371dcc09
VSE: Improve animation evaluation performance
Use lookup string callback function for `sequences_all` RNA property
`rna_SequenceEditor_sequences_all_lookup_string` using a GHash for faster lookups.
When names are changed or strips are added/removed the lookup is tagged invalid.
The next time the lookup is used it will rebuild it.
Reviewed By: sergey, jbakker
Differential Revision: https://developer.blender.org/D11544
===================================================================
M source/blender/blenkernel/intern/scene.c
M source/blender/blenloader/intern/versioning_280.c
M source/blender/editors/space_sequencer/sequencer_edit.c
M source/blender/makesdna/DNA_sequence_types.h
M source/blender/makesrna/intern/rna_sequencer.c
M source/blender/sequencer/CMakeLists.txt
M source/blender/sequencer/SEQ_edit.h
M source/blender/sequencer/SEQ_sequencer.h
M source/blender/sequencer/SEQ_utils.h
A source/blender/sequencer/intern/sequence_lookup.c
M source/blender/sequencer/intern/sequencer.c
M source/blender/sequencer/intern/strip_add.c
M source/blender/sequencer/intern/strip_edit.c
M source/blender/sequencer/intern/utils.c
===================================================================
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 86d4c03d51a..2a5a2bf93a1 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -1145,6 +1145,7 @@ static void scene_blend_read_data(BlendDataReader *reader, ID *id)
BLO_read_data_address(reader, &ed->act_seq);
ed->cache = NULL;
ed->prefetch_job = NULL;
+ ed->runtime.sequence_lookup = NULL;
/* recursive link sequences, lb will be correctly initialized */
link_recurs_seq(reader, &ed->seqbase);
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index cf8f45ca227..c9f0cb62fcb 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -1785,7 +1785,7 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports))
static void do_versions_seq_unique_name_all_strips(Scene *sce, ListBase *seqbasep)
{
for (Sequence *seq = seqbasep->first; seq != NULL; seq = seq->next) {
- SEQ_sequence_base_unique_name_recursive(&sce->ed->seqbase, seq);
+ SEQ_sequence_base_unique_name_recursive(sce, &sce->ed->seqbase, seq);
if (seq->seqbase.first != NULL) {
do_versions_seq_unique_name_all_strips(sce, &seq->seqbase);
}
diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c
index b8134095492..42e2a2e5549 100644
--- a/source/blender/editors/space_sequencer/sequencer_edit.c
+++ b/source/blender/editors/space_sequencer/sequencer_edit.c
@@ -1983,7 +1983,7 @@ static int sequencer_meta_make_exec(bContext *C, wmOperator *op)
seqm->machine = active_seq ? active_seq->machine : channel_max;
strcpy(seqm->name + 2, "MetaStrip");
- SEQ_sequence_base_unique_name_recursive(&ed->seqbase, seqm);
+ SEQ_sequence_base_unique_name_recursive(scene, &ed->seqbase, seqm);
seqm->start = meta_start_frame;
seqm->len = meta_end_frame - meta_start_frame;
SEQ_time_update_sequence(scene, seqm);
diff --git a/source/blender/makesdna/DNA_sequence_types.h b/source/blender/makesdna/DNA_sequence_types.h
index 7e0bf81457d..fe793875d67 100644
--- a/source/blender/makesdna/DNA_sequence_types.h
+++ b/source/blender/makesdna/DNA_sequence_types.h
@@ -45,6 +45,7 @@ struct MovieClip;
struct Scene;
struct VFont;
struct bSound;
+struct SequenceLookup;
/* strlens; 256= FILE_MAXFILE, 768= FILE_MAXDIR */
@@ -257,6 +258,10 @@ typedef struct MetaStack {
int disp_range[2];
} MetaStack;
+typedef struct EditingRuntime {
+ struct SequenceLookup *sequence_lookup;
+} EditingRuntime;
+
typedef struct Editing {
/** Pointer to the current list of seq's being edited (can be within a meta strip). */
ListBase *seqbasep;
@@ -287,6 +292,8 @@ typedef struct Editing {
/* Must be initialized only by seq_cache_create() */
int64_t disk_cache_timestamp;
+
+ EditingRuntime runtime;
} Editing;
/* ************* Effect Variable Structs ********* */
diff --git a/source/blender/makesrna/intern/rna_sequencer.c b/source/blender/makesrna/intern/rna_sequencer.c
index 2652003cb1c..29100cd7658 100644
--- a/source/blender/makesrna/intern/rna_sequencer.c
+++ b/source/blender/makesrna/intern/rna_sequencer.c
@@ -94,6 +94,8 @@ const EnumPropertyItem rna_enum_sequence_modifier_type_items[] = {
# include "IMB_imbuf.h"
+# include "SEQ_edit.h"
+
typedef struct SequenceSearchData {
Sequence *seq;
void *data;
@@ -243,6 +245,21 @@ static void rna_SequenceEditor_sequences_all_next(CollectionPropertyIterator *it
iter->valid = (internal->link != NULL);
}
+static int rna_SequenceEditor_sequences_all_lookup_string(PointerRNA *ptr,
+ const char *key,
+ PointerRNA *r_ptr)
+{
+ ID *id = ptr->owner_id;
+ Scene *scene = (Scene *)id;
+
+ Sequence *seq = SEQ_sequence_lookup_by_name(scene, key);
+ if (seq) {
+ RNA_pointer_create(ptr->owner_id, &RNA_Sequence, seq, r_ptr);
+ return true;
+ }
+ return false;
+}
+
/* internal use */
static int rna_SequenceEditor_elements_length(PointerRNA *ptr)
{
@@ -627,11 +644,10 @@ static void rna_Sequence_name_set(PointerRNA *ptr, const char *value)
BLI_strncpy(oldname, seq->name + 2, sizeof(seq->name) - 2);
/* copy the new name into the name slot */
- BLI_strncpy_utf8(seq->name + 2, value, sizeof(seq->name) - 2);
+ SEQ_edit_sequence_name_set(scene, seq, value);
/* make sure the name is unique */
- SEQ_sequence_base_unique_name_recursive(&scene->ed->seqbase, seq);
-
+ SEQ_sequence_base_unique_name_recursive(scene, &scene->ed->seqbase, seq);
/* fix all the animation data which may link to this */
/* Don't rename everywhere because these are per scene. */
@@ -1997,7 +2013,7 @@ static void rna_def_editor(BlenderRNA *brna)
NULL,
NULL,
NULL,
- NULL,
+ "rna_SequenceEditor_sequences_all_lookup_string",
NULL);
prop = RNA_def_property(srna, "meta_stack", PROP_COLLECTION, PROP_NONE);
diff --git a/source/blender/sequencer/CMakeLists.txt b/source/blender/sequencer/CMakeLists.txt
index 2b402b4750f..9340cfbf03d 100644
--- a/source/blender/sequencer/CMakeLists.txt
+++ b/source/blender/sequencer/CMakeLists.txt
@@ -79,6 +79,7 @@ set(SRC
intern/render.h
intern/sequencer.c
intern/sequencer.h
+ intern/sequence_lookup.c
intern/sound.c
intern/strip_add.c
intern/strip_edit.c
diff --git a/source/blender/sequencer/SEQ_edit.h b/source/blender/sequencer/SEQ_edit.h
index 2711e0a7ee3..6d043dffe72 100644
--- a/source/blender/sequencer/SEQ_edit.h
+++ b/source/blender/sequencer/SEQ_edit.h
@@ -58,6 +58,8 @@ bool SEQ_edit_remove_gaps(struct Scene *scene,
struct ListBase *seqbase,
const int initial_frame,
const bool remove_all_gaps);
+void SEQ_edit_sequence_name_set(struct Scene *scene, struct Sequence *seq, const char *new_name);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/sequencer/SEQ_sequencer.h b/source/blender/sequencer/SEQ_sequencer.h
index ad0815892f7..fd4181a5a54 100644
--- a/source/blender/sequencer/SEQ_sequencer.h
+++ b/source/blender/sequencer/SEQ_sequencer.h
@@ -33,6 +33,7 @@ struct Editing;
struct Scene;
struct Sequence;
struct SequencerToolSettings;
+struct SequenceLookup;
/* RNA enums, just to be more readable */
enum {
@@ -79,6 +80,16 @@ void SEQ_sequence_base_dupli_recursive(const struct Scene *scene_src,
int dupe_flag,
const int flag);
+/* Defined in sequence_lookup.c */
+
+typedef enum eSequenceLookupTag {
+ SEQ_LOOKUP_TAG_INVALID = (1 << 0),
+} eSequenceLookupTag;
+
+struct Sequence *SEQ_sequence_lookup_by_name(const struct Scene *scene, const char *key);
+void SEQ_sequence_lookup_free(const struct Scene *scene);
+void SEQ_sequence_lookup_tag(const struct Scene *scene, eSequenceLookupTag tag);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/sequencer/SEQ_utils.h b/source/blender/sequencer/SEQ_utils.h
index a4dc80d75db..432e8fdd0c0 100644
--- a/source/blender/sequencer/SEQ_utils.h
+++ b/source/blender/sequencer/SEQ_utils.h
@@ -36,7 +36,9 @@ struct Sequence;
struct StripElem;
void SEQ_sort(struct ListBase *seqbase);
-void SEQ_sequence_base_unique_name_recursive(struct ListBase *seqbasep, struct Sequence *seq);
+void SEQ_sequence_base_unique_name_recursive(struct Scene *scene,
+ struct ListBase *seqbasep,
+ struct Sequence *seq);
const char *SEQ_sequence_give_name(struct Sequence *seq);
struct ListBase *SEQ_get_seqbase_from_sequence(struct Sequence *seq, int *r_offset);
const struct Sequence *SEQ_get_topmost_sequence(const struct Scene *scene, int frame);
diff --git a/source/blender/sequencer/intern/sequence_lookup.c b/source/blender/sequencer/intern/sequence_lookup.c
new file mode 100644
index 00000000000..72567dc394e
--- /dev/null
+++ b/source/blender/sequencer/intern/sequence_lookup.c
@@ -0,0 +1,161 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup sequencer
+ */
+
+#include "SEQ_sequencer.h"
+
+#include "DNA_listBase.h"
+#include "DNA_scene_types.h"
+#include "DNA_sequence_types.h"
+
+#include "SEQ_iterator.h"
+
+#include "BLI_ghash.h"
+#include "BLI_string.h"
+#include "BLI_sys_types.h"
+#include "BLI_threads.h"
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+static ThreadMutex lookup_lock = BLI_MUTEX_INITIALIZER;
+
+typedef struct SequenceLookup {
+ GHash *by_name;
+ eSequenceLookupTag tag;
+} SequenceLookup;
+
+static void seq_sequence_lookup_init(struct SequenceLookup *lookup)
+{
+ lookup->by_name = BLI_ghash_str_new(__func__);
+ lookup->tag |= SEQ_LOOKUP_TAG_INVALID;
+}
+
+static void seq_sequence_lookup_build(const struct Scene *scene, struct SequenceLookup *lookup)
+{
+ SeqCollection *all_strips = SEQ_query_all_strips_recursive(&scene->ed->seqbase);
+ Sequence *seq;
+ SEQ_ITERATOR_FOREACH (seq, all_strips) {
+ BLI_ghash_insert(lookup->by_name, seq->name + 2, seq);
+ }
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list