[Bf-blender-cvs] [fa64dfa449d] id_copy_refactor: On second thought, avoid adding new stuff to ID.

Bastien Montagne noreply at git.blender.org
Fri Jun 16 10:51:23 CEST 2017


Commit: fa64dfa449d4c66b0cae55ebbafba18a3e6c7534
Author: Bastien Montagne
Date:   Thu Jun 15 11:05:32 2017 +0200
Branches: id_copy_refactor
https://developer.blender.org/rBfa64dfa449d4c66b0cae55ebbafba18a3e6c7534

On second thought, avoid adding new stuff to ID.

We can extend ID->tag and store there our few alloc-related tags.

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

M	source/blender/blenkernel/BKE_library.h
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/makesdna/DNA_ID.h

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

diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index 3765ae97ebc..4273aafd7d8 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -54,10 +54,32 @@ size_t BKE_libblock_get_alloc_info(short type, const char **name);
 void *BKE_libblock_alloc_notest(short type);
 void *BKE_libblock_alloc(struct Main *bmain, short type, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
 void  BKE_libblock_init_empty(struct ID *id);
+
+/**
+ * New copy logic options.
+ */
+enum {
+	/* *** Generic options (should be handled by all ID types copying). *** */
+	/* Create copy outside of any main database - similar to 'localize' functions of materials etc. */
+	LIB_ID_COPY_NO_MAIN            = 1 << 0,
+	LIB_ID_COPY_NO_USER_REFCOUNT   = 1 << 1,  /* Do not affect user refcount of datablocks used by copied one. */
+	LIB_ID_COPY_NO_DEG_TAG         = 1 << 2,  /* Do not tag duplicated ID for update in depsgraph. */
+	/* Assume given 'newid' already points to allocated memory for whole datablock (ID + data) - USE WITH CAUTION! */
+	LIB_ID_COPY_NO_ALLOCATE        = 1 << 3,
+
+	/* Specific options to some ID types or usages, may be ignored by unrelated ID copying functions. */
+	LIB_ID_COPY_NO_PROXY_CLEAR     = 1 << 16,  /* Object only, needed by make_local code. */
+	LIB_ID_COPY_NO_PREVIEW         = 1 << 17,  /* Do not copy preview data, when supported. */
+	LIB_ID_COPY_CACHES             = 1 << 18,  /* Copy runtime data caches. */
+	/* XXX TODO Do we want to keep that? would rather try to get rid of it... */
+	LIB_ID_COPY_ACTIONS            = 1 << 19,  /* EXCEPTION! Deep-copy actions used by animdata of copied ID. */
+};
+
 void BKE_libblock_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, const int flag);
 void *BKE_libblock_copy(struct Main *bmain, const struct ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
 void *BKE_libblock_copy_nolib(const struct ID *id, const bool do_action) ATTR_NONNULL();
 void  BKE_libblock_copy_data(struct ID *id, const struct ID *id_from, const bool do_action);
+
 void  BKE_libblock_rename(struct Main *bmain, struct ID *id, const char *name) ATTR_NONNULL();
 void  BLI_libblock_ensure_unique_name(struct Main *bmain, const char *name) ATTR_NONNULL();
 
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index db459905eba..a1d0f12bed3 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -1159,7 +1159,15 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int fla
 	/* TODO we can remove that one later and bring its code here. */
 	BKE_libblock_copy_data(idn, id, (flag & LIB_ID_COPY_ACTIONS) != 0);
 
-	idn->copy_tag = flag & (LIB_ID_COPY_NO_MAIN | LIB_ID_COPY_NO_USER_REFCOUNT | LIB_ID_COPY_NO_ALLOCATE);
+	if ((flag & LIB_ID_COPY_NO_MAIN) != 0) {
+		idn->tag |= LIB_TAG_FREE_NO_MAIN;
+	}
+	if ((flag & LIB_ID_COPY_NO_USER_REFCOUNT) != 0) {
+		idn->tag |= LIB_TAG_FREE_NO_USER_REFCOUNT;
+	}
+	if ((flag & LIB_ID_COPY_NO_ALLOCATE) != 0) {
+		idn->tag |= LIB_TAG_FREE_NO_ALLOCATED;
+	}
 
 	if ((flag & LIB_ID_COPY_NO_DEG_TAG) == 0 && (flag & LIB_ID_COPY_NO_MAIN) == 0) {
 		DAG_id_type_tag(bmain, GS(idn->name));
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 3c38a122787..f224f0b5633 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -8221,7 +8221,6 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short
 		return blo_nextbhead(fd, bhead);
 	
 	id->tag = tag | LIB_TAG_NEED_LINK;
-	id->copy_tag = 0;
 	id->lib = main->curlib;
 	id->us = ID_FAKE_USERS(id);
 	id->icon_id = 0;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 236fe2289aa..0336f28ed85 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3842,7 +3842,7 @@ static bool write_file_handle(
 
 		for (; id; id = id->next) {
 			/* We should never attempt to write non-regular IDs (i.e. all kind of temp/runtime ones). */
-			BLI_assert(id->copy_tag == 0);
+			BLI_assert((id->tag & (LIB_TAG_FREE_NO_MAIN | LIB_TAG_FREE_NO_USER_REFCOUNT | LIB_TAG_FREE_NO_ALLOCATED)) == 0);
 
 			switch ((ID_Type)GS(id->name)) {
 				case ID_WM:
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
index 1023afdd205..857b7478481 100644
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@ -127,17 +127,10 @@ typedef struct ID {
 	/**
 	 * LIB_TAG_... tags (runtime only, cleared at read time).
 	 */
-	short tag;
-	short pad_s1;
+	int tag;
 	int us;
 	int icon_id;
 	IDProperty *properties;
-	/**
-	 * LIB_ID_COPY_... options (should be NULL/empty when ID is not temp/runtime-only one).
-	 * Also used by freeing code to know what to do (unlink used IDs, remove from main, ...).
-	 */
-	int copy_tag;
-	int pad_i1;
 } ID;
 
 /**
@@ -356,33 +349,13 @@ enum {
 	LIB_TAG_ID_RECALC_DATA  = 1 << 13,
 	LIB_TAG_ANIM_NO_RECALC  = 1 << 14,
 	LIB_TAG_ID_RECALC_ALL   = (LIB_TAG_ID_RECALC | LIB_TAG_ID_RECALC_DATA),
-};
 
-/**
- * id->copy_tag (runtime-only).
- *
- * Those flags keep track of special options used when copying that ID from another one (or, in some case,
- * from special creation options).
- *
- * They are mostly here for two things:
- *   * Detect attempt to write in .blend file temp/runtime only IDs (id->copy_tag should be void for regular datablocks).
- *   * Simplify freeing, since they should tell whether ID has to be removed from main, whether it should be unlinked, etc.
- */
-enum {
-	/* *** Generic options (should be handled by all ID types copying). *** */
-	/* Create copy outside of any main database - similar to 'localize' functions of materials etc. */
-	LIB_ID_COPY_NO_MAIN            = 1 << 0,
-	LIB_ID_COPY_NO_USER_REFCOUNT   = 1 << 1,  /* Do not affect user refcount of datablocks used by copied one. */
-	LIB_ID_COPY_NO_DEG_TAG         = 1 << 2,  /* Do not tag duplicated ID for update in depsgraph. */
-	/* Assume given 'newid' already points to allocated memory for whole datablock (ID + data) - USE WITH CAUTION! */
-	LIB_ID_COPY_NO_ALLOCATE        = 1 << 3,
-
-	/* Specific options to some ID types or usages, may be ignored by unrelated ID copying functions. */
-	LIB_ID_COPY_NO_PROXY_CLEAR     = 1 << 16,  /* Object only, needed by make_local code. */
-	LIB_ID_COPY_NO_PREVIEW         = 1 << 17,  /* Do not copy preview data, when supported. */
-	LIB_ID_COPY_CACHES             = 1 << 18,  /* Copy runtime data caches. */
-	/* XXX TODO Do we want to keep that? would rather try to get rid of it... */
-	LIB_ID_COPY_ACTIONS            = 1 << 19,  /* EXCEPTION! Deep-copy actions used by animdata of copied ID. */
+	/* RESET_NEVER tag datablock for freeing behavior (usually set when copying real one into temp/runtime one). */
+	LIB_TAG_FREE_NO_MAIN          = 1 << 16,  /* Datablock is not listed in Main database. */
+	LIB_TAG_FREE_NO_USER_REFCOUNT = 1 << 17,  /* Datablock does not refcount usages of other IDs. */
+	/* Datablock was not allocated by standard system (BKE_libblock_alloc), do not free its memory
+	 * (usual type-specific freeing is called though). */
+	LIB_TAG_FREE_NO_ALLOCATED     = 1 << 18,
 };
 
 /* To filter ID types (filter_id) */




More information about the Bf-blender-cvs mailing list