Blender  V2.93
depsgraph_tag.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19 
26 #include "intern/depsgraph_tag.h"
27 
28 #include <cstdio>
29 #include <cstring> /* required for memset */
30 #include <queue>
31 
32 #include "BLI_math_bits.h"
33 #include "BLI_task.h"
34 #include "BLI_utildefines.h"
35 
36 #include "DNA_anim_types.h"
37 #include "DNA_curve_types.h"
38 #include "DNA_key_types.h"
39 #include "DNA_lattice_types.h"
40 #include "DNA_mesh_types.h"
41 #include "DNA_object_types.h"
42 #include "DNA_particle_types.h"
43 #include "DNA_screen_types.h"
45 
46 #include "BKE_anim_data.h"
47 #include "BKE_global.h"
48 #include "BKE_idtype.h"
49 #include "BKE_node.h"
50 #include "BKE_scene.h"
51 #include "BKE_screen.h"
52 #include "BKE_workspace.h"
53 
54 #include "DEG_depsgraph.h"
55 #include "DEG_depsgraph_debug.h"
56 #include "DEG_depsgraph_query.h"
57 
59 #include "intern/depsgraph.h"
64 #include "intern/node/deg_node.h"
70 
71 namespace deg = blender::deg;
72 
73 /* *********************** */
74 /* Update Tagging/Flushing */
75 
76 namespace blender::deg {
77 
78 namespace {
79 
80 void depsgraph_geometry_tag_to_component(const ID *id, NodeType *component_type)
81 {
83  if (result != NodeType::UNDEFINED) {
84  *component_type = result;
85  }
86 }
87 
88 bool is_selectable_data_id_type(const ID_Type id_type)
89 {
90  return ELEM(id_type, ID_ME, ID_CU, ID_MB, ID_LT, ID_GD, ID_HA, ID_PT, ID_VO);
91 }
92 
93 void depsgraph_select_tag_to_component_opcode(const ID *id,
94  NodeType *component_type,
95  OperationCode *operation_code)
96 {
97  const ID_Type id_type = GS(id->name);
98  if (id_type == ID_SCE) {
99  /* We need to flush base flags to all objects in a scene since we
100  * don't know which ones changed. However, we don't want to update
101  * the whole scene, so pick up some operation which will do as less
102  * as possible.
103  *
104  * TODO(sergey): We can introduce explicit exit operation which
105  * does nothing and which is only used to cascade flush down the
106  * road. */
107  *component_type = NodeType::LAYER_COLLECTIONS;
108  *operation_code = OperationCode::VIEW_LAYER_EVAL;
109  }
110  else if (id_type == ID_OB) {
111  *component_type = NodeType::OBJECT_FROM_LAYER;
112  *operation_code = OperationCode::OBJECT_FROM_LAYER_ENTRY;
113  }
114  else if (id_type == ID_MC) {
115  *component_type = NodeType::BATCH_CACHE;
116  *operation_code = OperationCode::MOVIECLIP_SELECT_UPDATE;
117  }
118  else if (is_selectable_data_id_type(id_type)) {
119  *component_type = NodeType::BATCH_CACHE;
120  *operation_code = OperationCode::GEOMETRY_SELECT_UPDATE;
121  }
122  else {
123  *component_type = NodeType::COPY_ON_WRITE;
124  *operation_code = OperationCode::COPY_ON_WRITE;
125  }
126 }
127 
128 void depsgraph_base_flags_tag_to_component_opcode(const ID *id,
129  NodeType *component_type,
130  OperationCode *operation_code)
131 {
132  const ID_Type id_type = GS(id->name);
133  if (id_type == ID_SCE) {
134  *component_type = NodeType::LAYER_COLLECTIONS;
135  *operation_code = OperationCode::VIEW_LAYER_EVAL;
136  }
137  else if (id_type == ID_OB) {
138  *component_type = NodeType::OBJECT_FROM_LAYER;
139  *operation_code = OperationCode::OBJECT_BASE_FLAGS;
140  }
141 }
142 
143 OperationCode psysTagToOperationCode(IDRecalcFlag tag)
144 {
145  if (tag == ID_RECALC_PSYS_RESET) {
147  }
149 }
150 
151 void depsgraph_tag_to_component_opcode(const ID *id,
152  IDRecalcFlag tag,
153  NodeType *component_type,
154  OperationCode *operation_code)
155 {
156  const ID_Type id_type = GS(id->name);
157  *component_type = NodeType::UNDEFINED;
158  *operation_code = OperationCode::OPERATION;
159  /* Special case for now, in the future we should get rid of this. */
160  if (tag == 0) {
161  *component_type = NodeType::ID_REF;
162  *operation_code = OperationCode::OPERATION;
163  return;
164  }
165  switch (tag) {
166  case ID_RECALC_TRANSFORM:
167  *component_type = NodeType::TRANSFORM;
168  break;
169  case ID_RECALC_GEOMETRY:
170  depsgraph_geometry_tag_to_component(id, component_type);
171  break;
172  case ID_RECALC_ANIMATION:
173  *component_type = NodeType::ANIMATION;
174  break;
175  case ID_RECALC_PSYS_REDO:
178  case ID_RECALC_PSYS_PHYS:
179  if (id_type == ID_PA) {
180  /* NOTES:
181  * - For particle settings node we need to use different
182  * component. Will be nice to get this unified with object,
183  * but we can survive for now with single exception here.
184  * Particles needs reconsideration anyway, */
185  *component_type = NodeType::PARTICLE_SETTINGS;
186  *operation_code = psysTagToOperationCode(tag);
187  }
188  else {
189  *component_type = NodeType::PARTICLE_SYSTEM;
190  }
191  break;
193  *component_type = NodeType::COPY_ON_WRITE;
194  break;
195  case ID_RECALC_SHADING:
196  if (id_type == ID_NT) {
197  *component_type = NodeType::SHADING_PARAMETERS;
198  }
199  else {
200  *component_type = NodeType::SHADING;
201  }
202  break;
203  case ID_RECALC_SELECT:
204  depsgraph_select_tag_to_component_opcode(id, component_type, operation_code);
205  break;
207  depsgraph_base_flags_tag_to_component_opcode(id, component_type, operation_code);
208  break;
210  *component_type = NodeType::POINT_CACHE;
211  break;
212  case ID_RECALC_EDITORS:
213  /* There is no such node in depsgraph, this tag is to be handled
214  * separately. */
215  break;
217  *component_type = NodeType::SEQUENCER;
218  break;
220  case ID_RECALC_AUDIO_FPS:
224  case ID_RECALC_AUDIO:
225  *component_type = NodeType::AUDIO;
226  break;
228  *component_type = NodeType::PARAMETERS;
229  break;
230  case ID_RECALC_SOURCE:
231  *component_type = NodeType::PARAMETERS;
232  break;
233  case ID_RECALC_ALL:
234  case ID_RECALC_PSYS_ALL:
235  BLI_assert(!"Should not happen");
236  break;
238  break; /* Must be ignored by depsgraph. */
239  }
240 }
241 
242 void id_tag_update_ntree_special(
243  Main *bmain, Depsgraph *graph, ID *id, int flag, eUpdateSource update_source)
244 {
245  bNodeTree *ntree = ntreeFromID(id);
246  if (ntree == nullptr) {
247  return;
248  }
249  graph_id_tag_update(bmain, graph, &ntree->id, flag, update_source);
250 }
251 
252 void depsgraph_update_editors_tag(Main *bmain, Depsgraph *graph, ID *id)
253 {
254  /* NOTE: We handle this immediately, without delaying anything, to be
255  * sure we don't cause threading issues with OpenGL. */
256  /* TODO(sergey): Make sure this works for CoW-ed data-blocks as well. */
257  DEGEditorUpdateContext update_ctx = {nullptr};
258  update_ctx.bmain = bmain;
259  update_ctx.depsgraph = (::Depsgraph *)graph;
260  update_ctx.scene = graph->scene;
261  update_ctx.view_layer = graph->view_layer;
262  deg_editors_id_update(&update_ctx, id);
263 }
264 
265 void depsgraph_id_tag_copy_on_write(Depsgraph *graph, IDNode *id_node, eUpdateSource update_source)
266 {
267  ComponentNode *cow_comp = id_node->find_component(NodeType::COPY_ON_WRITE);
268  if (cow_comp == nullptr) {
270  return;
271  }
272  cow_comp->tag_update(graph, update_source);
273 }
274 
275 void depsgraph_tag_component(Depsgraph *graph,
276  IDNode *id_node,
277  NodeType component_type,
278  OperationCode operation_code,
279  eUpdateSource update_source)
280 {
281  ComponentNode *component_node = id_node->find_component(component_type);
282  /* NOTE: Animation component might not be existing yet (which happens when adding new driver or
283  * adding a new keyframe), so the required copy-on-write tag needs to be taken care explicitly
284  * here. */
285  if (component_node == nullptr) {
286  if (component_type == NodeType::ANIMATION) {
287  depsgraph_id_tag_copy_on_write(graph, id_node, update_source);
288  }
289  return;
290  }
291  if (operation_code == OperationCode::OPERATION) {
292  component_node->tag_update(graph, update_source);
293  }
294  else {
295  OperationNode *operation_node = component_node->find_operation(operation_code);
296  if (operation_node != nullptr) {
297  operation_node->tag_update(graph, update_source);
298  }
299  }
300  /* If component depends on copy-on-write, tag it as well. */
301  if (component_node->need_tag_cow_before_update()) {
302  depsgraph_id_tag_copy_on_write(graph, id_node, update_source);
303  }
304 }
305 
306 /* This is a tag compatibility with legacy code.
307  *
308  * Mainly, old code was tagging object with ID_RECALC_GEOMETRY tag to inform
309  * that object's data data-block changed. Now API expects that ID is given
310  * explicitly, but not all areas are aware of this yet. */
311 void deg_graph_id_tag_legacy_compat(
312  Main *bmain, Depsgraph *depsgraph, ID *id, IDRecalcFlag tag, eUpdateSource update_source)
313 {
314  if (ELEM(tag, ID_RECALC_GEOMETRY, 0)) {
315  switch (GS(id->name)) {
316  case ID_OB: {
317  Object *object = (Object *)id;
318  ID *data_id = (ID *)object->data;
319  if (data_id != nullptr) {
320  graph_id_tag_update(bmain, depsgraph, data_id, 0, update_source);
321  }
322  break;
323  }
324  /* TODO(sergey): Shape keys are annoying, maybe we should find a
325  * way to chain geometry evaluation to them, so we don't need extra
326  * tagging here. */
327  case ID_ME: {
328  Mesh *mesh = (Mesh *)id;
329  if (mesh->key != nullptr) {
330  ID *key_id = &mesh->key->id;
331  if (key_id != nullptr) {
332  graph_id_tag_update(bmain, depsgraph, key_id, 0, update_source);
333  }
334  }
335  break;
336  }
337  case ID_LT: {
338  Lattice *lattice = (Lattice *)id;
339  if (lattice->key != nullptr) {
340  ID *key_id = &lattice->key->id;
341  if (key_id != nullptr) {
342  graph_id_tag_update(bmain, depsgraph, key_id, 0, update_source);
343  }
344  }
345  break;
346  }
347  case ID_CU: {
348  Curve *curve = (Curve *)id;
349  if (curve->key != nullptr) {
350  ID *key_id = &curve->key->id;
351  if (key_id != nullptr) {
352  graph_id_tag_update(bmain, depsgraph, key_id, 0, update_source);
353  }
354  }
355  break;
356  }
357  default:
358  break;
359  }
360  }
361 }
362 
363 void graph_id_tag_update_single_flag(Main *bmain,
364  Depsgraph *graph,
365  ID *id,
366  IDNode *id_node,
367  IDRecalcFlag tag,
368  eUpdateSource update_source)
369 {
370  if (tag == ID_RECALC_EDITORS) {
371  if (graph != nullptr && graph->is_active) {
372  depsgraph_update_editors_tag(bmain, graph, id);
373  }
374  return;
375  }
376  /* Get description of what is to be tagged. */
377  NodeType component_type;
378  OperationCode operation_code;
379  depsgraph_tag_to_component_opcode(id, tag, &component_type, &operation_code);
380  /* Check whether we've got something to tag. */
381  if (component_type == NodeType::UNDEFINED) {
382  /* Given ID does not support tag. */
383  /* TODO(sergey): Shall we raise some panic here? */
384  return;
385  }
386  /* Some sanity checks before moving forward. */
387  if (id_node == nullptr) {
388  /* Happens when object is tagged for update and not yet in the
389  * dependency graph (but will be after relations update). */
390  return;
391  }
392  /* Tag ID recalc flag. */
393  DepsNodeFactory *factory = type_get_factory(component_type);
394  BLI_assert(factory != nullptr);
395  id_node->id_cow->recalc |= factory->id_recalc_tag();
396  /* Tag corresponding dependency graph operation for update. */
397  if (component_type == NodeType::ID_REF) {
398  id_node->tag_update(graph, update_source);
399  }
400  else {
401  depsgraph_tag_component(graph, id_node, component_type, operation_code, update_source);
402  }
403  /* TODO(sergey): Get rid of this once all areas are using proper data ID
404  * for tagging. */
405  deg_graph_id_tag_legacy_compat(bmain, graph, id, tag, update_source);
406 }
407 
408 string stringify_append_bit(const string &str, IDRecalcFlag tag)
409 {
410  const char *tag_name = DEG_update_tag_as_string(tag);
411  if (tag_name == nullptr) {
412  return str;
413  }
414  string result = str;
415  if (!result.empty()) {
416  result += ", ";
417  }
418  result += tag_name;
419  return result;
420 }
421 
422 string stringify_update_bitfield(int flag)
423 {
424  if (flag == 0) {
425  return "LEGACY_0";
426  }
427  string result;
428  int current_flag = flag;
429  /* Special cases to avoid ALL flags form being split into
430  * individual bits. */
431  if ((current_flag & ID_RECALC_PSYS_ALL) == ID_RECALC_PSYS_ALL) {
432  result = stringify_append_bit(result, ID_RECALC_PSYS_ALL);
433  }
434  /* Handle all the rest of the flags. */
435  while (current_flag != 0) {
436  IDRecalcFlag tag = (IDRecalcFlag)(1 << bitscan_forward_clear_i(&current_flag));
437  result = stringify_append_bit(result, tag);
438  }
439  return result;
440 }
441 
442 const char *update_source_as_string(eUpdateSource source)
443 {
444  switch (source) {
446  return "TIME";
448  return "USER_EDIT";
450  return "RELATIONS";
452  return "VISIBILITY";
453  }
454  BLI_assert(!"Should never happen.");
455  return "UNKNOWN";
456 }
457 
458 int deg_recalc_flags_for_legacy_zero()
459 {
460  return ID_RECALC_ALL &
462 }
463 
464 int deg_recalc_flags_effective(Depsgraph *graph, int flags)
465 {
466  if (graph != nullptr) {
467  if (!graph->is_active) {
468  return 0;
469  }
470  }
471  if (flags == 0) {
472  return deg_recalc_flags_for_legacy_zero();
473  }
474  return flags;
475 }
476 
477 /* Special tag function which tags all components which needs to be tagged
478  * for update flag=0.
479  *
480  * TODO(sergey): This is something to be avoid in the future, make it more
481  * explicit and granular for users to tag what they really need. */
482 void deg_graph_node_tag_zero(Main *bmain,
483  Depsgraph *graph,
484  IDNode *id_node,
485  eUpdateSource update_source)
486 {
487  if (id_node == nullptr) {
488  return;
489  }
490  ID *id = id_node->id_orig;
491  /* TODO(sergey): Which recalc flags to set here? */
492  id_node->id_cow->recalc |= deg_recalc_flags_for_legacy_zero();
493 
494  for (ComponentNode *comp_node : id_node->components.values()) {
495  if (comp_node->type == NodeType::ANIMATION) {
496  continue;
497  }
498  comp_node->tag_update(graph, update_source);
499  }
500  deg_graph_id_tag_legacy_compat(bmain, graph, id, (IDRecalcFlag)0, update_source);
501 }
502 
503 void deg_graph_on_visible_update(Main *bmain, Depsgraph *graph, const bool do_time)
504 {
505  /* NOTE: It is possible to have this function called with `do_time=false` first and later (prior
506  * to evaluation though) with `do_time=true`. This means early output checks should be aware of
507  * this. */
508  for (deg::IDNode *id_node : graph->id_nodes) {
509  const ID_Type id_type = GS(id_node->id_orig->name);
510  if (id_type == ID_OB) {
511  Object *object_orig = reinterpret_cast<Object *>(id_node->id_orig);
512  if (object_orig->proxy != nullptr) {
513  object_orig->proxy->proxy_from = object_orig;
514  }
515  }
516 
518  /* ID has no components which affects anything visible.
519  * No need bother with it to tag or anything. */
520  continue;
521  }
522  int flag = 0;
524  flag |= ID_RECALC_COPY_ON_WRITE;
525  if (do_time) {
526  if (BKE_animdata_from_id(id_node->id_orig) != nullptr) {
527  flag |= ID_RECALC_ANIMATION;
528  }
529  }
530  }
531  else {
533  /* The ID was already visible and evaluated, all the subsequent
534  * updates and tags are to be done explicitly. */
535  continue;
536  }
537  }
538  /* We only tag components which needs an update. Tagging everything is
539  * not a good idea because that might reset particles cache (or any
540  * other type of cache).
541  *
542  * TODO(sergey): Need to generalize this somehow. */
543  if (id_type == ID_OB) {
545  }
547  if (id_type == ID_SCE) {
548  /* Make sure collection properties are up to date. */
550  }
551  /* Now when ID is updated to the new visibility state, prevent it from
552  * being re-tagged again. Simplest way to do so is to pretend that it
553  * was already updated by the "previous" dependency graph.
554  *
555  * NOTE: Even if the on_visible_update() is called from the state when
556  * dependency graph is tagged for relations update, it will be fine:
557  * since dependency graph builder re-schedules entry tags, all the
558  * tags we request from here will be applied in the updated state of
559  * dependency graph. */
561  }
562 }
563 
564 } /* namespace */
565 
567 {
568  const ID_Type id_type = GS(id->name);
569  switch (id_type) {
570  case ID_OB: {
571  const Object *object = (Object *)id;
572  switch (object->type) {
573  case OB_MESH:
574  case OB_CURVE:
575  case OB_SURF:
576  case OB_FONT:
577  case OB_LATTICE:
578  case OB_MBALL:
579  case OB_GPENCIL:
580  case OB_HAIR:
581  case OB_POINTCLOUD:
582  case OB_VOLUME:
583  return NodeType::GEOMETRY;
584  case OB_ARMATURE:
585  return NodeType::EVAL_POSE;
586  /* TODO(sergey): More cases here? */
587  }
588  break;
589  }
590  case ID_ME:
591  case ID_CU:
592  case ID_LT:
593  case ID_MB:
594  case ID_HA:
595  case ID_PT:
596  case ID_VO:
597  case ID_GR:
598  return NodeType::GEOMETRY;
599  case ID_PA: /* Particles */
600  return NodeType::UNDEFINED;
601  case ID_LP:
602  return NodeType::PARAMETERS;
603  case ID_GD:
604  return NodeType::GEOMETRY;
605  case ID_PAL: /* Palettes */
606  return NodeType::PARAMETERS;
607  case ID_MSK:
608  return NodeType::PARAMETERS;
609  default:
610  break;
611  }
612  return NodeType::UNDEFINED;
613 }
614 
615 void id_tag_update(Main *bmain, ID *id, int flag, eUpdateSource update_source)
616 {
617  graph_id_tag_update(bmain, nullptr, id, flag, update_source);
619  graph_id_tag_update(bmain, depsgraph, id, flag, update_source);
620  }
621 
622  /* Accumulate all tags for an ID between two undo steps, so they can be
623  * replayed for undo. */
624  id->recalc_after_undo_push |= deg_recalc_flags_effective(nullptr, flag);
625 }
626 
628  Main *bmain, Depsgraph *graph, ID *id, int flag, eUpdateSource update_source)
629 {
630  const int debug_flags = (graph != nullptr) ? DEG_debug_flags_get((::Depsgraph *)graph) : G.debug;
631  if (graph != nullptr && graph->is_evaluating) {
632  if (debug_flags & G_DEBUG_DEPSGRAPH) {
633  printf("ID tagged for update during dependency graph evaluation.");
634  }
635  return;
636  }
637  if (debug_flags & G_DEBUG_DEPSGRAPH_TAG) {
638  printf("%s: id=%s flags=%s source=%s\n",
639  __func__,
640  id->name,
641  stringify_update_bitfield(flag).c_str(),
642  update_source_as_string(update_source));
643  }
644  IDNode *id_node = (graph != nullptr) ? graph->find_id_node(id) : nullptr;
645  if (graph != nullptr) {
646  DEG_graph_id_type_tag(reinterpret_cast<::Depsgraph *>(graph), GS(id->name));
647  }
648  if (flag == 0) {
649  deg_graph_node_tag_zero(bmain, graph, id_node, update_source);
650  }
651  /* Store original flag in the ID.
652  * Allows to have more granularity than a node-factory based flags. */
653  if (id_node != nullptr) {
654  id_node->id_cow->recalc |= flag;
655  }
656  /* When ID is tagged for update based on an user edits store the recalc flags in the original ID.
657  * This way IDs in the undo steps will have this flag preserved, making it possible to restore
658  * all needed tags when new dependency graph is created on redo.
659  * This is the only way to ensure modifications to animation data (such as keyframes i.e.)
660  * properly triggers animation update for the newly constructed dependency graph on redo (while
661  * usually newly created dependency graph skips animation update to avoid loss of unkeyed
662  * changes). */
663  if (update_source == DEG_UPDATE_SOURCE_USER_EDIT) {
664  id->recalc |= deg_recalc_flags_effective(graph, flag);
665  }
666  int current_flag = flag;
667  while (current_flag != 0) {
668  IDRecalcFlag tag = (IDRecalcFlag)(1 << bitscan_forward_clear_i(&current_flag));
669  graph_id_tag_update_single_flag(bmain, graph, id, id_node, tag, update_source);
670  }
671  /* Special case for nested node tree data-blocks. */
672  id_tag_update_ntree_special(bmain, graph, id, flag, update_source);
673  /* Direct update tags means that something outside of simulated/cached
674  * physics did change and that cache is to be invalidated.
675  * This is only needed if data changes. If it's just a drawing, we keep the
676  * point cache. */
677  if (update_source == DEG_UPDATE_SOURCE_USER_EDIT && flag != ID_RECALC_SHADING) {
678  graph_id_tag_update_single_flag(
679  bmain, graph, id, id_node, ID_RECALC_POINT_CACHE, update_source);
680  }
681 }
682 
683 } // namespace blender::deg
684 
686 {
687  switch (flag) {
688  case ID_RECALC_TRANSFORM:
689  return "TRANSFORM";
690  case ID_RECALC_GEOMETRY:
691  return "GEOMETRY";
692  case ID_RECALC_ANIMATION:
693  return "ANIMATION";
694  case ID_RECALC_PSYS_REDO:
695  return "PSYS_REDO";
697  return "PSYS_RESET";
699  return "PSYS_CHILD";
700  case ID_RECALC_PSYS_PHYS:
701  return "PSYS_PHYS";
702  case ID_RECALC_PSYS_ALL:
703  return "PSYS_ALL";
705  return "COPY_ON_WRITE";
706  case ID_RECALC_SHADING:
707  return "SHADING";
708  case ID_RECALC_SELECT:
709  return "SELECT";
711  return "BASE_FLAGS";
713  return "POINT_CACHE";
714  case ID_RECALC_EDITORS:
715  return "EDITORS";
717  return "SEQUENCER_STRIPS";
719  return "AUDIO_SEEK";
720  case ID_RECALC_AUDIO_FPS:
721  return "AUDIO_FPS";
723  return "AUDIO_VOLUME";
725  return "AUDIO_MUTE";
727  return "AUDIO_LISTENER";
728  case ID_RECALC_AUDIO:
729  return "AUDIO";
731  return "PARAMETERS";
732  case ID_RECALC_SOURCE:
733  return "SOURCE";
734  case ID_RECALC_ALL:
735  return "ALL";
737  return "TAG_FOR_UNDO";
738  }
739  return nullptr;
740 }
741 
742 /* Data-Based Tagging */
743 
744 /* Tag given ID for an update in all the dependency graphs. */
745 void DEG_id_tag_update(ID *id, int flag)
746 {
747  DEG_id_tag_update_ex(G.main, id, flag);
748 }
749 
750 void DEG_id_tag_update_ex(Main *bmain, ID *id, int flag)
751 {
752  if (id == nullptr) {
753  /* Ideally should not happen, but old depsgraph allowed this. */
754  return;
755  }
757 }
758 
759 void DEG_graph_id_tag_update(struct Main *bmain,
760  struct Depsgraph *depsgraph,
761  struct ID *id,
762  int flag)
763 {
766 }
767 
768 void DEG_time_tag_update(struct Main *bmain)
769 {
771  DEG_graph_time_tag_update(reinterpret_cast<::Depsgraph *>(depsgraph));
772  }
773 }
774 
776 {
777  deg::Depsgraph *deg_graph = reinterpret_cast<deg::Depsgraph *>(depsgraph);
778  deg_graph->tag_time_source();
779 }
780 
781 /* Mark a particular data-block type as having changing. */
783 {
784  if (id_type == ID_NT) {
785  /* Stupid workaround so parent data-blocks of nested node-tree get looped
786  * over when we loop over tagged data-block types. */
793  }
794  const int id_type_index = BKE_idtype_idcode_to_index(id_type);
795  deg::Depsgraph *deg_graph = reinterpret_cast<deg::Depsgraph *>(depsgraph);
796  deg_graph->id_type_updated[id_type_index] = 1;
797 }
798 
799 void DEG_id_type_tag(Main *bmain, short id_type)
800 {
802  DEG_graph_id_type_tag(reinterpret_cast<::Depsgraph *>(depsgraph), id_type);
803  }
804 }
805 
806 /* Update dependency graph when visible scenes/layers changes. */
807 void DEG_graph_on_visible_update(Main *bmain, Depsgraph *depsgraph, const bool do_time)
808 {
810  deg::deg_graph_on_visible_update(bmain, graph, do_time);
811 }
812 
813 void DEG_on_visible_update(Main *bmain, const bool do_time)
814 {
816  DEG_graph_on_visible_update(bmain, reinterpret_cast<::Depsgraph *>(depsgraph), do_time);
817  }
818 }
819 
821 {
823  graph->use_editors_update = true;
824 }
825 
826 /* Check if something was changed in the database and inform
827  * editors about this. */
829 {
831  if (!graph->use_editors_update) {
832  return;
833  }
834 
837  Main *bmain = DEG_get_bmain(depsgraph);
838  bool updated = time || DEG_id_type_any_updated(depsgraph);
839 
840  DEGEditorUpdateContext update_ctx = {nullptr};
841  update_ctx.bmain = bmain;
842  update_ctx.depsgraph = depsgraph;
843  update_ctx.scene = scene;
844  update_ctx.view_layer = view_layer;
845  deg::deg_editors_scene_update(&update_ctx, updated);
846 }
847 
849 {
850  id->recalc &= ~ID_RECALC_ALL;
851  bNodeTree *ntree = ntreeFromID(id);
852  /* Clear embedded node trees too. */
853  if (ntree) {
855  }
856  /* XXX And what about scene's master collection here? */
857 }
858 
860 {
861  deg::Depsgraph *deg_graph = reinterpret_cast<deg::Depsgraph *>(depsgraph);
862  /* TODO(sergey): Re-implement POST_UPDATE_HANDLER_WORKAROUND using entry_tags
863  * and id_tags storage from the new dependency graph. */
865  return;
866  }
867  /* Go over all ID nodes nodes, clearing tags. */
868  for (deg::IDNode *id_node : deg_graph->id_nodes) {
869  if (backup) {
870  id_node->id_cow_recalc_backup |= id_node->id_cow->recalc;
871  }
872  /* TODO: we clear original ID recalc flags here, but this may not work
873  * correctly when there are multiple depsgraph with others still using
874  * the recalc flag. */
875  id_node->is_user_modified = false;
877  if (deg_graph->is_active) {
879  }
880  }
881  memset(deg_graph->id_type_updated, 0, sizeof(deg_graph->id_type_updated));
882 }
883 
885 {
886  deg::Depsgraph *deg_graph = reinterpret_cast<deg::Depsgraph *>(depsgraph);
887 
888  for (deg::IDNode *id_node : deg_graph->id_nodes) {
889  id_node->id_cow->recalc |= id_node->id_cow_recalc_backup;
890  id_node->id_cow_recalc_backup = 0;
891  }
892 }
struct AnimData * BKE_animdata_from_id(struct ID *id)
Definition: anim_data.c:96
@ G_DEBUG_DEPSGRAPH
Definition: BKE_global.h:148
@ G_DEBUG_DEPSGRAPH_TAG
Definition: BKE_global.h:143
int BKE_idtype_idcode_to_index(const short idcode)
Definition: idtype.c:345
struct bNodeTree * ntreeFromID(struct ID *id)
Definition: node.cc:3147
#define BLI_assert(a)
Definition: BLI_assert.h:58
MINLINE int bitscan_forward_clear_i(int *a)
#define ELEM(...)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
int DEG_debug_flags_get(const struct Depsgraph *depsgraph)
struct Scene * DEG_get_input_scene(const Depsgraph *graph)
bool DEG_id_type_any_updated(const struct Depsgraph *depsgraph)
struct Main * DEG_get_bmain(const Depsgraph *graph)
struct ViewLayer * DEG_get_input_view_layer(const Depsgraph *graph)
IDRecalcFlag
Definition: DNA_ID.h:594
@ ID_RECALC_PARAMETERS
Definition: DNA_ID.h:668
@ ID_RECALC_AUDIO_FPS
Definition: DNA_ID.h:661
@ ID_RECALC_PSYS_PHYS
Definition: DNA_ID.h:624
@ ID_RECALC_AUDIO_LISTENER
Definition: DNA_ID.h:664
@ ID_RECALC_TRANSFORM
Definition: DNA_ID.h:599
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:654
@ ID_RECALC_SHADING
Definition: DNA_ID.h:631
@ ID_RECALC_AUDIO
Definition: DNA_ID.h:666
@ ID_RECALC_POINT_CACHE
Definition: DNA_ID.h:642
@ ID_RECALC_SELECT
Definition: DNA_ID.h:638
@ ID_RECALC_PSYS_REDO
Definition: DNA_ID.h:618
@ ID_RECALC_PSYS_CHILD
Definition: DNA_ID.h:622
@ ID_RECALC_SOURCE
Definition: DNA_ID.h:673
@ ID_RECALC_EDITORS
Definition: DNA_ID.h:648
@ ID_RECALC_PSYS_ALL
Definition: DNA_ID.h:699
@ ID_RECALC_AUDIO_MUTE
Definition: DNA_ID.h:663
@ ID_RECALC_SEQUENCER_STRIPS
Definition: DNA_ID.h:658
@ ID_RECALC_TAG_FOR_UNDO
Definition: DNA_ID.h:682
@ ID_RECALC_PSYS_RESET
Definition: DNA_ID.h:620
@ ID_RECALC_AUDIO_SEEK
Definition: DNA_ID.h:660
@ ID_RECALC_ANIMATION
Definition: DNA_ID.h:614
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:611
@ ID_RECALC_ALL
Definition: DNA_ID.h:697
@ ID_RECALC_AUDIO_VOLUME
Definition: DNA_ID.h:662
@ ID_RECALC_BASE_FLAGS
Definition: DNA_ID.h:641
ID_Type
Definition: DNA_ID_enums.h:56
@ ID_MC
Definition: DNA_ID_enums.h:85
@ ID_TE
Definition: DNA_ID_enums.h:64
@ ID_VO
Definition: DNA_ID_enums.h:95
@ ID_NT
Definition: DNA_ID_enums.h:80
@ ID_LA
Definition: DNA_ID_enums.h:67
@ ID_SCE
Definition: DNA_ID_enums.h:57
@ ID_MSK
Definition: DNA_ID_enums.h:86
@ ID_GD
Definition: DNA_ID_enums.h:83
@ ID_PAL
Definition: DNA_ID_enums.h:88
@ ID_LP
Definition: DNA_ID_enums.h:92
@ ID_HA
Definition: DNA_ID_enums.h:93
@ ID_WO
Definition: DNA_ID_enums.h:71
@ ID_SIM
Definition: DNA_ID_enums.h:96
@ ID_MA
Definition: DNA_ID_enums.h:63
@ ID_ME
Definition: DNA_ID_enums.h:60
@ ID_GR
Definition: DNA_ID_enums.h:77
@ ID_MB
Definition: DNA_ID_enums.h:62
@ ID_LT
Definition: DNA_ID_enums.h:66
@ ID_OB
Definition: DNA_ID_enums.h:59
@ ID_PA
Definition: DNA_ID_enums.h:82
@ ID_PT
Definition: DNA_ID_enums.h:94
@ ID_CU
Definition: DNA_ID_enums.h:61
Object is a sort of wrapper for general info.
@ OB_LATTICE
@ OB_MBALL
@ OB_SURF
@ OB_FONT
@ OB_ARMATURE
@ OB_MESH
@ OB_POINTCLOUD
@ OB_HAIR
@ OB_VOLUME
@ OB_CURVE
@ OB_GPENCIL
Depsgraph * graph
const IDNode * id_node
double time
Scene scene
Curve curve
const Depsgraph * depsgraph
Lattice lattice
AnimationBackup * backup
void DEG_id_type_tag(Main *bmain, short id_type)
const char * DEG_update_tag_as_string(IDRecalcFlag flag)
void DEG_editors_update(Depsgraph *depsgraph, bool time)
void DEG_id_tag_update(ID *id, int flag)
void DEG_enable_editors_update(Depsgraph *depsgraph)
void DEG_graph_on_visible_update(Main *bmain, Depsgraph *depsgraph, const bool do_time)
void DEG_ids_clear_recalc(Depsgraph *depsgraph, const bool backup)
void DEG_graph_id_tag_update(struct Main *bmain, struct Depsgraph *depsgraph, struct ID *id, int flag)
void DEG_graph_time_tag_update(struct Depsgraph *depsgraph)
void DEG_time_tag_update(struct Main *bmain)
void DEG_on_visible_update(Main *bmain, const bool do_time)
void DEG_id_tag_update_ex(Main *bmain, ID *id, int flag)
void DEG_graph_id_type_tag(Depsgraph *depsgraph, short id_type)
void DEG_ids_restore_recalc(Depsgraph *depsgraph)
static void deg_graph_clear_id_recalc_flags(ID *id)
bNodeTree * ntree
#define str(s)
#define GS(x)
Definition: iris.c:241
Span< Depsgraph * > get_all_registered_graphs(Main *bmain)
NodeType geometry_tag_to_component(const ID *id)
void deg_editors_id_update(const DEGEditorUpdateContext *update_ctx, ID *id)
void deg_editors_scene_update(const DEGEditorUpdateContext *update_ctx, bool updated)
void id_tag_update(Main *bmain, ID *id, int flag, eUpdateSource update_source)
bool deg_copy_on_write_is_needed(const ID *id_orig)
DepsNodeFactory * type_get_factory(const NodeType type)
bool deg_copy_on_write_is_expanded(const ID *id_cow)
void graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id, int flag, eUpdateSource update_source)
@ DEG_UPDATE_SOURCE_USER_EDIT
@ DEG_UPDATE_SOURCE_RELATIONS
@ DEG_UPDATE_SOURCE_VISIBILITY
struct Key * key
struct Depsgraph * depsgraph
struct ViewLayer * view_layer
struct Scene * scene
Definition: DNA_ID.h:273
int recalc
Definition: DNA_ID.h:295
char name[66]
Definition: DNA_ID.h:283
ID id
Definition: DNA_key_types.h:79
struct Key * key
Definition: BKE_main.h:116
struct Key * key
struct Object * proxy_from
struct Object * proxy
void * data
IDNode * find_id_node(const ID *id) const
Definition: depsgraph.cc:112
char id_type_updated[INDEX_ID_MAX]
Definition: depsgraph.h:112
ViewLayer * view_layer
Definition: depsgraph.h:135
IDDepsNodes id_nodes
Definition: depsgraph.h:103
IDComponentsMask previously_visible_components_mask
Definition: deg_node_id.h:127
IDComponentsMask visible_components_mask
Definition: deg_node_id.h:126
Map< ComponentIDKey, ComponentNode * > components
Definition: deg_node_id.h:96
ComponentNode * find_component(NodeType type, const char *name="") const
Definition: deg_node_id.cc:162
virtual void tag_update(Depsgraph *graph, eUpdateSource source) override
Definition: deg_node_id.cc:183
#define G(x, y, z)