Blender  V3.3
deg_node_component.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2013 Blender Foundation. All rights reserved. */
3 
8 #pragma once
9 
11 #include "intern/node/deg_node.h"
14 
15 #include "BLI_string.h"
16 #include "BLI_utildefines.h"
17 
18 #include "BKE_object.h"
19 
20 #include "DNA_object_types.h"
21 
22 struct ID;
23 struct bPoseChannel;
24 
25 namespace blender::deg {
26 
27 struct Depsgraph;
28 struct IDNode;
29 struct OperationNode;
30 
31 /* ID Component - Base type for all components */
32 struct ComponentNode : public Node {
33  /* Key used to look up operations within a component */
34  struct OperationIDKey {
36  const char *name;
37  int name_tag;
38 
41  OperationIDKey(OperationCode opcode, const char *name, int name_tag);
42 
43  string identifier() const;
44  bool operator==(const OperationIDKey &other) const;
45  uint64_t hash() const;
46  };
47 
48  /* Typedef for container of operations */
49  ComponentNode();
51 
53  void init(const ID *id, const char *subdata) override;
54 
55  virtual string identifier() const override;
56 
57  /* Find an existing operation, if requested operation does not exist nullptr will be returned.
58  * See #add_operation for the meaning and examples of #name and #name_tag.
59  */
62  const char *name = "",
63  int name_tag = -1) const;
64 
65  /* Find an existing operation, will throw an assert() if it does not exist.
66  * See #add_operation for the meaning and examples of #name and #name_tag. */
69  const char *name = "",
70  int name_tag = -1) const;
71 
72  /* Check operation exists and return it. */
73  bool has_operation(OperationIDKey key) const;
74  bool has_operation(OperationCode opcode, const char *name = "", int name_tag = -1) const;
75 
93  OperationCode opcode,
94  const char *name = "",
95  int name_tag = -1);
96 
97  /* Entry/exit operations management.
98  *
99  * Use those instead of direct set since this will perform sanity checks. */
100  void set_entry_operation(OperationNode *op_node);
101  void set_exit_operation(OperationNode *op_node);
102 
103  void clear_operations();
104 
105  virtual void tag_update(Depsgraph *graph, eUpdateSource source) override;
106 
107  virtual OperationNode *get_entry_operation() override;
108  virtual OperationNode *get_exit_operation() override;
109 
111 
113 
114  /* ** Inner nodes for this component ** */
115 
116  /* Operations stored as a hash map, for faster build.
117  * This hash map will be freed when graph is fully built. */
119 
120  /* This is a "normal" list of operations, used by evaluation
121  * and other routines after construction. */
123 
126 
127  virtual bool depends_on_cow()
128  {
129  return true;
130  }
131 
132  /* Denotes whether COW component is to be tagged when this component
133  * is tagged for update. */
135  {
136  return true;
137  }
138 
139  /* The component has (possibly indirect) effect on a data-block whose node has
140  * is_visible_on_build set to true.
141  *
142  * This field is ensured to be up-to-date prior to `IDNode::finalize_build()`. */
144 
145  /* Denotes whether this component actually affects (possibly indirectly) on a directly visible
146  * object. Includes possibly run-time visibility update of ID nodes.
147  *
148  * NOTE: Is only reliable after `deg_graph_flush_visibility()`. */
150 };
151 
152 /* ---------------------------------------- */
153 
154 #define DEG_COMPONENT_NODE_DEFINE_TYPEINFO(NodeType, type_, type_name_, id_recalc_tag) \
155  const Node::TypeInfo NodeType::typeinfo = Node::TypeInfo(type_, type_name_, id_recalc_tag)
156 
157 #define DEG_COMPONENT_NODE_DECLARE DEG_DEPSNODE_DECLARE
158 
159 #define DEG_COMPONENT_NODE_DEFINE(name, NAME, id_recalc_tag) \
160  DEG_COMPONENT_NODE_DEFINE_TYPEINFO( \
161  name##ComponentNode, NodeType::NAME, #name " Component", id_recalc_tag); \
162  static DepsNodeFactoryImpl<name##ComponentNode> DNTI_##NAME
163 
164 #define DEG_COMPONENT_NODE_DECLARE_GENERIC(name) \
165  struct name##ComponentNode : public ComponentNode { \
166  DEG_COMPONENT_NODE_DECLARE; \
167  }
168 
169 #define DEG_COMPONENT_NODE_DECLARE_NO_COW_TAG_ON_UPDATE(name) \
170  struct name##ComponentNode : public ComponentNode { \
171  DEG_COMPONENT_NODE_DECLARE; \
172  virtual bool need_tag_cow_before_update() \
173  { \
174  return false; \
175  } \
176  }
177 
178 #define DEG_COMPONENT_NODE_DECLARE_NO_COW(name) \
179  struct name##ComponentNode : public ComponentNode { \
180  DEG_COMPONENT_NODE_DECLARE; \
181  virtual bool depends_on_cow() \
182  { \
183  return false; \
184  } \
185  }
186 
211 
212 /* Bone Component */
215  void init(const ID *id, const char *subdata);
216 
217  struct bPoseChannel *pchan; /* the bone that this component represents */
218 
220 };
221 
222 /* Eventually we would not tag parameters in all cases.
223  * Support for this each ID needs to be added on an individual basis. */
225  virtual bool need_tag_cow_before_update() override
226  {
228  /* Disabled as this is not true for newly added objects, needs investigation. */
229  // BLI_assert(deg_copy_on_write_is_expanded(owner->id_cow));
230  return false;
231  }
232  return true;
233  }
234 
236 };
237 
239 
240 } // namespace blender::deg
General operations, lookup, etc. for blender objects.
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
#define ID_TYPE_SUPPORTS_PARAMS_WITHOUT_COW(id_type)
Definition: DNA_ID.h:606
Object is a sort of wrapper for general info.
Depsgraph * graph
DEG_COMPONENT_NODE_DECLARE_GENERIC(Animation)
void deg_register_component_depsnodes()
DEG_COMPONENT_NODE_DECLARE_NO_COW_TAG_ON_UPDATE(BatchCache)
function< void(struct ::Depsgraph *)> DepsEvalOperationCb
unsigned __int64 uint64_t
Definition: stdint.h:90
Definition: DNA_ID.h:368
void init(const ID *id, const char *subdata)
bool operator==(const OperationIDKey &other) const
virtual bool need_tag_cow_before_update()
virtual OperationNode * get_entry_operation() override
OperationNode * get_operation(OperationIDKey key) const
void init(const ID *id, const char *subdata) override
virtual void tag_update(Depsgraph *graph, eUpdateSource source) override
Vector< OperationNode * > operations
OperationNode * find_operation(OperationIDKey key) const
virtual OperationNode * get_exit_operation() override
OperationNode * add_operation(const DepsEvalOperationCb &op, OperationCode opcode, const char *name="", int name_tag=-1)
bool has_operation(OperationIDKey key) const
void set_exit_operation(OperationNode *op_node)
void finalize_build(Depsgraph *graph)
virtual string identifier() const override
Map< ComponentNode::OperationIDKey, OperationNode * > * operations_map
void set_entry_operation(OperationNode *op_node)
virtual bool need_tag_cow_before_update() override