[Bf-blender-cvs] [bc5381f154f] id_override_static: Some cleanup/renaming, and move 'self remapping' into new id_swap function.

Bastien Montagne noreply at git.blender.org
Thu Nov 16 12:30:56 CET 2017


Commit: bc5381f154f82a43141419daf1f1be99c13ef252
Author: Bastien Montagne
Date:   Thu Nov 16 12:29:25 2017 +0100
Branches: id_override_static
https://developer.blender.org/rBbc5381f154f82a43141419daf1f1be99c13ef252

Some cleanup/renaming, and move 'self remapping' into new id_swap function.

I can't think of any case where we would swap content of two IDs while
wanting to keep old 'self' ID pointers after the swap!

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

M	source/blender/blenkernel/BKE_library.h
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/library_override.c

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

diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index aaae1a75ede..468aab9bdf9 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -147,7 +147,7 @@ bool id_make_local(struct Main *bmain, struct ID *id, const bool test, const boo
 bool id_single_user(struct bContext *C, struct ID *id, struct PointerRNA *ptr, struct PropertyRNA *prop);
 bool id_copy(struct Main *bmain, const struct ID *id, struct ID **newid, bool test);
 bool BKE_id_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, const int flag, const bool test);
-void BKE_id_swap(struct ID *id_a, struct ID *id_b);
+void BKE_id_swap(struct Main *bmain, struct ID *id_a, struct ID *id_b);
 void id_sort_by_name(struct ListBase *lb, struct ID *id);
 void BKE_id_expand_local(struct Main *bmain, struct ID *id);
 void BKE_id_copy_ensure_local(struct Main *bmain, const struct ID *old_id, struct ID *new_id);
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 8585dfea316..f9fdaa0e32f 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -692,7 +692,7 @@ bool id_copy(Main *bmain, const ID *id, ID **newid, bool test)
 
 /** Does a mere memory swap over the whole IDs data (including type-specific memory).
  *  \note Most internal ID data itself is not swapped (only IDProperties are). */
-void BKE_id_swap(ID *id_a, ID *id_b)
+void BKE_id_swap(Main *bmain, ID *id_a, ID *id_b)
 {
 	BLI_assert(GS(id_a->name) == GS(id_b->name));
 
@@ -753,6 +753,10 @@ void BKE_id_swap(ID *id_a, ID *id_b)
 	/* Exception: IDProperties. */
 	id_a->properties = id_b_back.properties;
 	id_b->properties = id_a_back.properties;
+
+	/* Swap will have broken internal references to itself, restore them. */
+	BKE_libblock_relink_ex(bmain, id_a, id_b, id_a, false);
+	BKE_libblock_relink_ex(bmain, id_b, id_a, id_b, false);
 }
 
 /** Does *not* set ID->newid pointer. */
diff --git a/source/blender/blenkernel/intern/library_override.c b/source/blender/blenkernel/intern/library_override.c
index 456cf2fd877..bdcdd13ba03 100644
--- a/source/blender/blenkernel/intern/library_override.c
+++ b/source/blender/blenkernel/intern/library_override.c
@@ -102,7 +102,7 @@ void BKE_override_copy(ID *dst_id, const ID *src_id)
 		BKE_override_init(dst_id, NULL);
 	}
 
-	/* Source is already overriding data, we copy it but reuse it's reference for dest ID.
+	/* Source is already overriding data, we copy it but reuse its reference for dest ID.
 	 * otherwise, source is only an override template, it then becomes reference of dest ID. */
 	dst_id->override->reference = src_id->override->reference ? src_id->override->reference : (ID *)src_id;
 	id_us_plus(dst_id->override->reference);
@@ -491,7 +491,7 @@ void BKE_override_update(Main *bmain, ID *local)
 
 	/* We want to avoid having to remap here, however creating up-to-date override is much simpler if based
 	 * on reference than on current override.
-	 * So we work on temp copy of reference. */
+	 * So we work on temp copy of reference, and 'swap' its content with local. */
 
 	/* XXX We need a way to get off-Main copies of IDs (similar to localized mats/texts/ etc.)!
 	 *     However, this is whole bunch of code work in itself, so for now plain stupid ID copy will do,
@@ -499,6 +499,9 @@ void BKE_override_update(Main *bmain, ID *local)
 	 *     Actually, maybe not! Since we are swapping with original ID's local content, we want to keep
 	 *     usercount in correct state when freeing tmp_id (and that usercounts of IDs used by 'new' local data
 	 *     also remain correct). */
+	/* This would imply change in handling of usercout all over RNA (and possibly all over Blender code).
+	 * Not impossible to do, but would rather see first if extra useless usual user handling is actually
+	 * a (performances) issue here. */
 
 	ID *tmp_id;
 	id_copy(bmain, local->override->reference, &tmp_id, false);
@@ -507,22 +510,19 @@ void BKE_override_update(Main *bmain, ID *local)
 		return;
 	}
 
-	PointerRNA rnaptr_local, rnaptr_final, rnaptr_storage_stack, *rnaptr_storage = NULL;
-	RNA_id_pointer_create(local, &rnaptr_local);
-	RNA_id_pointer_create(tmp_id, &rnaptr_final);
+	PointerRNA rnaptr_src, rnaptr_dst, rnaptr_storage_stack, *rnaptr_storage = NULL;
+	RNA_id_pointer_create(local, &rnaptr_src);
+	RNA_id_pointer_create(tmp_id, &rnaptr_dst);
 	if (local->override->storage) {
 		rnaptr_storage = &rnaptr_storage_stack;
 		RNA_id_pointer_create(local->override->storage, rnaptr_storage);
 	}
 
-	RNA_struct_override_apply(&rnaptr_final, &rnaptr_local, rnaptr_storage, local->override);
+	RNA_struct_override_apply(&rnaptr_dst, &rnaptr_src, rnaptr_storage, local->override);
 
 	/* This also transfers all pointers (memory) owned by local to tmp_id, and vice-versa. So when we'll free tmp_id,
 	 * we'll actually free old, outdated data from local. */
-	BKE_id_swap(local, tmp_id);
-	/* Swap above may have broken internal references to itself. */
-	BKE_libblock_relink_ex(bmain, local, tmp_id, local, false);
-	BKE_libblock_relink_ex(bmain, tmp_id, local, tmp_id, false);  /* Grrrr... */
+	BKE_id_swap(bmain, local, tmp_id);
 
 	/* Again, horribly innefficient in our case, we need something off-Main (aka moar generic nolib copy/free stuff)! */
 	/* XXX And crashing in complex cases (e.g. because depsgraph uses same data...). */
@@ -605,7 +605,10 @@ ID *BKE_override_operations_store_start(OverrideStorage *override_storage, ID *l
 
 	/* XXX TODO We may also want a specialized handling of things here too, to avoid copying heavy never-overridable
 	 *          data (like Mesh geometry etc.)? And also maybe avoid lib refcounting completely (shallow copy...). */
-	id_copy((Main *)override_storage, local, &storage_id, false);  /* XXX ...and worse of all, this won't work with scene! */
+	/* This would imply change in handling of usercout all over RNA (and possibly all over Blender code).
+	 * Not impossible to do, but would rather see first is extra useless usual user handling is actually
+	 * a (performances) issue here, before doing it. */
+	id_copy((Main *)override_storage, local, &storage_id, false);
 
 	if (storage_id != NULL) {
 		PointerRNA rnaptr_reference, rnaptr_final, rnaptr_storage;



More information about the Bf-blender-cvs mailing list