[Bf-blender-cvs] [8bcf950c28c] id_copy_refactor: Move Mask and FreestyleLineStyle to new ID copying code.

Bastien Montagne noreply at git.blender.org
Sun Jul 9 22:45:08 CEST 2017


Commit: 8bcf950c28c7dfc83a00df7faf0ac6aa349bb1c3
Author: Bastien Montagne
Date:   Sun Jul 9 22:44:21 2017 +0200
Branches: id_copy_refactor
https://developer.blender.org/rB8bcf950c28c7dfc83a00df7faf0ac6aa349bb1c3

Move Mask and FreestyleLineStyle to new ID copying code.

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

M	source/blender/blenkernel/BKE_linestyle.h
M	source/blender/blenkernel/BKE_mask.h
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/linestyle.c
M	source/blender/blenkernel/intern/mask.c
M	source/blender/blenkernel/intern/text.c
M	source/blender/editors/render/render_shading.c

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

diff --git a/source/blender/blenkernel/BKE_linestyle.h b/source/blender/blenkernel/BKE_linestyle.h
index c7b323d0f6e..3ba4fbe0338 100644
--- a/source/blender/blenkernel/BKE_linestyle.h
+++ b/source/blender/blenkernel/BKE_linestyle.h
@@ -52,6 +52,9 @@ struct bContext;
 void BKE_linestyle_init(struct FreestyleLineStyle *linestyle);
 FreestyleLineStyle *BKE_linestyle_new(struct Main *bmain, const char *name);
 void                BKE_linestyle_free(FreestyleLineStyle *linestyle);
+void BKE_linestyle_copy_data(
+        struct Main *bmain, struct FreestyleLineStyle *linestyle_dst, const struct FreestyleLineStyle *linestyle_src,
+        const int flag);
 FreestyleLineStyle *BKE_linestyle_copy(struct Main *bmain, const FreestyleLineStyle *linestyle);
 
 void BKE_linestyle_make_local(struct Main *bmain, struct FreestyleLineStyle *linestyle, const bool lib_local);
@@ -63,10 +66,14 @@ LineStyleModifier *BKE_linestyle_alpha_modifier_add(FreestyleLineStyle *linestyl
 LineStyleModifier *BKE_linestyle_thickness_modifier_add(FreestyleLineStyle *linestyle, const char *name, int type);
 LineStyleModifier *BKE_linestyle_geometry_modifier_add(FreestyleLineStyle *linestyle, const char *name, int type);
 
-LineStyleModifier *BKE_linestyle_color_modifier_copy(FreestyleLineStyle *linestyle, const LineStyleModifier *m);
-LineStyleModifier *BKE_linestyle_alpha_modifier_copy(FreestyleLineStyle *linestyle, const LineStyleModifier *m);
-LineStyleModifier *BKE_linestyle_thickness_modifier_copy(FreestyleLineStyle *linestyle, const LineStyleModifier *m);
-LineStyleModifier *BKE_linestyle_geometry_modifier_copy(FreestyleLineStyle *linestyle, const LineStyleModifier *m);
+LineStyleModifier *BKE_linestyle_color_modifier_copy(
+        FreestyleLineStyle *linestyle, const LineStyleModifier *m, const int flag);
+LineStyleModifier *BKE_linestyle_alpha_modifier_copy(
+        FreestyleLineStyle *linestyle, const LineStyleModifier *m, const int flag);
+LineStyleModifier *BKE_linestyle_thickness_modifier_copy(
+        FreestyleLineStyle *linestyle, const LineStyleModifier *m, const int flag);
+LineStyleModifier *BKE_linestyle_geometry_modifier_copy(
+        FreestyleLineStyle *linestyle, const LineStyleModifier *m, const int flag);
 
 int BKE_linestyle_color_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *modifier);
 int BKE_linestyle_alpha_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *modifier);
