[Bf-blender-cvs] [17ceb807dd4] id_copy_refactor: Move Material, Texture and Image datablocks to new copying code.

Bastien Montagne noreply at git.blender.org
Sat Jul 8 12:22:53 CEST 2017


Commit: 17ceb807dd4814f90fc856e72f87a4d32834331b
Author: Bastien Montagne
Date:   Sat Jul 8 12:14:31 2017 +0200
Branches: id_copy_refactor
https://developer.blender.org/rB17ceb807dd4814f90fc856e72f87a4d32834331b

Move Material, Texture and Image datablocks to new copying code.

Note that this is also bringing back Image copying code into 'regular'
process, instead of doing its own dirty cooking.

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

M	source/blender/blenkernel/BKE_image.h
M	source/blender/blenkernel/BKE_material.h
M	source/blender/blenkernel/BKE_texture.h
M	source/blender/blenkernel/intern/image.c
M	source/blender/blenkernel/intern/lamp.c
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/material.c
M	source/blender/blenkernel/intern/texture.c

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

diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index e155b0719cc..146b7bfadb0 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -250,6 +250,7 @@ void BKE_image_packfiles_from_mem(struct ReportList *reports, struct Image *ima,
 void BKE_image_print_memlist(void);
 
 /* empty image block, of similar type and filename */
+void BKE_image_copy_ex(struct Main *bmain, struct Image *ima_dst, const struct Image *ima_src, const int flag);
 struct Image *BKE_image_copy(struct Main *bmain, const struct Image *ima);
 
 /* merge source into dest, and free source */
diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h
index 7da962dd6d6..6ac7b154415 100644
--- a/source/blender/blenkernel/BKE_material.h
+++ b/source/blender/blenkernel/BKE_material.h
@@ -54,6 +54,7 @@ void BKE_material_init(struct Material *ma);
 void BKE_material_remap_object(struct Object *ob, const unsigned int *remap);
 void BKE_material_remap_object_calc(struct  Object *ob_dst, struct Object *ob_src, short *remap_src_to_dst);
 struct Material *BKE_material_add(struct Main *bmain, const char *name);
+void BKE_material_copy_ex(struct Main *bmain, struct Material *ma_dst, const struct Material *ma_src, const int flag);
 struct Material *BKE_material_copy(struct Main *bmain, const struct Material *ma);
 struct Material *localize_material(struct Material *ma);
 struct Material *give_node_material(struct Material *ma); /* returns node material or self */
diff --git a/source/blender/blenkernel/BKE_texture.h b/source/blender/blenkernel/BKE_texture.h
index 190fdeafaec..9319f6f5a76 100644
--- a/source/blender/blenkernel/BKE_texture.h
+++ b/source/blender/blenkernel/BKE_texture.h
@@ -70,6 +70,7 @@ void colorband_update_sort(struct ColorBand *coba);
 
 void         BKE_texture_free(struct Tex *tex);
 void         BKE_texture_default(struct Tex *tex);
+void         BKE_texture_copy_ex(struct Main *bmain, struct Tex *tex_dst, const struct Tex *tex_src, const int flag);
 struct Tex  *BKE_texture_copy(struct Main *bmain, const struct Tex *tex);
 struct Tex  *BKE_texture_add(struct Main *bmain, const char *name);
 struct Tex  *BKE_texture_localize(struct Tex *tex);
@@ -114,13 +115,13 @@ void                 BKE_texture_colormapping_default(struct ColorMapping *color
 void           BKE_texture_envmap_free_data(struct EnvMap *env);
 void           BKE_texture_envmap_free(struct EnvMap *env);
 struct EnvMap *BKE_texture_envmap_add(void);
-struct EnvMap *BKE_texture_envmap_copy(const struct EnvMap *env);
+struct EnvMap *BKE_texture_envmap_copy(const struct EnvMap *env, const int flag);
 
 void                 BKE_texture_pointdensity_init_data(struct PointDensity *pd);
 void                 BKE_texture_pointdensity_free_data(struct PointDensity *pd);
 void                 BKE_texture_pointdensity_free(struct PointDensity *pd);
 struct PointDensity *BKE_texture_pointdensity_add(void);
-struct PointDensity *BKE_texture_pointdensity_copy(const struct PointDensity *pd);
+struct PointDensity *BKE_texture_pointdensity_copy(const struct PointDensity *pd, const int flag);
 
 void              BKE_texture_voxeldata_free_data(struct VoxelData *vd);
 void              BKE_texture_voxeldata_free(struct VoxelData *vd);
@@ -129,7 +130,7 @@ struct VoxelData *BKE_texture_voxeldata_copy(struct VoxelData *vd);
 
 void             BKE_texture_ocean_free(struct OceanTex *ot);
 struct OceanTex *BKE_texture_ocean_add(void);
-struct OceanTex *BKE_texture_ocean_copy(const struct OceanTex *ot);
+struct OceanTex *BKE_texture_ocean_copy(const struct OceanTex *ot, const int flag);
 
 bool    BKE_texture_dependsOnTime(const struct Tex *texture);
 bool    BKE_texture_is_image_user(const struct Tex *tex);
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index abe08def197..567316fc847 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -433,39 +433,53 @@ static void copy_image_packedfiles(ListBase *lb_dst, const ListBase *lb_src)
 	}
 }
 
