[Bf-blender-cvs] [a8e4aae0910] id_copy_refactor: Extend a bit 'NO_MAIN'/'NO_USER_REFCOUNT'/etc. flags to ID allocation itself.
Bastien Montagne
noreply at git.blender.org
Mon Jul 17 15:19:23 CEST 2017
Commit: a8e4aae09104d596798aefc9ce7ff3836a2425a1
Author: Bastien Montagne
Date: Mon Jul 17 15:16:41 2017 +0200
Branches: id_copy_refactor
https://developer.blender.org/rBa8e4aae09104d596798aefc9ce7ff3836a2425a1
Extend a bit 'NO_MAIN'/'NO_USER_REFCOUNT'/etc. flags to ID allocation itself.
No real reason we keep this only to copying, creating ID outside of
database is handy as well!
Also, add helpers to add/remove an ID from Main, and to set/clear its
'user refcounting' status. Those will be useful in future complex ID
manipulation cases (like static override...).
===================================================================
M source/blender/blenkernel/BKE_library.h
M source/blender/blenkernel/intern/action.c
M source/blender/blenkernel/intern/armature.c
M source/blender/blenkernel/intern/brush.c
M source/blender/blenkernel/intern/cachefile.c
M source/blender/blenkernel/intern/camera.c
M source/blender/blenkernel/intern/constraint.c
M source/blender/blenkernel/intern/curve.c
M source/blender/blenkernel/intern/font.c
M source/blender/blenkernel/intern/freestyle.c
M source/blender/blenkernel/intern/gpencil.c
M source/blender/blenkernel/intern/group.c
M source/blender/blenkernel/intern/idprop.c
M source/blender/blenkernel/intern/image.c
M source/blender/blenkernel/intern/key.c
M source/blender/blenkernel/intern/lamp.c
M source/blender/blenkernel/intern/lattice.c
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/material.c
M source/blender/blenkernel/intern/mball.c
M source/blender/blenkernel/intern/mesh.c
M source/blender/blenkernel/intern/modifier.c
M source/blender/blenkernel/intern/movieclip.c
M source/blender/blenkernel/intern/node.c
M source/blender/blenkernel/intern/object.c
M source/blender/blenkernel/intern/paint.c
M source/blender/blenkernel/intern/particle.c
M source/blender/blenkernel/intern/rigidbody.c
M source/blender/blenkernel/intern/sca.c
M source/blender/blenkernel/intern/scene.c
M source/blender/blenkernel/intern/sequencer.c
M source/blender/blenkernel/intern/sound.c
M source/blender/blenkernel/intern/speaker.c
M source/blender/blenkernel/intern/text.c
M source/blender/blenkernel/intern/texture.c
M source/blender/blenkernel/intern/tracking.c
M source/blender/blenkernel/intern/world.c
M source/blender/blenloader/intern/readfile.c
M source/blender/editors/io/io_cache.c
M source/blender/editors/screen/screen_edit.c
M source/blender/windowmanager/intern/wm.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index 004442fb013..b5104b35b3c 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -52,24 +52,24 @@ struct PropertyRNA;
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_alloc(struct Main *bmain, short type, const char *name, const int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
void BKE_libblock_init_empty(struct ID *id);
/**
- * New copy logic options.
+ * New ID creation/copying 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,
- /* Do not affect user refcount of datablocks used by copied one.
- * Implies LIB_ID_COPY_NO_MAIN. */
- LIB_ID_COPY_NO_USER_REFCOUNT = 1 << 1,
+ /* *** Generic options (should be handled by all ID types copying, ID creation, etc.). *** */
+ /* Create datablock outside of any main database - similar to 'localize' functions of materials etc. */
+ LIB_ID_CREATE_NO_MAIN = 1 << 0,
+ /* Do not affect user refcount of datablocks used by new one (which also gets zero usercount then).
+ * Implies LIB_ID_CREATE_NO_MAIN. */
+ LIB_ID_CREATE_NO_USER_REFCOUNT = 1 << 1,
/* Assume given 'newid' already points to allocated memory for whole datablock (ID + data) - USE WITH CAUTION!
- * Implies LIB_ID_COPY_NO_MAIN. */
- LIB_ID_COPY_NO_ALLOCATE = 1 << 2,
+ * Implies LIB_ID_CREATE_NO_MAIN. */
+ LIB_ID_CREATE_NO_ALLOCATE = 1 << 2,
- LIB_ID_COPY_NO_DEG_TAG = 1 << 8, /* Do not tag duplicated ID for update in depsgraph. */
+ LIB_ID_CREATE_NO_DEG_TAG = 1 << 8, /* Do not tag new ID for update in depsgraph. */
/* 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. */
@@ -84,8 +84,6 @@ void *BKE_libblock_copy(struct Main *bmain, const struct ID *id) ATTR_WARN_UNUSE
/* "Deprecated" old API. */
void *BKE_libblock_copy_nolib(const struct ID *id, const bool do_action) ATTR_NONNULL();
-void BKE_libblock_copy_data(struct Main *bmain, struct ID *id, const struct ID *id_from, const int flag);
-
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();
@@ -120,6 +118,12 @@ void BKE_libblock_free_ex(struct Main *bmain, void *idv, const bool do_id_user,
void BKE_libblock_free(struct Main *bmain, void *idv) ATTR_NONNULL();
void BKE_libblock_free_us(struct Main *bmain, void *idv) ATTR_NONNULL();
+void BKE_libblock_management_main_add(struct Main *bmain, void *idv);
+void BKE_libblock_management_main_remove(struct Main *bmain, void *idv);
+
+void BKE_libblock_management_usercounts_set(struct Main *bmain, void *idv);
+void BKE_libblock_management_usercounts_clear(struct Main *bmain, void *idv);
+
/* TODO should be named "BKE_id_delete()". */
void BKE_libblock_delete(struct Main *bmain, void *idv) ATTR_NONNULL();
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index d30014db7db..bb4e09364d4 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -88,7 +88,7 @@ bAction *add_empty_action(Main *bmain, const char name[])
{
bAction *act;
- act = BKE_libblock_alloc(bmain, ID_AC, name);
+ act = BKE_libblock_alloc(bmain, ID_AC, name, 0);
return act;
}
@@ -563,7 +563,7 @@ void BKE_pose_copy_data_ex(bPose **dst, const bPose *src, const int flag, const
outPose->avs = src->avs;
for (pchan = outPose->chanbase.first; pchan; pchan = pchan->next) {
- if ((flag & LIB_ID_COPY_NO_USER_REFCOUNT) == 0) {
+ if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
id_us_plus((ID *)pchan->custom);
}
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 58def201e2a..669344e18d7 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -83,7 +83,7 @@ bArmature *BKE_armature_add(Main *bmain, const char *name)
{
bArmature *arm;
- arm = BKE_libblock_alloc(bmain, ID_AR, name);
+ arm = BKE_libblock_alloc(bmain, ID_AR, name, 0);
arm->deformflag = ARM_DEF_VGROUP | ARM_DEF_ENVELOPE;
arm->flag = ARM_COL_CUSTOM; /* custom bone-group colors */
arm->layer = 1;
@@ -190,7 +190,7 @@ void BKE_armature_copy_data(Main *UNUSED(bmain), bArmature *arm_dst, const bArma
Bone *bone_dst_act = NULL;
/* We never handle usercount here for own data. */
- const int flag_subdata = flag | LIB_ID_COPY_NO_USER_REFCOUNT;
+ const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
BLI_duplicatelist(&arm_dst->bonebase, &arm_src->bonebase);
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 8277d0a4b1c..03b0710c8fc 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -152,7 +152,7 @@ Brush *BKE_brush_add(Main *bmain, const char *name, short ob_mode)
{
Brush *brush;
- brush = BKE_libblock_alloc(bmain, ID_BR, name);
+ brush = BKE_libblock_alloc(bmain, ID_BR, name, 0);
BKE_brush_init(brush);
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index 2d9a1b762c1..1916531b066 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -66,7 +66,7 @@ void BKE_cachefiles_exit(void)
void *BKE_cachefile_add(Main *bmain, const char *name)
{
- CacheFile *cache_file = BKE_libblock_alloc(bmain, ID_CF, name);
+ CacheFile *cache_file = BKE_libblock_alloc(bmain, ID_CF, name, 0);
BKE_cachefile_init(cache_file);
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index eaa0c5bbcbf..719125b3317 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -86,7 +86,7 @@ void *BKE_camera_add(Main *bmain, const char *name)
{
Camera *cam;
- cam = BKE_libblock_alloc(bmain, ID_CA, name);
+ cam = BKE_libblock_alloc(bmain, ID_CA, name, 0);
BKE_camera_init(cam);
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 32021d525df..c05feb7faf4 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -4757,7 +4757,7 @@ void BKE_constraints_copy_ex(ListBase *dst, const ListBase *src, const int flag,
cti->copy_data(con, srccon);
/* Fix usercounts for all referenced data that need it. */
- if (cti->id_looper && (flag & LIB_ID_COPY_NO_USER_REFCOUNT) == 0) {
+ if (cti->id_looper && (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
cti->id_looper(con, con_fix_copied_refs_cb, NULL);
}
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index de90429be26..e08fdcf10e9 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -179,7 +179,7 @@ Curve *BKE_curve_add(Main *bmain, const char *name, int type)
{
Curve *cu;
- cu = BKE_libblock_alloc(bmain, ID_CU, name);
+ cu = BKE_libblock_alloc(bmain, ID_CU, name, 0);
cu->type = type;
BKE_curve_init(cu);
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index 5892c8aeeb7..d6b28cfaf70 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -109,7 +109,7 @@ void BKE_vfont_free(struct VFont *vf)
void BKE_vfont_copy_data(Main *UNUSED(bmain), VFont *vfont_dst, const VFont *UNUSED(vfont_src), const int flag)
{
/* We never handle usercount here for own data. */
- const int flag_subdata = flag | LIB_ID_COPY_NO_USER_REFCOUNT;
+ const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
/* Just to be sure, should not have any value actually after reading time. */
vfont_dst->temp_pf = NULL;
@@ -266,7 +266,7 @@ VFont *BKE_vfont_load(Main *bmain, const char *filepath)
vfd = BLI_vfontdata_from_freetypefont(pf);
if (vfd) {
- vfont = BKE_libblock_alloc(bmain, ID_VF, filename);
+ vfont = BKE_libblock_alloc(bmain, ID_VF, filename, 0);
vfont->data = vfd;
/* if there's a font name, use it for the ID name */
diff --git a/source/blender/blenkernel/intern/freestyle.c b/source/blender/blenkernel/intern/freestyle.c
index 05dba538b26..e45a938a4fc 100644
--- a/source/blender/blenkernel/intern/freestyle.c
+++ b/source/blender/blenkernel/intern/freestyle.c
@@ -118,7 +118,7 @@ static void copy_lineset(FreestyleLineSet *new_lineset, FreestyleLineSet *linese
new_lineset->group = lineset->group;
strcpy(new_lineset->name, lineset->name);
- if ((flag & LIB_ID_COPY_NO_USER_REFCOUNT) == 0) {
+ if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
id_us_plus((ID *)new_lineset->linestyle);
id_us_plus((ID *)new_lineset->group);
}
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index a9a741b0713..ee0d0b41898 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -627,7 +627,7 @@ bGPdata *BKE_gpencil_data_addnew(const char name[])
bGPdata *gpd;
/* allocate memory for a new block */
- gpd = BKE_libblock_alloc(G.main, ID_GD, name);
+ gpd = BKE_libblock_alloc(G.main, ID_GD, name, 0);
/* initial settings */
gpd->flag = (GP_DATA_DISPINFO | GP_DATA_EXPAND);
diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c
index 7b292fb2d10..fd6e9681e64 100644
--- a/source/blender/blenkernel/intern/group.c
+++ b/source/blender/blenkernel/intern/group.c
@@ -79,7 +79,7 @@ Group *BKE_group_add(
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list