diff --git a/source/blender/blenkernel/BKE_mask.h b/source/blender/blenkernel/BKE_mask.h
index 0735d2d97a1..6e154241af7 100644
--- a/source/blender/blenkernel/BKE_mask.h
+++ b/source/blender/blenkernel/BKE_mask.h
@@ -122,6 +122,7 @@ void BKE_mask_point_select_set_handle(struct MaskSplinePoint *point, const eMask
 
 /* general */
 struct Mask *BKE_mask_new(struct Main *bmain, const char *name);
+void BKE_mask_copy_data(struct Main *bmain, struct Mask *mask_dst, const struct Mask *mask_src, const int flag);
 struct Mask *BKE_mask_copy_nolib(struct Mask *mask);
 struct Mask *BKE_mask_copy(struct Main *bmain, const struct Mask *mask);
 
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 9917cac0f11..6e8c41843b6 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -526,8 +526,8 @@ static int id_copy_libmanagement_cb(void *user_data, ID *id_self, ID **id_pointe
 /* XXX TODO remove test thing, *all* IDs should be copyable that way! */
 bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, const bool test)
 {
-#define ITEMS_IMPLEMENTED_1 ID_OB, ID_ME, ID_CU, ID_MB, ID_MA, ID_TE, ID_IM, ID_LT, ID_LA, ID_SPK, ID_CA, ID_KE, ID_WO, ID_TXT, ID_GR
-#define ITEMS_IMPLEMENTED_2 ID_AR, ID_AC, ID_NT, ID_BR, ID_PA, ID_GD, ID_MC
+#define ITEMS_IMPLEMENTED_1 ID_OB, ID_ME, ID_CU, ID_MB, ID_MA, ID_TE, ID_IM, ID_LT, ID_LA, ID_SPK, ID_CA, ID_KE, ID_WO, ID_TXT
+#define ITEMS_IMPLEMENTED_2 ID_GR, ID_AR, ID_AC, ID_NT, ID_BR, ID_PA, ID_GD, ID_MC, ID_MSK, ID_LS
 
 	if (!test) {
 		/* Check to be removed of course, just here until all BKE_xxx_copy_ex functions are done. */
@@ -604,10 +604,10 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
 			if (!test) BKE_movieclip_copy_data(bmain, (MovieClip *)*r_newid, (MovieClip *)id, flag);
 			break;
 		case ID_MSK:
-			if (!test) *r_newid = (ID *)BKE_mask_copy(bmain, (Mask *)id);
+			if (!test) BKE_mask_copy_data(bmain, (Mask *)*r_newid, (Mask *)id, flag);
 			break;
 		case ID_LS:
-			if (!test) *r_newid = (ID *)BKE_linestyle_copy(bmain, (FreestyleLineStyle *)id);
+			if (!test) BKE_linestyle_copy_data(bmain, (FreestyleLineStyle *)*r_newid, (FreestyleLineStyle *)id, flag);
 			break;
 		case ID_PAL:
 			if (!test) *r_newid = (ID *)BKE_palette_copy(bmain, (Palette *)id);
@@ -619,13 +619,13 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
 			if (!test) *r_newid = (ID *)BKE_cachefile_copy(bmain, (CacheFile *)id);
 			break;
 		case ID_SCE:
+		case ID_VF:
+		case ID_SO:
+			return false;  /* not implemented */
 		case ID_LI:
 		case ID_SCR:
 		case ID_WM:
 			return false;  /* can't be copied from here */
-		case ID_VF:
-		case ID_SO:
-			return false;  /* not implemented */
 		case ID_IP:
 			return false;  /* deprecated */
 	}
diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c
index 771e81ddc4f..97aa2e2f47c 100644
--- a/source/blender/blenkernel/intern/linestyle.c
+++ b/source/blender/blenkernel/intern/linestyle.c
@@ -155,73 +155,50 @@ void BKE_linestyle_free(FreestyleLineStyle *linestyle)
 		BKE_linestyle_geometry_modifier_remove(linestyle, m);
 }
 
-FreestyleLineStyle *BKE_linestyle_copy(struct Main *bmain, const FreestyleLineStyle *linestyle)
+/**
+ * Only copy internal data of Linestyle ID from source to already allocated/initialized destination.
+ * You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs.
+ *
+ * WARNING! This function will not handle ID user count!
+ *
+ * \param flag  Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
+ */
+void BKE_linestyle_copy_data(
+        struct Main *bmain, FreestyleLineStyle *linestyle_dst, const FreestyleLineStyle *linestyle_src, const int flag)
 {
-	FreestyleLineStyle *new_linestyle;
-	LineStyleModifier *m;
-	int a;
+	/* We never handle usercount here for own data. */
+	const int flag_subdata = flag | LIB_ID_COPY_NO_USER_REFCOUNT;
 
-	new_linestyle = BKE_linestyle_new(bmain, linestyle->id.name + 2);
-	BKE_linestyle_free(new_linestyle);
-
-	for (a = 0; a < MAX_MTEX; a++) {
-		if (linestyle->mtex[a]) {
-			new_linestyle->mtex[a] = MEM_mallocN(sizeof(MTex), "BKE_linestyle_copy");
-			memcpy(new_linestyle->mtex[a], linestyle->mtex[a], sizeof(MTex));
-			id_us_plus((ID *)new_linestyle->mtex[a]->tex);
+	for (int a = 0; a < MAX_MTEX; a++) {
+		if (linestyle_src->mtex[a]) {
+			linestyle_dst->mtex[a] = MEM_mallocN(sizeof(*linestyle_dst->mtex[a]), __func__);
+			*linestyle_dst->mtex[a] = *linestyle_src->mtex[a];
 		}
 	}
-	if (linestyle->nodetree) {
-		new_linestyle->nodetree = ntreeCopyTree(bmain, linestyle->nodetree);
+	if (linestyle_src->nodetree) {
+		BKE_id_copy_ex(bmain, (ID *)linestyle_src->nodetree, (ID **)&linestyle_dst->nodetree, flag, false);
 	}
 
-	new_linestyle->r = linestyle->r;
-	new_linestyle->g = linestyle->g;
-	new_linestyle->b = linestyle->b;
-	new_linestyle->alpha = linestyle->alpha;
-	new_linestyle->thickness = linestyle->thickness;
-	new_linestyle->thickness_position = linestyle->thickness_position;
-	new_linestyle->thickness_ratio = linestyle->thickness_ratio;
-	new_linestyle->flag = linestyle->flag;
-	new_linestyle->caps = linestyle->caps;
-	new_linestyle->chaining = linestyle->chaining;
-	new_linestyle->rounds = linestyle->rounds;
-	new_linestyle->split_length = linestyle->split_length;
-	new_linestyle->min_angle = linestyle->min_angle;
-	new_linestyle->max_angle = linestyle->max_angle;
-	new_linestyle->min_length = linestyle->min_length;
-	new_linestyle->max_length = linestyle->max_length;
-	new_linestyle->chain_count = linestyle->chain_count;
-	new_linestyle->split_dash1 = linestyle->split_dash1;
-	new_linestyle->split_gap1 = linestyle->split_gap1;
-	new_linestyle->split_dash2 = linestyle->split_dash2;
-	new_linestyle->split_gap2 = linestyle->split_gap2;
-	new_linestyle->split_dash3 = linestyle->split_dash3;
-	new_linestyle->split_gap3 = linestyle->split_gap3;
-	new_linestyle->dash1 = linestyle->dash1;
-	new_linestyle->gap1 = linestyle->gap1;
-	new_linestyle->dash2 = linestyle->dash2;
-	new_linestyle->gap2 = linestyle->gap2;
-	new_linestyle->dash3 = linestyle->dash3;
-	new_linestyle->gap3 = linestyle->gap3;
-	new_linestyle->panel = linestyle->panel;
-	new_linestyle->sort_key = linestyle->sort_key;
-	new_linestyle->integration_type = linestyle->integration_type;
-	new_linestyle->texstep = linestyle->texstep;
-	new_linestyle->pr_texture = linestyle->pr_texture;
-	new_linestyle->use_nodes = linestyle->use_nodes;
-	for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next)
-		BKE_linestyle_color_modifier_copy(new_linestyle, m);
-	for (m = (LineStyleModifier *)linestyle->alpha_modifiers.first; m; m = m->next)
-		BKE_linestyle_alpha_modifier_copy(new_linestyle, m);
-	for (m = (LineStyleModifier *)linestyle->thickness_modifiers.first; m; m = m->next)
-		BKE_linestyle_thickness_modifier_copy(new_linestyle, m);
-	for (m = (LineStyleModifier *)linestyle->geometry_modifiers.first; m; m = m->next)
-		BKE_linestyle_geometry_modifier_copy(new_linestyle, m);
-
-	BKE_id_copy_ensure_local(bmain, &linestyle->id, &new_linestyle->id);
-
-	return new_linestyle;
+	LineStyleModifier *m;
+	for (m = (LineStyleModifier *)linestyle_src->color_modifiers.first; m; m = m->next) {
+		BKE_linestyle_color_modifier_copy(linestyle_dst, m, flag_subdata);
+	}
+	for (m = (LineStyleModifier *)linestyle_src->alpha_modifiers.first; m; m = m->next) {
+		BKE_linestyle_alpha_modifier_copy(linestyle_dst, m, flag_subdata);
+	}
+	for (m = (LineStyleModifier *)linestyle_src->thickness_modifiers.first; m; m = m->next) {
+		BKE_linestyle_thickness_modifier_copy(linestyle_dst, m, flag_sub

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list