-/* empty image block, of similar type and filename */
-Image *BKE_image_copy(Main *bmain, const Image *ima)
+/**
+ * Only copy internal data of Image 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_image_copy_ex(Main *UNUSED(bmain), Image *ima_dst, const Image *ima_src, const int flag)
 {
-	Image *nima = image_alloc(bmain, ima->id.name + 2, ima->source, ima->type);
-
-	BLI_strncpy(nima->name, ima->name, sizeof(ima->name));
-
-	nima->flag = ima->flag;
-	nima->tpageflag = ima->tpageflag;
-
-	nima->gen_x = ima->gen_x;
-	nima->gen_y = ima->gen_y;
-	nima->gen_type = ima->gen_type;
-	copy_v4_v4(nima->gen_color, ima->gen_color);
-
-	nima->animspeed = ima->animspeed;
+	BKE_color_managed_colorspace_settings_copy(&ima_dst->colorspace_settings, &ima_src->colorspace_settings);
 
-	nima->aspx = ima->aspx;
-	nima->aspy = ima->aspy;
+	copy_image_packedfiles(&ima_dst->packedfiles, &ima_src->packedfiles);
 
-	BKE_color_managed_colorspace_settings_copy(&nima->colorspace_settings, &ima->colorspace_settings);
+	ima_dst->stereo3d_format = MEM_dupallocN(ima_src->stereo3d_format);
+	BLI_duplicatelist(&ima_dst->views, &ima_src->views);
 
-	copy_image_packedfiles(&nima->packedfiles, &ima->packedfiles);
+	/* Cleanup stuff that cannot be copied. */
+	ima_dst->cache = NULL;
+	ima_dst->rr = NULL;
+	for (int i = 0; i < IMA_MAX_RENDER_SLOT; i++) {
+		ima_dst->renders[i] = NULL;
+	}
 
-	/* nima->stere3d_format is already allocated by image_alloc... */
-	*nima->stereo3d_format = *ima->stereo3d_format;
-	BLI_duplicatelist(&nima->views, &ima->views);
+	BLI_listbase_clear(&ima_dst->anims);
 
-	BKE_previewimg_id_copy(&nima->id, &ima->id);
+	ima_dst->totbind = 0;
+	for (int i = 0; i < TEXTARGET_COUNT; i++) {
+		ima_dst->bindcode[i] = 0;
+		ima_dst->gputexture[i] = NULL;
+	}
+	ima_dst->repbind = NULL;
 
-	BKE_id_copy_ensure_local(bmain, &ima->id, &nima->id);
+	if ((flag & LIB_ID_COPY_NO_PREVIEW) != 1) {
+		BKE_previewimg_id_copy(&ima_dst->id, &ima_src->id);
+	}
+	else {
+		ima_dst->preview = NULL;
+	}
+}
 
