[Bf-blender-cvs] [f49d438ced7] master: Cleanup and remove SEQ_ALL_BEGIN macro

Sebastian Parborg noreply at git.blender.org
Wed Aug 25 17:41:47 CEST 2021


Commit: f49d438ced7c5874dbf43976d9901a462176f541
Author: Sebastian Parborg
Date:   Fri Aug 20 16:30:34 2021 +0200
Branches: master
https://developer.blender.org/rBf49d438ced7c5874dbf43976d9901a462176f541

Cleanup and remove SEQ_ALL_BEGIN macro

We now use a for_each function with callback to iterate through all sequences in the scene.

This has the benefit that we now only loop over the sequences in the scene once.
Before we would loop over them twice and allocate memory to store temporary data.

The allocation of temporary data lead to unintentional memory leaks if the code used returns to exit out of the iteration loop.
The new for_each callback method doesn't allocate any temporary data and only iterates though all sequences once.

Reviewed By: Richard Antalik, Bastien Montagne

Differential Revision: http://developer.blender.org/D12278

===================================================================

M	source/blender/blenkernel/BKE_scene.h
M	source/blender/blenkernel/intern/bpath.c
M	source/blender/blenkernel/intern/ipo.c
M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_250.c
M	source/blender/blenloader/intern/versioning_260.c
M	source/blender/blenloader/intern/versioning_270.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/blenloader/intern/versioning_legacy.c
M	source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
M	source/blender/depsgraph/intern/builder/deg_builder_relations.cc
M	source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_sequencer.cc
M	source/blender/editors/sound/sound_ops.c
M	source/blender/editors/space_sequencer/sequencer_edit.c
M	source/blender/imbuf/intern/colormanagement.c
M	source/blender/makesrna/intern/rna_color.c
M	source/blender/makesrna/intern/rna_sequencer.c
M	source/blender/sequencer/SEQ_iterator.h
M	source/blender/sequencer/SEQ_sequencer.h
M	source/blender/sequencer/SEQ_utils.h
M	source/blender/sequencer/intern/clipboard.c
M	source/blender/sequencer/intern/iterator.c
M	source/blender/sequencer/intern/proxy.c
M	source/blender/sequencer/intern/sequencer.c
M	source/blender/sequencer/intern/sequencer.h
M	source/blender/sequencer/intern/strip_relations.c
M	source/blender/sequencer/intern/utils.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h
index 83ce5e72794..f3edf8e9f64 100644
--- a/source/blender/blenkernel/BKE_scene.h
+++ b/source/blender/blenkernel/BKE_scene.h
@@ -264,14 +264,6 @@ void BKE_scene_cursor_from_mat4(struct View3DCursor *cursor,
                                 const float mat[4][4],
                                 bool use_compat);
 
-/* Dependency graph evaluation. */
-
-/* Evaluate parts of sequences which needs to be done as a part of a dependency graph evaluation.
- * This does NOT include actual rendering of the strips, but rather makes them up-to-date for
- * animation playback and makes them ready for the sequencer's rendering pipeline to render them.
- */
-void BKE_scene_eval_sequencer_sequences(struct Depsgraph *depsgraph, struct Scene *scene);
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/bpath.c b/source/blender/blenkernel/intern/bpath.c
index 70274de8bff..1684e22dece 100644
--- a/source/blender/blenkernel/intern/bpath.c
+++ b/source/blender/blenkernel/intern/bpath.c
@@ -534,6 +534,46 @@ static bool rewrite_path_alloc(char **path,
   return false;
 }
 
+typedef struct Seq_callback_data {
+  const char *absbase;
+  void *bpath_user_data;
+  BPathVisitor visit_cb;
+  const int flag;
+} Seq_callback_data;
+
+static bool seq_rewrite_path_callback(Sequence *seq, void *user_data)
+{
+  if (SEQ_HAS_PATH(seq)) {
+    StripElem *se = seq->strip->stripdata;
+    Seq_callback_data *cd = (Seq_callback_data *)user_data;
+
+    if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM) && se) {
+      rewrite_path_fixed_dirfile(
+          seq->strip->dir, se->name, cd->visit_cb, cd->absbase, cd->bpath_user_data);
+    }
+    else if ((seq->type == SEQ_TYPE_IMAGE) && se) {
+      /* might want an option not to loop over all strips */
+      unsigned int len = (unsigned int)MEM_allocN_len(se) / (unsigned int)sizeof(*se);
+      unsigned int i;
+
+      if (cd->flag & BKE_BPATH_TRAVERSE_SKIP_MULTIFILE) {
+        /* only operate on one path */
+        len = MIN2(1u, len);
+      }
+
+      for (i = 0; i < len; i++, se++) {
+        rewrite_path_fixed_dirfile(
+            seq->strip->dir, se->name, cd->visit_cb, cd->absbase, cd->bpath_user_data);
+      }
+    }
+    else {
+      /* simple case */
+      rewrite_path_fixed(seq->strip->dir, cd->visit_cb, cd->absbase, cd->bpath_user_data);
+    }
+  }
+  return true;
+}
+
 /**
  * Run visitor function 'visit' on all paths contained in 'id'.
  */
