[Bf-blender-cvs] [41a3aafd48e] blender2.8: Depsgraph: Make it possible to use given pre-allocated ID as a copy

Sergey Sharybin noreply at git.blender.org
Thu Jul 27 15:23:02 CEST 2017


Commit: 41a3aafd48e5cff7ceb7e1b08df4c9b4f4d7676b
Author: Sergey Sharybin
Date:   Thu Jul 27 14:38:26 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB41a3aafd48e5cff7ceb7e1b08df4c9b4f4d7676b

Depsgraph: Make it possible to use given pre-allocated ID as a copy

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

M	source/blender/depsgraph/intern/depsgraph.cc
M	source/blender/depsgraph/intern/nodes/deg_node.cc
M	source/blender/depsgraph/intern/nodes/deg_node.h

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

diff --git a/source/blender/depsgraph/intern/depsgraph.cc b/source/blender/depsgraph/intern/depsgraph.cc
index 0644b8d6abd..322a561b4d8 100644
--- a/source/blender/depsgraph/intern/depsgraph.cc
+++ b/source/blender/depsgraph/intern/depsgraph.cc
@@ -286,6 +286,7 @@ IDDepsNode *Depsgraph::add_id_node(ID *id, bool do_tag)
 	if (!id_node) {
 		DepsNodeFactory *factory = deg_get_node_factory(DEG_NODE_TYPE_ID_REF);
 		id_node = (IDDepsNode *)factory->create_node(id, "", id->name);
+		id_node->init_copy_on_write();
 		if (do_tag) {
 			id->tag |= LIB_TAG_DOIT;
 		}
diff --git a/source/blender/depsgraph/intern/nodes/deg_node.cc b/source/blender/depsgraph/intern/nodes/deg_node.cc
index c34189e0ba7..e7fca5ac541 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node.cc
+++ b/source/blender/depsgraph/intern/nodes/deg_node.cc
@@ -173,14 +173,21 @@ void IDDepsNode::init(const ID *id, const char *UNUSED(subdata))
 	components = BLI_ghash_new(id_deps_node_hash_key,
 	                           id_deps_node_hash_key_cmp,
 	                           "Depsgraph id components hash");
+}
 
+void IDDepsNode::init_copy_on_write(ID *id_cow_hint)
+{
 #ifdef WITH_COPY_ON_WRITE
 	/* Create pointer as early as possible, so we can use it for function
 	 * bindings. Rest of data we'll be copying to the new datablock when
 	 * it is actually needed.
 	 */
-	if (deg_copy_on_write_is_needed(id_orig)) {
-		id_cow = (ID *)BKE_libblock_alloc_notest(GS(id->name));
+	if (id_cow_hint != NULL) {
+		BLI_assert(deg_copy_on_write_is_needed(id_orig));
+		id_cow = id_cow_hint;
+	}
+	else if (deg_copy_on_write_is_needed(id_orig)) {
+		id_cow = (ID *)BKE_libblock_alloc_notest(GS(id_orig->name));
 		DEG_COW_PRINT("Create shallow copy for %s: id_orig=%p id_cow=%p\n",
 		              id_orig->name, id_orig, id_cow);
 		deg_tag_copy_on_write_id(id_cow, id_orig);
diff --git a/source/blender/depsgraph/intern/nodes/deg_node.h b/source/blender/depsgraph/intern/nodes/deg_node.h
index a12a43d8658..16e75b2b5e7 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node.h
+++ b/source/blender/depsgraph/intern/nodes/deg_node.h
@@ -138,6 +138,7 @@ struct IDDepsNode : public DepsNode {
 	};
 
 	void init(const ID *id, const char *subdata);
+	void init_copy_on_write(ID *id_cow_hint = NULL);
 	~IDDepsNode();
 	void destroy();




More information about the Bf-blender-cvs mailing list