diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2016-07-11 17:41:59 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2016-07-11 22:30:02 +0300 |
commit | 4569e19b83894218257e04976df34662fed7a381 (patch) | |
tree | d960fcba7174697ba43a78988024a39e13878d73 /source/blender/blenkernel/intern | |
parent | c06d3b6c3650be099d50da5830e956ae77896693 (diff) |
Add generic 'BKE_id_expand_local' to BKE_library,
will be used by both make_local() and copy() datablock functions.
Note that this new func make 'extern' all IDs used by localized datablock,
not only refcounted ones as it used to be in each type's functions (with a few exceptions).
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 3dc7997ca79..fc584e172a1 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -251,6 +251,33 @@ void id_fake_user_clear(ID *id) } } +static int id_expand_local_callback(void *user_data, struct ID *UNUSED(id_self), struct ID **id_pointer, int cd_flag) +{ + const bool do_user_count = (user_data != NULL); + + /* We tag all ID usages as extern, and increase usercount in case it was requested. */ + if (*id_pointer) { + if (do_user_count && (cd_flag & IDWALK_USER)) { + id_us_plus(*id_pointer); + } + else { + id_lib_extern(*id_pointer); + } + } + + return IDWALK_RET_NOP; +} + +/** + * Expand ID usages of given id as 'extern' (and no more indirect) linked data. Used by ID copy/make_local functions. + * + * \param do_user_count If true, increase usercount of refcounted datablocks used by given id (use it with copied id). + */ +void BKE_id_expand_local(struct ID *id, const bool do_user_count) +{ + BKE_library_foreach_ID_link(id, id_expand_local_callback, SET_INT_IN_POINTER((int)do_user_count), 0); +} + /* calls the appropriate make_local method for the block, unless test. Returns true * if the block can be made local. */ bool id_make_local(Main *bmain, ID *id, bool test) |