@@ -701,38 +741,8 @@ void BKE_bpath_traverse_id(
     case ID_SCE: {
       Scene *scene = (Scene *)id;
       if (scene->ed) {
-        Sequence *seq;
-
-        SEQ_ALL_BEGIN (scene->ed, seq) {
-          if (SEQ_HAS_PATH(seq)) {
-            StripElem *se = seq->strip->stripdata;
-
-            if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM) && se) {
-              rewrite_path_fixed_dirfile(
-                  seq->strip->dir, se->name, visit_cb, absbase, bpath_user_data);
-            }
-            else if ((seq->type == SEQ_TYPE_IMAGE) && se) {
-              /* might want an option not to loop over all strips */
-              unsigned int len = (unsigned int)MEM_allocN_len(se) / (unsigned int)sizeof(*se);
-              unsigned int i;
-
-              if (flag & BKE_BPATH_TRAVERSE_SKIP_MULTIFILE) {
-                /* only operate on one path */
-                len = MIN2(1u, len);
-              }
-
-              for (i = 0; i < len; i++, se++) {
-                rewrite_path_fixed_dirfile(
-                    seq->strip->dir, se->name, visit_cb, absbase, bpath_user_data);
-              }
-            }
-            else {
-              /* simple case */
-              rewrite_path_fixed(seq->strip->dir, visit_cb, absbase, bpath_user_data);
-            }
-          }
-        }
-        SEQ_ALL_END;
+        Seq_callback_data user_data = {absbase, bpath_user_data, visit_cb, flag};
+        SEQ_for_each_callback(&scene->ed->seqbase, seq_rewrite_path_callback, &user_data);
       }
       break;
     }
diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c
index 8a70f065e40..aac081991e3 100644
--- a/source/blender/blenkernel/intern/ipo.c
+++ b/source/blender/blenkernel/intern/ipo.c
@@ -2038,6 +2038,58 @@ static void nlastrips_to_animdata(ID *id, ListBase *strips)
   }
 }
 
+typedef struct Seq_callback_data {
+  Main *bmain;
+  Scene *scene;
+  AnimData *adt;
+} Seq_callback_data;
+
+static bool seq_convert_callback(Sequence *seq, void *userdata)
+{
+  IpoCurve *icu = (seq->ipo) ? seq->ipo->curve.first : NULL;
+  short adrcode = SEQ_FAC1;
+
+  if (G.debug & G_DEBUG) {
+    printf("\tconverting sequence strip %s\n", seq->name + 2);
+  }
+
+  if (ELEM(NULL, seq->ipo, icu)) {
+    seq->flag |= SEQ_USE_EFFECT_DEFAULT_FADE;
+    return true;
+  }
+
+  /* patch adrcode, so that we can map
+   * to different DNA variables later
+   * (semi-hack (tm) )
+   */
+  switch (seq->type) {
+    case SEQ_TYPE_IMAGE:
+    case SEQ_TYPE_META:
+    case SEQ_TYPE_SCENE:
+    case SEQ_TYPE_MOVIE:
+    case SEQ_TYPE_COLOR:
+      adrcode = SEQ_FAC_OPACITY;
+      break;
+    case SEQ_TYPE_SPEED:
+      adrcode = SEQ_FAC_SPEED;
+      break;
+  }
+  icu->adrcode = adrcode;
+
+  Seq_callback_data *cd = (Seq_callback_data *)userdata;
+
+  /* convert IPO */
+  ipo_to_animdata(cd->bmain, (ID *)cd->scene, seq->ipo, NULL, NULL, seq);
+
+  if (cd->adt->action) {
+    cd->adt->action->idroot = ID_SCE; /* scene-rooted */
+  }
+
+  id_us_min(&seq->ipo->id);
+  seq->ipo = NULL;
+  return true;
+}
+
 /* *************************************************** */
 /* External API - Only Called from do_versions() */
 
