[Bf-blender-cvs] [af5a4034b9b] node-tree-update-refactor: unify update a bit

Jacques Lucke noreply at git.blender.org
Mon Nov 15 19:09:20 CET 2021


Commit: af5a4034b9b7bfa029c744cb6c99c577d6ad3ddd
Author: Jacques Lucke
Date:   Thu Nov 11 12:05:47 2021 +0100
Branches: node-tree-update-refactor
https://developer.blender.org/rBaf5a4034b9b7bfa029c744cb6c99c577d6ad3ddd

unify update a bit

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

M	source/blender/editors/include/ED_node.h
M	source/blender/editors/space_node/drawnode.cc
M	source/blender/editors/space_node/node_add.cc
M	source/blender/editors/space_node/node_edit.cc
M	source/blender/editors/space_node/node_group.cc
M	source/blender/editors/space_node/node_relationships.cc
M	source/blender/editors/space_node/node_templates.cc
M	source/blender/editors/uvedit/uvedit_ops.c
M	source/blender/makesrna/intern/rna_color.c
M	source/blender/makesrna/intern/rna_image.c
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/makesrna/intern/rna_texture.c

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

diff --git a/source/blender/editors/include/ED_node.h b/source/blender/editors/include/ED_node.h
index e68617f7867..2b6f669900c 100644
--- a/source/blender/editors/include/ED_node.h
+++ b/source/blender/editors/include/ED_node.h
@@ -120,6 +120,25 @@ void ED_node_set_active(struct Main *bmain,
                         struct bNode *node,
                         bool *r_active_texture_changed);
 
+/**
+ * Call after one or more node trees have been changed and have been tagged accordingly.
+ *
+ * This function will make sure that other parts of Blender update accordingly. For example, if the
+ * node group interface changed, parent node groups have to be updated as well.
+ *
+ * Additionally, this will send notifiers and tag the depsgraph based on the changes. Depsgraph
+ * relation updates have to be triggered by the caller.
+ *
+ * \param C: Context if available. This can be null.
+ * \param bmain: Main whose data-blocks should be updated based on the changes.
+ * \param only_tagged_tree: Under some circumstances the caller knows that only one node tree has
+ *   changed since the last update. In this case the function may be able to skip scanning bmain
+ *   for other things that have to be changed.
+ */
+void ED_node_tree_propagate_change(struct bContext *C,
+                                   struct Main *bmain,
+                                   struct bNodeTree *only_tagged_tree);
+
 void ED_node_composite_job(const struct bContext *C,
                            struct bNodeTree *nodetree,
                            struct Scene *scene_owner);
diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc
index d903e9ee984..705fd391a6b 100644
--- a/source/blender/editors/space_node/drawnode.cc
+++ b/source/blender/editors/space_node/drawnode.cc
@@ -3323,7 +3323,8 @@ static void node_property_update_default(Main *bmain, Scene *UNUSED(scene), Poin
 {
   bNodeTree *ntree = (bNodeTree *)ptr->owner_id;
   bNode *node = (bNode *)ptr->data;
-  ED_node_tag_update_nodetree(bmain, ntree, node);
+  UNUSED_VARS(node);
+  ED_node_tree_propagate_change(nullptr, bmain, ntree);
 }
 
 static void node_socket_template_properties_update(bNodeType *ntype, bNodeSocketTemplate *stemp)
diff --git a/source/blender/editors/space_node/node_add.cc b/source/blender/editors/space_node/node_add.cc
index cb66d0dbd2b..6895a1d3516 100644
--- a/source/blender/editors/space_node/node_add.cc
+++ b/source/blender/editors/space_node/node_add.cc
@@ -288,9 +288,7 @@ static int add_reroute_exec(bContext *C, wmOperator *op)
     BLI_freelistN(&input_links);
 
     /* always last */
-    ntreeUpdateTree(CTX_data_main(C), ntree);
-    snode_notify(C, snode);
-    snode_dag_update(C, snode);
+    ED_node_tree_propagate_change(C, CTX_data_main(C), ntree);
 
     return OPERATOR_FINISHED;
   }
@@ -392,11 +390,7 @@ static int node_add_group_exec(bContext *C, wmOperator *op)
   id_us_plus(group_node->id);
 
   nodeSetActive(ntree, group_node);
-  ntreeUpdateTree(bmain, node_group);
-  ntreeUpdateTree(bmain, ntree);
-
-  snode_notify(C, snode);
-  snode_dag_update(C, snode);
+  ED_node_tree_propagate_change(C, bmain, nullptr);
 
   return OPERATOR_FINISHED;
 }
