Cleanup: Core: lib_query: Make names of self and owner ID data consistent.
Internal private struct was using `owner_id`/`self_id`, while the public callback data struct was using `id_owner`/`id_self`. Now using internal naming everywhere in lib_query related code, as `owner_id` is already used in very low-level 'fundamental' part of the code, e.g. in the `PointerRNA` struct, or in ID's 'loopback' pointers for embedded data. Note that this is only a very small first step toward proper naming consistency for these type of data, the mismatch is currently spread all over the code base. We also need to document more formally the meaning and differences between `self` and `owner` here.
This commit is contained in:
@@ -111,12 +111,12 @@ typedef struct LibraryIDLinkCallbackData {
|
||||
* 'Real' ID, the one that might be in bmain, only differs from self_id when the later is an
|
||||
* embedded one.
|
||||
*/
|
||||
struct ID *id_owner;
|
||||
struct ID *owner_id;
|
||||
/**
|
||||
* ID from which the current ID pointer is being processed. It may be an embedded ID like master
|
||||
* collection or root node tree.
|
||||
*/
|
||||
struct ID *id_self;
|
||||
struct ID *self_id;
|
||||
struct ID **id_pointer;
|
||||
int cb_flag;
|
||||
} LibraryIDLinkCallbackData;
|
||||
@@ -259,17 +259,17 @@ void BKE_library_update_ID_link_user(struct ID *id_dst, struct ID *id_src, int c
|
||||
int BKE_library_ID_use_ID(struct ID *id_user, struct ID *id_used);
|
||||
|
||||
/**
|
||||
* Say whether given \a id_owner may use (in any way) a data-block of \a id_type_used.
|
||||
* Say whether given \a owner_id may use (in any way) a data-block of \a id_type_used.
|
||||
*
|
||||
* This is a 'simplified' abstract version of #BKE_library_foreach_ID_link() above,
|
||||
* quite useful to reduce useless iterations in some cases.
|
||||
*/
|
||||
bool BKE_library_id_can_use_idtype(struct ID *id_owner, short id_type_used);
|
||||
bool BKE_library_id_can_use_idtype(struct ID *owner_id, short id_type_used);
|
||||
|
||||
/**
|
||||
* Given the id_owner return the type of id_types it can use as a filter_id.
|
||||
* Given the owner_id return the type of id_types it can use as a filter_id.
|
||||
*/
|
||||
uint64_t BKE_library_id_can_use_filter_id(const struct ID *id_owner, const bool include_ui);
|
||||
uint64_t BKE_library_id_can_use_filter_id(const struct ID *owner_id, const bool include_ui);
|
||||
|
||||
/**
|
||||
* Check whether given ID is used locally (i.e. by another non-linked ID).
|
||||
|
||||
@@ -952,7 +952,7 @@ static int foreach_libblock_link_append_callback(LibraryIDLinkCallbackData *cb_d
|
||||
* meshes for shape keys e.g.), or this is an unsupported case (two shape-keys depending on
|
||||
* each-other need to be also 'linked' in by their respective meshes, independent shape-keys
|
||||
* are not allowed). ref #96048. */
|
||||
if (id != cb_data->id_self && BKE_idtype_idcode_is_linkable(GS(cb_data->id_self->name))) {
|
||||
if (id != cb_data->self_id && BKE_idtype_idcode_is_linkable(GS(cb_data->self_id->name))) {
|
||||
BKE_library_foreach_ID_link(
|
||||
cb_data->bmain, id, foreach_libblock_link_append_callback, data, IDWALK_NOP);
|
||||
}
|
||||
@@ -972,7 +972,7 @@ static int foreach_libblock_link_append_callback(LibraryIDLinkCallbackData *cb_d
|
||||
const bool do_recursive = (data->lapp_context->params->flag & BLO_LIBLINK_APPEND_RECURSIVE) !=
|
||||
0 ||
|
||||
do_link;
|
||||
if (!do_recursive && cb_data->id_owner->lib != id->lib) {
|
||||
if (!do_recursive && cb_data->owner_id->lib != id->lib) {
|
||||
return IDWALK_RET_NOP;
|
||||
}
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ static int lib_id_clear_library_data_users_update_cb(LibraryIDLinkCallbackData *
|
||||
/* Even though the ID itself remain the same after being made local, from depsgraph point of
|
||||
* view this is a different ID. Hence we need to tag all of its users for COW update. */
|
||||
DEG_id_tag_update_ex(
|
||||
cb_data->bmain, cb_data->id_owner, ID_RECALC_TAG_FOR_UNDO | ID_RECALC_COPY_ON_WRITE);
|
||||
cb_data->bmain, cb_data->owner_id, ID_RECALC_TAG_FOR_UNDO | ID_RECALC_COPY_ON_WRITE);
|
||||
return IDWALK_RET_STOP_ITER;
|
||||
}
|
||||
return IDWALK_RET_NOP;
|
||||
@@ -396,7 +396,7 @@ void BKE_id_newptr_and_tag_clear(ID *id)
|
||||
static int lib_id_expand_local_cb(LibraryIDLinkCallbackData *cb_data)
|
||||
{
|
||||
Main *bmain = cb_data->bmain;
|
||||
ID *id_self = cb_data->id_self;
|
||||
ID *self_id = cb_data->self_id;
|
||||
ID **id_pointer = cb_data->id_pointer;
|
||||
int const cb_flag = cb_data->cb_flag;
|
||||
const int flags = POINTER_AS_INT(cb_data->user_data);
|
||||
@@ -412,7 +412,7 @@ static int lib_id_expand_local_cb(LibraryIDLinkCallbackData *cb_data)
|
||||
* local directly), its embedded IDs should also have already been duplicated, and hence be
|
||||
* fully local here already. */
|
||||
if (*id_pointer != NULL && ID_IS_LINKED(*id_pointer)) {
|
||||
BLI_assert(*id_pointer != id_self);
|
||||
BLI_assert(*id_pointer != self_id);
|
||||
|
||||
BKE_lib_id_clear_library_data(bmain, *id_pointer, flags);
|
||||
}
|
||||
@@ -423,7 +423,7 @@ static int lib_id_expand_local_cb(LibraryIDLinkCallbackData *cb_data)
|
||||
* (through drivers)...
|
||||
* Just skip it, shape key can only be either indirectly linked, or fully local, period.
|
||||
* And let's curse one more time that stupid useless shape-key ID type! */
|
||||
if (*id_pointer && *id_pointer != id_self &&
|
||||
if (*id_pointer && *id_pointer != self_id &&
|
||||
BKE_idtype_idcode_is_linkable(GS((*id_pointer)->name)))
|
||||
{
|
||||
id_lib_extern(*id_pointer);
|
||||
@@ -583,14 +583,14 @@ static int id_copy_libmanagement_cb(LibraryIDLinkCallbackData *cb_data)
|
||||
|
||||
/* Remap self-references to new copied ID. */
|
||||
if (id == data->id_src) {
|
||||
/* We cannot use id_self here, it is not *always* id_dst (thanks to $£!+@#&/? nodetrees). */
|
||||
/* We cannot use self_id here, it is not *always* id_dst (thanks to $£!+@#&/? nodetrees). */
|
||||
id = *id_pointer = data->id_dst;
|
||||
}
|
||||
|
||||
/* Increase used IDs refcount if needed and required. */
|
||||
if ((data->flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0 && (cb_flag & IDWALK_CB_USER)) {
|
||||
if ((data->flag & LIB_ID_CREATE_NO_MAIN) != 0) {
|
||||
BLI_assert(cb_data->id_self->tag & LIB_TAG_NO_MAIN);
|
||||
BLI_assert(cb_data->self_id->tag & LIB_TAG_NO_MAIN);
|
||||
id_us_plus_no_lib(id);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -373,7 +373,7 @@ bool BKE_lib_override_library_property_is_animated(const ID *id,
|
||||
|
||||
static int foreachid_is_hierarchy_leaf_fn(LibraryIDLinkCallbackData *cb_data)
|
||||
{
|
||||
ID *id_owner = cb_data->id_owner;
|
||||
ID *id_owner = cb_data->owner_id;
|
||||
ID *id = *cb_data->id_pointer;
|
||||
bool *is_leaf = static_cast<bool *>(cb_data->user_data);
|
||||
|
||||
@@ -3194,7 +3194,7 @@ static int lib_override_sort_libraries_func(LibraryIDLinkCallbackData *cb_data)
|
||||
if (cb_data->cb_flag & IDWALK_CB_LOOPBACK) {
|
||||
return IDWALK_RET_NOP;
|
||||
}
|
||||
ID *id_owner = cb_data->id_owner;
|
||||
ID *id_owner = cb_data->owner_id;
|
||||
ID *id = *cb_data->id_pointer;
|
||||
if (id != nullptr && ID_IS_LINKED(id) && id->lib != id_owner->lib) {
|
||||
const int owner_library_indirect_level = ID_IS_LINKED(id_owner) ? id_owner->lib->temp_index :
|
||||
|
||||
@@ -87,8 +87,8 @@ void BKE_lib_query_foreachid_process(LibraryForeachIDData *data, ID **id_pp, int
|
||||
const int callback_return = data->callback(
|
||||
&(struct LibraryIDLinkCallbackData){.user_data = data->user_data,
|
||||
.bmain = data->bmain,
|
||||
.id_owner = data->owner_id,
|
||||
.id_self = data->self_id,
|
||||
.owner_id = data->owner_id,
|
||||
.self_id = data->self_id,
|
||||
.id_pointer = id_pp,
|
||||
.cb_flag = cb_flag});
|
||||
if (flag & IDWALK_READONLY) {
|
||||
@@ -126,7 +126,7 @@ int BKE_lib_query_foreachid_process_callback_flag_override(LibraryForeachIDData
|
||||
}
|
||||
|
||||
static bool library_foreach_ID_link(Main *bmain,
|
||||
ID *id_owner,
|
||||
ID *owner_id,
|
||||
ID *id,
|
||||
LibraryIDLinkCallback callback,
|
||||
void *user_data,
|
||||
@@ -192,7 +192,7 @@ static void library_foreach_ID_data_cleanup(LibraryForeachIDData *data)
|
||||
|
||||
/** \return false in case iteration over ID pointers must be stopped, true otherwise. */
|
||||
static bool library_foreach_ID_link(Main *bmain,
|
||||
ID *id_owner,
|
||||
ID *owner_id,
|
||||
ID *id,
|
||||
LibraryIDLinkCallback callback,
|
||||
void *user_data,
|
||||
@@ -259,7 +259,7 @@ static bool library_foreach_ID_link(Main *bmain,
|
||||
* knowledge of the owner ID then.
|
||||
* While not great, and that should be probably sanitized at some point, we cal live with it
|
||||
* for now. */
|
||||
data.owner_id = ((id->flag & LIB_EMBEDDED_DATA) != 0 && id_owner != NULL) ? id_owner :
|
||||
data.owner_id = ((id->flag & LIB_EMBEDDED_DATA) != 0 && owner_id != NULL) ? owner_id :
|
||||
data.self_id;
|
||||
|
||||
/* inherit_data is non-NULL when this function is called for some sub-data ID
|
||||
@@ -374,13 +374,13 @@ void BKE_library_update_ID_link_user(ID *id_dst, ID *id_src, const int cb_flag)
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t BKE_library_id_can_use_filter_id(const ID *id_owner, const bool include_ui)
|
||||
uint64_t BKE_library_id_can_use_filter_id(const ID *owner_id, const bool include_ui)
|
||||
{
|
||||
/* any type of ID can be used in custom props. */
|
||||
if (id_owner->properties) {
|
||||
if (owner_id->properties) {
|
||||
return FILTER_ID_ALL;
|
||||
}
|
||||
const short id_type_owner = GS(id_owner->name);
|
||||
const short id_type_owner = GS(owner_id->name);
|
||||
|
||||
/* IDProps of armature bones and nodes, and bNode->id can use virtually any type of ID. */
|
||||
if (ELEM(id_type_owner, ID_NT, ID_AR)) {
|
||||
@@ -395,16 +395,16 @@ uint64_t BKE_library_id_can_use_filter_id(const ID *id_owner, const bool include
|
||||
/* Casting to non const.
|
||||
* TODO(jbakker): We should introduce a ntree_id_has_tree function as we are actually not
|
||||
* interested in the result. */
|
||||
if (ntreeFromID((ID *)id_owner)) {
|
||||
if (ntreeFromID((ID *)owner_id)) {
|
||||
return FILTER_ID_ALL;
|
||||
}
|
||||
|
||||
if (BKE_animdata_from_id(id_owner)) {
|
||||
if (BKE_animdata_from_id(owner_id)) {
|
||||
/* AnimationData can use virtually any kind of data-blocks, through drivers especially. */
|
||||
return FILTER_ID_ALL;
|
||||
}
|
||||
|
||||
if (ID_IS_OVERRIDE_LIBRARY_REAL(id_owner)) {
|
||||
if (ID_IS_OVERRIDE_LIBRARY_REAL(owner_id)) {
|
||||
/* LibOverride data 'hierarchy root' can virtually point back to any type of ID. */
|
||||
return FILTER_ID_ALL;
|
||||
}
|
||||
@@ -496,14 +496,14 @@ uint64_t BKE_library_id_can_use_filter_id(const ID *id_owner, const bool include
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool BKE_library_id_can_use_idtype(ID *id_owner, const short id_type_used)
|
||||
bool BKE_library_id_can_use_idtype(ID *owner_id, const short id_type_used)
|
||||
{
|
||||
/* any type of ID can be used in custom props. */
|
||||
if (id_owner->properties) {
|
||||
if (owner_id->properties) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const short id_type_owner = GS(id_owner->name);
|
||||
const short id_type_owner = GS(owner_id->name);
|
||||
/* Exception for ID_LI as they don't exist as a filter. */
|
||||
if (id_type_used == ID_LI) {
|
||||
return id_type_owner == ID_LI;
|
||||
@@ -520,7 +520,7 @@ bool BKE_library_id_can_use_idtype(ID *id_owner, const short id_type_used)
|
||||
}
|
||||
|
||||
const uint64_t filter_id_type_used = BKE_idtype_idcode_to_idfilter(id_type_used);
|
||||
const uint64_t can_be_used = BKE_library_id_can_use_filter_id(id_owner, false);
|
||||
const uint64_t can_be_used = BKE_library_id_can_use_filter_id(owner_id, false);
|
||||
return (can_be_used & filter_id_type_used) != 0;
|
||||
}
|
||||
|
||||
@@ -866,7 +866,7 @@ void BKE_lib_query_unused_ids_tag(Main *bmain,
|
||||
|
||||
static int foreach_libblock_used_linked_data_tag_clear_cb(LibraryIDLinkCallbackData *cb_data)
|
||||
{
|
||||
ID *self_id = cb_data->id_self;
|
||||
ID *self_id = cb_data->self_id;
|
||||
ID **id_p = cb_data->id_pointer;
|
||||
const int cb_flag = cb_data->cb_flag;
|
||||
bool *is_changed = cb_data->user_data;
|
||||
|
||||
@@ -177,8 +177,8 @@ static int foreach_libblock_remap_callback(LibraryIDLinkCallbackData *cb_data)
|
||||
return IDWALK_RET_NOP;
|
||||
}
|
||||
|
||||
ID *id_owner = cb_data->id_owner;
|
||||
ID *id_self = cb_data->id_self;
|
||||
ID *id_owner = cb_data->owner_id;
|
||||
ID *id_self = cb_data->self_id;
|
||||
ID **id_p = cb_data->id_pointer;
|
||||
IDRemap *id_remap_data = cb_data->user_data;
|
||||
|
||||
|
||||
@@ -230,22 +230,22 @@ void BKE_main_unlock(struct Main *bmain)
|
||||
static int main_relations_create_idlink_cb(LibraryIDLinkCallbackData *cb_data)
|
||||
{
|
||||
MainIDRelations *bmain_relations = cb_data->user_data;
|
||||
ID *id_self = cb_data->id_self;
|
||||
ID *self_id = cb_data->self_id;
|
||||
ID **id_pointer = cb_data->id_pointer;
|
||||
const int cb_flag = cb_data->cb_flag;
|
||||
|
||||
if (*id_pointer) {
|
||||
MainIDRelationsEntry **entry_p;
|
||||
|
||||
/* Add `id_pointer` as child of `id_self`. */
|
||||
/* Add `id_pointer` as child of `self_id`. */
|
||||
{
|
||||
if (!BLI_ghash_ensure_p(
|
||||
bmain_relations->relations_from_pointers, id_self, (void ***)&entry_p)) {
|
||||
bmain_relations->relations_from_pointers, self_id, (void ***)&entry_p)) {
|
||||
*entry_p = MEM_callocN(sizeof(**entry_p), __func__);
|
||||
(*entry_p)->session_uuid = id_self->session_uuid;
|
||||
(*entry_p)->session_uuid = self_id->session_uuid;
|
||||
}
|
||||
else {
|
||||
BLI_assert((*entry_p)->session_uuid == id_self->session_uuid);
|
||||
BLI_assert((*entry_p)->session_uuid == self_id->session_uuid);
|
||||
}
|
||||
MainIDRelationsEntryItem *to_id_entry = BLI_mempool_alloc(bmain_relations->entry_items_pool);
|
||||
to_id_entry->next = (*entry_p)->to_ids;
|
||||
@@ -256,7 +256,7 @@ static int main_relations_create_idlink_cb(LibraryIDLinkCallbackData *cb_data)
|
||||
(*entry_p)->to_ids = to_id_entry;
|
||||
}
|
||||
|
||||
/* Add `id_self` as parent of `id_pointer`. */
|
||||
/* Add `self_id` as parent of `id_pointer`. */
|
||||
if (*id_pointer != NULL) {
|
||||
if (!BLI_ghash_ensure_p(
|
||||
bmain_relations->relations_from_pointers, *id_pointer, (void ***)&entry_p)) {
|
||||
@@ -269,8 +269,8 @@ static int main_relations_create_idlink_cb(LibraryIDLinkCallbackData *cb_data)
|
||||
MainIDRelationsEntryItem *from_id_entry = BLI_mempool_alloc(
|
||||
bmain_relations->entry_items_pool);
|
||||
from_id_entry->next = (*entry_p)->from_ids;
|
||||
from_id_entry->id_pointer.from = id_self;
|
||||
from_id_entry->session_uuid = id_self->session_uuid;
|
||||
from_id_entry->id_pointer.from = self_id;
|
||||
from_id_entry->session_uuid = self_id->session_uuid;
|
||||
from_id_entry->usage_flag = cb_flag;
|
||||
(*entry_p)->from_ids = from_id_entry;
|
||||
}
|
||||
|
||||
@@ -1165,17 +1165,17 @@ static void id_buffer_init_from_id(BLO_Write_IDBuffer *id_buffer, ID *id, const
|
||||
* linked data is tagged accordingly. */
|
||||
static int write_id_direct_linked_data_process_cb(LibraryIDLinkCallbackData *cb_data)
|
||||
{
|
||||
ID *id_self = cb_data->id_self;
|
||||
ID *self_id = cb_data->self_id;
|
||||
ID *id = *cb_data->id_pointer;
|
||||
const int cb_flag = cb_data->cb_flag;
|
||||
|
||||
if (id == nullptr || !ID_IS_LINKED(id)) {
|
||||
return IDWALK_RET_NOP;
|
||||
}
|
||||
BLI_assert(!ID_IS_LINKED(id_self));
|
||||
BLI_assert(!ID_IS_LINKED(self_id));
|
||||
BLI_assert((cb_flag & IDWALK_CB_INDIRECT_USAGE) == 0);
|
||||
|
||||
if (id_self->tag & LIB_TAG_RUNTIME) {
|
||||
if (self_id->tag & LIB_TAG_RUNTIME) {
|
||||
return IDWALK_RET_NOP;
|
||||
}
|
||||
|
||||
|
||||
@@ -462,7 +462,7 @@ static int foreach_id_cow_detect_need_for_update_callback(LibraryIDLinkCallbackD
|
||||
}
|
||||
|
||||
DepsgraphNodeBuilder *builder = static_cast<DepsgraphNodeBuilder *>(cb_data->user_data);
|
||||
ID *id_cow_self = cb_data->id_self;
|
||||
ID *id_cow_self = cb_data->self_id;
|
||||
|
||||
return builder->foreach_id_cow_detect_need_for_update_callback(id_cow_self, id);
|
||||
}
|
||||
|
||||
@@ -584,11 +584,11 @@ static int gather_frames_to_render_for_id(LibraryIDLinkCallbackData *cb_data)
|
||||
}
|
||||
ID *id = *id_p;
|
||||
|
||||
ID *id_self = cb_data->id_self;
|
||||
ID *self_id = cb_data->self_id;
|
||||
const int cb_flag = cb_data->cb_flag;
|
||||
if (cb_flag == IDWALK_CB_LOOPBACK || id == id_self) {
|
||||
if (cb_flag == IDWALK_CB_LOOPBACK || id == self_id) {
|
||||
/* IDs may end up referencing themselves one way or the other, and those
|
||||
* (the id_self ones) have always already been processed. */
|
||||
* (the self_id ones) have always already been processed. */
|
||||
return IDWALK_RET_STOP_RECURSION;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,16 +99,16 @@ static bool memfile_undosys_step_encode(struct bContext * /*C*/,
|
||||
|
||||
static int memfile_undosys_step_id_reused_cb(LibraryIDLinkCallbackData *cb_data)
|
||||
{
|
||||
ID *id_self = cb_data->id_self;
|
||||
ID *self_id = cb_data->self_id;
|
||||
ID **id_pointer = cb_data->id_pointer;
|
||||
BLI_assert((id_self->tag & LIB_TAG_UNDO_OLD_ID_REUSED_UNCHANGED) != 0);
|
||||
BLI_assert((self_id->tag & LIB_TAG_UNDO_OLD_ID_REUSED_UNCHANGED) != 0);
|
||||
|
||||
ID *id = *id_pointer;
|
||||
if (id != nullptr && !ID_IS_LINKED(id) && (id->tag & LIB_TAG_UNDO_OLD_ID_REUSED_UNCHANGED) == 0)
|
||||
{
|
||||
bool do_stop_iter = true;
|
||||
if (GS(id_self->name) == ID_OB) {
|
||||
Object *ob_self = (Object *)id_self;
|
||||
if (GS(self_id->name) == ID_OB) {
|
||||
Object *ob_self = (Object *)self_id;
|
||||
if (ob_self->type == OB_ARMATURE) {
|
||||
if (ob_self->data == id) {
|
||||
BLI_assert(GS(id->name) == ID_AR);
|
||||
|
||||
Reference in New Issue
Block a user