@@ -2286,52 +2338,8 @@ void do_versions_ipos_to_animato(Main *bmain)
     Scene *scene = (Scene *)id;
     Editing *ed = scene->ed;
     if (ed && ed->seqbasep) {
-      Sequence *seq;
-
-      AnimData *adt = BKE_animdata_ensure_id(id);
-
-      SEQ_ALL_BEGIN (ed, seq) {
-        IpoCurve *icu = (seq->ipo) ? seq->ipo->curve.first : NULL;
-        short adrcode = SEQ_FAC1;
-
-        if (G.debug & G_DEBUG) {
-          printf("\tconverting sequence strip %s\n", seq->name + 2);
-        }
-
-        if (ELEM(NULL, seq->ipo, icu)) {
-          seq->flag |= SEQ_USE_EFFECT_DEFAULT_FADE;
-          continue;
-        }
-
-        /* patch adrcode, so that we can map
-         * to different DNA variables later
-         * (semi-hack (tm) )
-         */
-        switch (seq->type) {
-          case SEQ_TYPE_IMAGE:
-          case SEQ_TYPE_META:
-          case SEQ_TYPE_SCENE:
-          case SEQ_TYPE_MOVIE:
-          case SEQ_TYPE_COLOR:
-            adrcode = SEQ_FAC_OPACITY;
-            break;
-          case SEQ_TYPE_SPEED:
-            adrcode = SEQ_FAC_SPEED;
-            break;
-        }
-        icu->adrcode = adrcode;
-
-        /* convert IPO */
-        ipo_to_animdata(bmain, (ID *)scene, seq->ipo, NULL, NULL, seq);
-
-        if (adt->action) {
-          adt->action->idroot = ID_SCE; /* scene-rooted */
-        }
-
-        id_us_min(&seq->ipo->id);
-        seq->ipo = NULL;
-      }
-      SEQ_ALL_END;
+      Seq_callback_data cb_data = {bmain, scene, BKE_animdata_ensure_id(id)};
+      SEQ_for_each_callback(&ed->seqbase, seq_convert_callback, &cb_data);
     }
   }
 
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 5a668746956..de82f0832d8 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -113,11 +113,7 @@
 
 #include "SEQ_edit.h"
 #include "SEQ_iterator.h"
-#include "SEQ_modifier.h"
-#include "SEQ_proxy.h"
-#include "SEQ_relations.h"
 #include "SEQ_sequencer.h"
-#include "SEQ_sound.h"
 
 #include "BLO_read_write.h"
 
@@ -702,6 +698,40 @@ static void scene_foreach_layer_collection(LibraryForeachIDData *data, ListBase
   }
 }
 
+static bool seq_foreach_member_id_cb(Sequence *seq, void *user_data)
+{
+  LibraryForeachIDData *data = (LibraryForeachIDData *)user_data;
+
+#define FOREACHID_PROCESS(_data, _id_super, _cb_flag) \
+  { \
+    CHECK_TYPE(&((_id_super)->id), ID *); \
+    if (!BKE_lib_query_foreachid_process((_data), (ID **)&(_id_super), (_cb_flag))) { \
+      return false; \
+    } \
+  } \
+  ((void)0)
+
+  FOREACHID_PROCESS(data, seq->scene, IDWALK_CB_NEVER_SELF);
+  FOREACHID_PROCESS(data, seq->scene_camera, IDWALK_CB_NOP);
+  FOREACHID_PROCESS(data, seq->clip, IDWALK_CB_USER);
+  FOREACHID_PROCESS(data, seq->mask, IDWALK_CB_USER);
+  FOREACHID_PROCESS(data, seq->sound, IDWALK_CB_USER);
+  IDP_foreach_property(
+      seq->prop, IDP_TYPE_FILTER_ID, BKE_lib_query_idpropertiesForeachIDLink_callback, data);
+  LISTBASE_FOREACH (SequenceModifierData *, smd, &seq->modifiers) {
+    FOREACHID_PROCESS(data, smd->mask_id, IDWALK_CB_USER);
+  }
+
+  if (seq->type == SEQ_TYPE_TEXT && seq->effectdata) {
+    TextVars *text_data = seq->effectdata;
+    FOREACHID_PROCESS(data, text_data->text_font, IDWALK_CB_USER);
+  }
+
+#undef FOREACHID_PROCESS
+
+  return true;
+}
+
 static void scene_foreach_id(ID *id, LibraryForeachIDData *data)
 {
   Scene *scene = (Scene *)id;
@@ -717,25 +747,7 @@ static void scene_foreach_id(ID *id, LibraryForeachIDData *data)
     BKE_library_foreach_ID_embedded(data, (ID **)&scene->nodetree);
   }
   if (scene->ed) {
-    Sequence *seq;
-    SEQ_ALL_BEGIN (scene->ed, seq) {
-      BKE_LIB_FOREACHID_PROCESS(data, seq->scene, IDWALK_CB_NEVER_SELF);
-      BKE_LIB_FOREACHID_PROCESS(data, seq->scene_camera, IDWALK_CB_NOP);
-      BKE_LIB_FOREACHID_PROCESS(data, seq->clip, IDWALK_CB_USER);
-      BKE_LIB_FOREACHID_PROCESS(data, seq->mask, IDWALK_CB_USER);
-      BKE_LIB_FOREACHID_PROCESS(data, seq->sound, IDWALK_CB_USER);
-      IDP_foreach_property(
-          seq->prop, IDP_TYPE_FILTER_ID, BKE_lib_query_idpropertiesForeachIDLink_callback, data);
-      LISTBASE_FOREACH (SequenceModifierData *, smd, &seq->modifiers) {
-        BKE_LIB_FOREACHID_PROCESS(data, smd->mask_id, IDWALK_CB_USER);
-      }
-
-      if (seq->type == SEQ_TYPE_TEXT && seq->effectdata) {
-        TextVars *text_data = seq->effectdata;
-        BKE_LIB_FOREACHID_PROCESS(data, text_data->text_font, IDWALK_CB_USER);
-   

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list