@@ -487,12 +481,7 @@ static int node_add_object_exec(bContext *C, wmOperator *op)
   id_us_plus(&object->id);
 
   nodeSetActive(ntree, object_node);
-  ntreeUpdateTree(bmain, ntree);
-
-  snode_notify(C, snode);
-  snode_dag_update(C, snode);
-
-  ED_node_tag_update_nodetree(bmain, ntree, object_node);
+  ED_node_tree_propagate_change(C, bmain, ntree);
   DEG_relations_tag_update(bmain);
 
   return OPERATOR_FINISHED;
@@ -587,14 +576,9 @@ static int node_add_texture_exec(bContext *C, wmOperator *op)
   id_us_plus(&texture->id);
 
   nodeSetActive(ntree, texture_node);
-  ntreeUpdateTree(bmain, ntree);
-
-  snode_notify(C, snode);
-  snode_dag_update(C, snode);
+  ED_node_tree_propagate_change(C, bmain, ntree);
   DEG_relations_tag_update(bmain);
 
-  ED_node_tag_update_nodetree(bmain, ntree, texture_node);
-
   return OPERATOR_FINISHED;
 }
 
@@ -693,14 +677,9 @@ static int node_add_collection_exec(bContext *C, wmOperator *op)
   id_us_plus(&collection->id);
 
   nodeSetActive(ntree, collection_node);
-  ntreeUpdateTree(bmain, ntree);
-
-  snode_notify(C, snode);
-  snode_dag_update(C, snode);
+  ED_node_tree_propagate_change(C, bmain, ntree);
   DEG_relations_tag_update(bmain);
 
-  ED_node_tag_update_nodetree(bmain, ntree, collection_node);
-
   return OPERATOR_FINISHED;
 }
 
@@ -817,8 +796,7 @@ static int node_add_file_exec(bContext *C, wmOperator *op)
     WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
   }
 
-  snode_notify(C, snode);
-  snode_dag_update(C, snode);
+  ED_node_tree_propagate_change(C, bmain, snode->edittree);
   DEG_relations_tag_update(bmain);
 
   return OPERATOR_FINISHED;
@@ -913,8 +891,7 @@ static int node_add_mask_exec(bContext *C, wmOperator *op)
   node->id = mask;
   id_us_plus(mask);
 
-  snode_notify(C, snode);
-  snode_dag_update(C, snode);
+  ED_node_tree_propagate_change(C, bmain, snode->edittree);
   DEG_relations_tag_update(bmain);
 
   return OPERATOR_FINISHED;
diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc
index 030d1672a08..1a4903e2cfe 100644
--- a/source/blender/editors/space_node/node_edit.cc
+++ b/source/blender/editors/space_node/node_edit.cc
@@ -440,6 +440,27 @@ void snode_notify(bContext *C, SpaceNode *snode)
   }
 }
 
+void ED_node_tree_propagate_change(bContext *C, Main *bmain, bNodeTree *only_tagged_tree)
+{
+  if (C != nullptr) {
+    SpaceNode *snode = CTX_wm_space_node(C);
+    if (snode != nullptr) {
+      snode_notify(C, snode);
+      snode_dag_update(C, snode);
+    }
+  }
+  if (only_tagged_tree != nullptr) {
+    ntreeUpdateTree(bmain, only_tagged_tree);
+    ED_node_tag_update_nodetree(bmain, only_tagged_tree, nullptr);
+  }
+  else {
+    FOREACH_NODETREE_BEGIN (bmain, tree, id) {
+      ntreeUpdateTree(bmain, tree);
+    }
+    FOREACH_NODETREE_END;
+  }
+}
+
 void ED_node_set_tree_type(SpaceNode *snode, bNodeTreeType *typeinfo)
 {
   if (typeinfo) {
@@ -712,14 +733,10 @@ void ED_node_set_active(
         }
 
         node->flag |= NODE_DO_OUTPUT;
-        if (was_output == 0) {
-          ED_node_tag_update_nodetree(bmain, ntree, node);
-        }
-      }
-      else if (do_update) {
-        ED_node_tag_update_nodetree(bmain, ntree, node);
       }
 
+      ED_node_tree_propagate_change(nullptr, bmain, ntree);
+
       if ((node->flag & NODE_ACTIVE_TEXTURE) && !was_active_texture) {
         /* If active texture changed, free glsl materials. */
         LISTBASE_FOREACH (Material *, ma, &bmain->materials) {
@@ -765,7 +782,7 @@ void ED_node_set_active(
         if (r_active_texture_changed) {
           *r_active_texture_changed = true;
         }
-        ED_node_tag_update_nodetree(bmain, ntree, node);
+        ED_node_tree_propagate_change(nullptr, bmain, ntree);
         WM_main_add_notifier(NC_IMAGE, nullptr);
       }
 
@@ -782,7 +799,7 @@ void ED_node_set_active(
 
         node->flag |= NODE_DO_OUTPUT;
         if (was_output == 0) {
-          ED_node_tag_update_nodetree(bmain, ntree, node);
+          ED_node_tree_propagate_change(nullptr, bmain, ntree);
         }
 
         /* Adding a node doesn't link this yet. */
@@ -797,11 +814,11 @@ void ED_node_set_active(
           }
 
           node->flag |= NODE_DO_OUTPUT;
-          ED_node_tag_update_nodetree(bmain, ntree, node);
+          ED_node_tree_propagate_change(nullptr, bmain, ntree);
         }
       }
       else if (do_update) {
-        ED_node_tag_update_nodetree(bmain, ntree, node);
+        ED_node_tree_propagate_change(nullptr, bmain, ntree);
       }
     }
     else if (ntree->type == NTREE_TEXTURE) {
@@ -1398,12 +1415,7 @@ static int node_duplicate_exec(bContext *C, wmOperator *op)
     }
   }
 