-	return nima;
+/* empty image block, of similar type and filename */
+Image *BKE_image_copy(Main *bmain, const Image *ima)
+{
+	Image *ima_copy;
+	BKE_id_copy_ex(bmain, &ima->id, (ID **)&ima_copy, 0, false);
+	return ima_copy;
 }
 
 void BKE_image_make_local(Main *bmain, Image *ima, const bool lib_local)
diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c
index 1bee024d0f9..64581ae6891 100644
--- a/source/blender/blenkernel/intern/lamp.c
+++ b/source/blender/blenkernel/intern/lamp.c
@@ -130,8 +130,8 @@ void BKE_lamp_copy_ex(Main *bmain, Lamp *la_dst, const Lamp *la_src, const int f
 
 	for (a = 0; a < MAX_MTEX; a++) {
 		if (la_dst->mtex[a]) {
-			la_dst->mtex[a] = MEM_mallocN(sizeof(MTex), "copylamptex");
-			memcpy(la_dst->mtex[a], la_src->mtex[a], sizeof(MTex));
+			la_dst->mtex[a] = MEM_mallocN(sizeof(*la_dst->mtex[a]), __func__);
+			*la_dst->mtex[a] = *la_src->mtex[a];
 		}
 	}
 
@@ -158,6 +158,13 @@ Lamp *BKE_lamp_copy(Main *bmain, const Lamp *la)
 
 Lamp *localize_lamp(Lamp *la)
 {
+	/* TODO replace with something like
+	 * 	Lamp *la_copy;
+	 * 	BKE_id_copy_ex(bmain, &la->id, (ID **)&la_copy, LIB_ID_COPY_NO_MAIN | LIB_ID_COPY_NO_PREVIEW | LIB_ID_COPY_NO_USER_REFCOUNT, false);
+	 * 	return la_copy;
+	 *
+	 * ... Once f*** nodes are fully converted to that too :( */
+
 	Lamp *lan;
 	int a;
 	
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 78c42dd88b5..e9215705b9a 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -526,7 +526,7 @@ 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 ID_OB, ID_ME, ID_CU, ID_MB, ID_LT, ID_LA, ID_SPK, ID_CA, ID_KE, ID_AR, ID_NT
+#define ITEMS_IMPLEMENTED 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_AR, ID_NT
 
 	if (!test) {
 		/* Check to be removed of course, just here until all BKE_xxx_copy_ex functions are done. */
@@ -549,13 +549,13 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
 			if (!test) BKE_mball_copy_ex(bmain, (MetaBall *)*r_newid, (MetaBall *)id, flag);
 			break;
 		case ID_MA:
-			if (!test) *r_newid = (ID *)BKE_material_copy(bmain, (Material *)id);
+			if (!test) BKE_material_copy_ex(bmain, (Material *)*r_newid, (Material *)id, flag);
 			break;
 		case ID_TE:
-			if (!test) *r_newid = (ID *)BKE_texture_copy(bmain, (Tex *)id);
+			if (!test) BKE_texture_copy_ex(bmain, (Tex *)*r_newid, (Tex *)id, flag);
 			break;
 		case ID_IM:
-			if (!test) *r_newid = (ID *)BKE_image_copy(bmain, (Image *)id);
+			if (!test) BKE_image_copy_ex(bmain, (Image *)*r_newid, (Image *)id, flag);
 			break;
 		case ID_LT:
 			if (!test) BKE_lattice_copy_ex(bmain, (Lattice *)*r_newid, (Lattice *)id, flag);
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index f21efb71180..22d34127f1a 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -219,43 +219,61 @@ Material *BKE_material_add(Main *bmain, const char *name)
 	return ma;
 }
 
-/* XXX keep synced with next function */
-Material *BKE_material_copy(Main *bmain, const Material *ma)
+/**
+ * Only copy internal data of Material 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_l

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list