-  ntreeUpdateTree(CTX_data_main(C), snode->edittree);
-
-  snode_notify(C, snode);
-  if (do_tag_update) {
-    snode_dag_update(C, snode);
-  }
+  ED_node_tree_propagate_change(C, bmain, snode->edittree);
 
   return OPERATOR_FINISHED;
 }
@@ -1495,8 +1507,7 @@ static int node_read_viewlayers_exec(bContext *C, wmOperator *UNUSED(op))
     }
   }
 
-  snode_notify(C, snode);
-  snode_dag_update(C, snode);
+  ED_node_tree_propagate_change(C, bmain, snode->edittree);
 
   return OPERATOR_FINISHED;
 }
@@ -1663,7 +1674,7 @@ static int node_preview_toggle_exec(bContext *C, wmOperator *UNUSED(op))
 
   node_flag_toggle_exec(snode, NODE_PREVIEW);
 
-  snode_notify(C, snode);
+  ED_node_tree_propagate_change(C, CTX_data_main(C), snode->edittree);
 
   return OPERATOR_FINISHED;
 }
@@ -1783,10 +1794,7 @@ static int node_mute_exec(bContext *C, wmOperator *UNUSED(op))
     }
   }
 
-  snode_notify(C, snode);
-  if (do_tag_update) {
-    snode_dag_update(C, snode);
-  }
+  ED_node_tree_propagate_change(C, bmain, snode->edittree);
 
   return OPERATOR_FINISHED;
 }
@@ -1823,12 +1831,7 @@ static int node_delete_exec(bContext *C, wmOperator *UNUSED(op))
     }
   }
 
-  ntreeUpdateTree(CTX_data_main(C), snode->edittree);
-
-  snode_notify(C, snode);
-  if (do_tag_update) {
-    snode_dag_update(C, snode);
-  }
+  ED_node_tree_propagate_change(C, bmain, snode->edittree);
 
   return OPERATOR_FINISHED;
 }
@@ -1872,10 +1875,7 @@ static int node_switch_view_exec(bContext *C, wmOperator *UNUSED(op))
     }
   }
 
-  ntreeUpdateTree(CTX_data_main(C), snode->edittree);
-
-  snode_notify(C, snode);
-  snode_dag_update(C, snode);
+  ED_node_tree_propagate_change(C, CTX_data_main(C), snode->edittree);
 
   return OPERATOR_FINISHED;
 }
@@ -1910,10 +1910,7 @@ static int node_delete_reconnect_exec(bContext *C, wmOperator *UNUSED(op))
     }
   }
 
-  ntreeUpdateTree(CTX_data_main(C), snode->edittree);
-
-  snode_notify(C, snode);
-  snode_dag_update(C, snode);
+  ED_node_tree_propagate_change(C, bmain, snode->edittree);
 
   return OPERATOR_FINISHED;
 }
@@ -1960,7 +1957,7 @@ static int node_output_file_add_socket_exec(bContext *C, wmOperator *op)
   RNA_string_get(op->ptr, "file_path", file_path);
   ntreeCompositOutputFileAddSocket(ntree, node, file_path, &scene->r.im_format);
 
-  snode_notify(C, snode);
+  ED_nod

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list