IDManagement: change IDTypeInfo.owner_get to instead return address of the owner_id pointer.

Also rename the callback. That way, we can keep moving toward a more
generic handling of those embedded IDs (think e.g. about copy code).
This commit is contained in:
2022-09-08 16:32:35 +02:00
parent 462014b59b
commit 406243c2fd
41 changed files with 57 additions and 54 deletions

View File

@@ -85,7 +85,7 @@ typedef void (*IDTypeForeachCacheFunction)(struct ID *id,
typedef void (*IDTypeForeachPathFunction)(struct ID *id, struct BPathForeachPathData *bpath_data);
typedef struct ID *(*IDTypeEmbeddedOwnerGetFunction)(struct ID *id);
typedef struct ID **(*IDTypeEmbeddedOwnerPointerGetFunction)(struct ID *id);
typedef void (*IDTypeBlendWriteFunction)(struct BlendWriter *writer,
struct ID *id,
@@ -180,9 +180,9 @@ typedef struct IDTypeInfo {
IDTypeForeachPathFunction foreach_path;
/**
* For embedded IDs, return their owner ID.
* For embedded IDs, return the address of the pointer to their owner ID.
*/
IDTypeEmbeddedOwnerGetFunction owner_get;
IDTypeEmbeddedOwnerPointerGetFunction owner_pointer_get;
/* ********** Callbacks for reading and writing .blend files. ********** */

View File

@@ -315,7 +315,7 @@ IDTypeInfo IDType_ID_AC = {
.foreach_id = action_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = action_blend_write,
.blend_read_data = action_blend_read_data,

View File

@@ -313,7 +313,7 @@ IDTypeInfo IDType_ID_AR = {
.foreach_id = armature_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = armature_blend_write,
.blend_read_data = armature_blend_read_data,

View File

@@ -413,7 +413,7 @@ IDTypeInfo IDType_ID_BR = {
/* foreach_id */ brush_foreach_id,
/* foreach_cache */ nullptr,
/* foreach_path */ brush_foreach_path,
/* owner_get */ nullptr,
/* owner_pointer_get */ nullptr,
/* blend_write */ brush_blend_write,
/* blend_read_data */ brush_blend_read_data,

View File

@@ -146,7 +146,7 @@ IDTypeInfo IDType_ID_CF = {
.foreach_id = NULL,
.foreach_cache = NULL,
.foreach_path = cache_file_foreach_path,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = cache_file_blend_write,
.blend_read_data = cache_file_blend_read_data,

View File

@@ -186,7 +186,7 @@ IDTypeInfo IDType_ID_CA = {
.foreach_id = camera_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = camera_blend_write,
.blend_read_data = camera_blend_read_data,

View File

@@ -169,10 +169,10 @@ static void collection_foreach_id(ID *id, LibraryForeachIDData *data)
}
}
static ID *collection_owner_get(ID *id)
static ID **collection_owner_pointer_get(ID *id)
{
if ((id->flag & LIB_EMBEDDED_DATA) == 0) {
return id;
return NULL;
}
BLI_assert((id->tag & LIB_TAG_NO_MAIN) == 0);
@@ -182,7 +182,7 @@ static ID *collection_owner_get(ID *id)
BLI_assert(GS(master_collection->owner_id->name) == ID_SCE);
BLI_assert(((Scene *)master_collection->owner_id)->master_collection == master_collection);
return master_collection->owner_id;
return &master_collection->owner_id;
}
void BKE_collection_blend_write_nolib(BlendWriter *writer, Collection *collection)
@@ -393,7 +393,7 @@ IDTypeInfo IDType_ID_GR = {
.foreach_id = collection_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = collection_owner_get,
.owner_pointer_get = collection_owner_pointer_get,
.blend_write = collection_blend_write,
.blend_read_data = collection_blend_read_data,

View File

@@ -321,7 +321,7 @@ IDTypeInfo IDType_ID_CU_LEGACY = {
/* foreach_id */ curve_foreach_id,
/* foreach_cache */ nullptr,
/* foreach_path */ nullptr,
/* owner_get */ nullptr,
/* owner_pointer_get */ nullptr,
/* blend_write */ curve_blend_write,
/* blend_read_data */ curve_blend_read_data,

View File

@@ -216,7 +216,7 @@ IDTypeInfo IDType_ID_CV = {
/* foreach_id */ curves_foreach_id,
/* foreach_cache */ nullptr,
/* foreach_path */ nullptr,
/* owner_get */ nullptr,
/* owner_pointer_get */ nullptr,
/* blend_write */ curves_blend_write,
/* blend_read_data */ curves_blend_read_data,

View File

@@ -314,7 +314,7 @@ IDTypeInfo IDType_ID_GD = {
.foreach_id = greasepencil_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = greasepencil_blend_write,
.blend_read_data = greasepencil_blend_read_data,

View File

@@ -442,7 +442,7 @@ constexpr IDTypeInfo get_type_info()
info.foreach_id = nullptr;
info.foreach_cache = image_foreach_cache;
info.foreach_path = image_foreach_path;
info.owner_get = nullptr;
info.owner_pointer_get = nullptr;
info.blend_write = image_blend_write;
info.blend_read_data = image_blend_read_data;

View File

@@ -178,7 +178,7 @@ IDTypeInfo IDType_ID_IP = {
.foreach_id = NULL,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = NULL,
.blend_read_data = ipo_blend_read_data,

View File

@@ -91,14 +91,14 @@ static void shapekey_foreach_id(ID *id, LibraryForeachIDData *data)
BKE_LIB_FOREACHID_PROCESS_ID(data, key->from, IDWALK_CB_LOOPBACK);
}
static ID *shapekey_owner_get(ID *id)
static ID **shapekey_owner_pointer_get(ID *id)
{
Key *key = (Key *)id;
BLI_assert(key->from != NULL);
BLI_assert(BKE_key_from_id(key->from) == key);
return key->from;
return &key->from;
}
static void shapekey_blend_write(BlendWriter *writer, ID *id, const void *id_address)
@@ -215,7 +215,7 @@ IDTypeInfo IDType_ID_KE = {
.foreach_path = NULL,
/* A bit weird, due to shape-keys not being strictly speaking embedded data... But they also
* share a lot with those (non linkable, only ever used by one owner ID, etc.). */
.owner_get = shapekey_owner_get,
.owner_pointer_get = shapekey_owner_pointer_get,
.blend_write = shapekey_blend_write,
.blend_read_data = shapekey_blend_read_data,

View File

@@ -190,7 +190,7 @@ IDTypeInfo IDType_ID_LT = {
.foreach_id = lattice_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = lattice_blend_write,
.blend_read_data = lattice_blend_read_data,

View File

@@ -93,7 +93,7 @@ IDTypeInfo IDType_ID_LINK_PLACEHOLDER = {
.foreach_id = NULL,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = NULL,
.blend_read_data = NULL,
@@ -1968,8 +1968,11 @@ bool BKE_id_can_be_asset(const ID *id)
ID *BKE_id_owner_get(ID *id)
{
const IDTypeInfo *idtype = BKE_idtype_get_info_from_id(id);
if (idtype->owner_get != NULL) {
return idtype->owner_get(id);
if (idtype->owner_pointer_get != NULL) {
ID **owner_id_pointer = idtype->owner_pointer_get(id);
if (owner_id_pointer != NULL) {
return *owner_id_pointer;
}
}
return NULL;
}

View File

@@ -97,7 +97,7 @@ IDTypeInfo IDType_ID_LI = {
.foreach_id = library_foreach_id,
.foreach_cache = NULL,
.foreach_path = library_foreach_path,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = NULL,
.blend_read_data = library_blend_read_data,

View File

@@ -189,7 +189,7 @@ IDTypeInfo IDType_ID_LA = {
.foreach_id = light_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = light_blend_write,
.blend_read_data = light_blend_read_data,

View File

@@ -85,7 +85,7 @@ IDTypeInfo IDType_ID_LP = {
.foreach_id = lightprobe_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = lightprobe_blend_write,
.blend_read_data = lightprobe_blend_read_data,

View File

@@ -749,7 +749,7 @@ IDTypeInfo IDType_ID_LS = {
.foreach_id = linestyle_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = linestyle_blend_write,
.blend_read_data = linestyle_blend_read_data,

View File

@@ -249,7 +249,7 @@ IDTypeInfo IDType_ID_MSK = {
.foreach_id = mask_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = mask_blend_write,
.blend_read_data = mask_blend_read_data,

View File

@@ -256,7 +256,7 @@ IDTypeInfo IDType_ID_MA = {
.foreach_id = material_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = material_blend_write,
.blend_read_data = material_blend_read_data,

View File

@@ -180,7 +180,7 @@ IDTypeInfo IDType_ID_MB = {
/* foreach_id */ metaball_foreach_id,
/* foreach_cache */ nullptr,
/* foreach_path */ nullptr,
/* owner_get */ nullptr,
/* owner_pointer_get */ nullptr,
/* blend_write */ metaball_blend_write,
/* blend_read_data */ metaball_blend_read_data,

View File

@@ -402,7 +402,7 @@ IDTypeInfo IDType_ID_ME = {
/* foreach_id */ mesh_foreach_id,
/* foreach_cache */ nullptr,
/* foreach_path */ mesh_foreach_path,
/* owner_get */ nullptr,
/* owner_pointer_get */ nullptr,
/* blend_write */ mesh_blend_write,
/* blend_read_data */ mesh_blend_read_data,

View File

@@ -343,7 +343,7 @@ IDTypeInfo IDType_ID_MC = {
.foreach_id = movie_clip_foreach_id,
.foreach_cache = movie_clip_foreach_cache,
.foreach_path = movie_clip_foreach_path,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = movieclip_blend_write,
.blend_read_data = movieclip_blend_read_data,

View File

@@ -401,10 +401,10 @@ static void node_foreach_path(ID *id, BPathForeachPathData *bpath_data)
}
}
static ID *node_owner_get(ID *id)
static ID **node_owner_pointer_get(ID *id)
{
if ((id->flag & LIB_EMBEDDED_DATA) == 0) {
return id;
return NULL;
}
/* TODO: Sort this NO_MAIN or not for embedded node trees. See T86119. */
// BLI_assert((id->tag & LIB_TAG_NO_MAIN) == 0);
@@ -413,7 +413,7 @@ static ID *node_owner_get(ID *id)
BLI_assert(ntree->owner_id != NULL);
BLI_assert(ntreeFromID(ntree->owner_id) == ntree);
return ntree->owner_id;
return &ntree->owner_id;
}
static void write_node_socket_default_value(BlendWriter *writer, bNodeSocket *sock)
@@ -1036,7 +1036,7 @@ IDTypeInfo IDType_ID_NT = {
/* foreach_id */ node_foreach_id,
/* foreach_cache */ node_foreach_cache,
/* foreach_path */ node_foreach_path,
/* owner_get */ node_owner_get,
/* owner_pointer_get */ node_owner_pointer_get,
/* blend_write */ ntree_blend_write,
/* blend_read_data */ ntree_blend_read_data,

View File

@@ -1239,7 +1239,7 @@ IDTypeInfo IDType_ID_OB = {
/* foreach_id */ object_foreach_id,
/* foreach_cache */ nullptr,
/* foreach_path */ object_foreach_path,
/* owner_get */ nullptr,
/* owner_pointer_get */ nullptr,
/* blend_write */ object_blend_write,
/* blend_read_data */ object_blend_read_data,

View File

@@ -139,7 +139,7 @@ IDTypeInfo IDType_ID_PAL = {
/* foreach_id */ nullptr,
/* foreach_cache */ nullptr,
/* foreach_path */ nullptr,
/* owner_get */ nullptr,
/* owner_pointer_get */ nullptr,
/* blend_write */ palette_blend_write,
/* blend_read_data */ palette_blend_read_data,
@@ -207,7 +207,7 @@ IDTypeInfo IDType_ID_PC = {
/* foreach_id */ nullptr,
/* foreach_cache */ nullptr,
/* foreach_path */ nullptr,
/* owner_get */ nullptr,
/* owner_pointer_get */ nullptr,
/* blend_write */ paint_curve_blend_write,
/* blend_read_data */ paint_curve_blend_read_data,

View File

@@ -494,7 +494,7 @@ IDTypeInfo IDType_ID_PA = {
.foreach_id = particle_settings_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = particle_settings_blend_write,
.blend_read_data = particle_settings_blend_read_data,

View File

@@ -175,7 +175,7 @@ IDTypeInfo IDType_ID_PT = {
/* foreach_id */ pointcloud_foreach_id,
/* foreach_cache */ nullptr,
/* foreach_path */ nullptr,
/* owner_get */ nullptr,
/* owner_pointer_get */ nullptr,
/* blend_write */ pointcloud_blend_write,
/* blend_read_data */ pointcloud_blend_read_data,

View File

@@ -1675,7 +1675,7 @@ constexpr IDTypeInfo get_type_info()
info.foreach_id = scene_foreach_id;
info.foreach_cache = scene_foreach_cache;
info.foreach_path = scene_foreach_path;
info.owner_get = nullptr;
info.owner_pointer_get = nullptr;
info.blend_write = scene_blend_write;
info.blend_read_data = scene_blend_read_data;

View File

@@ -292,7 +292,7 @@ IDTypeInfo IDType_ID_SCR = {
.foreach_id = screen_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = screen_blend_write,
/* Cannot be used yet, because #direct_link_screen has a return value. */

View File

@@ -149,7 +149,7 @@ IDTypeInfo IDType_ID_SIM = {
/* foreach_id */ simulation_foreach_id,
/* foreach_cache */ nullptr,
/* foreach_path */ nullptr,
/* owner_get */ nullptr,
/* owner_pointer_get */ nullptr,
/* blend_write */ simulation_blend_write,
/* blend_read_data */ simulation_blend_read_data,

View File

@@ -211,7 +211,7 @@ IDTypeInfo IDType_ID_SO = {
.foreach_id = NULL,
.foreach_cache = sound_foreach_cache,
.foreach_path = sound_foreach_path,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = sound_blend_write,
.blend_read_data = sound_blend_read_data,

View File

@@ -94,7 +94,7 @@ IDTypeInfo IDType_ID_SPK = {
.foreach_id = speaker_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = speaker_blend_write,
.blend_read_data = speaker_blend_read_data,

View File

@@ -245,7 +245,7 @@ IDTypeInfo IDType_ID_TXT = {
.foreach_id = NULL,
.foreach_cache = NULL,
.foreach_path = text_foreach_path,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = text_blend_write,
.blend_read_data = text_blend_read_data,

View File

@@ -207,7 +207,7 @@ IDTypeInfo IDType_ID_TE = {
.foreach_id = texture_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = texture_blend_write,
.blend_read_data = texture_blend_read_data,

View File

@@ -171,7 +171,7 @@ IDTypeInfo IDType_ID_VF = {
.foreach_id = NULL,
.foreach_cache = NULL,
.foreach_path = vfont_foreach_path,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = vfont_blend_write,
.blend_read_data = vfont_blend_read_data,

View File

@@ -661,7 +661,7 @@ IDTypeInfo IDType_ID_VO = {
/* foreach_id */ volume_foreach_id,
/* foreach_cache */ volume_foreach_cache,
/* foreach_path */ volume_foreach_path,
/* owner_get */ nullptr,
/* owner_pointer_get */ nullptr,
/* blend_write */ volume_blend_write,
/* blend_read_data */ volume_blend_read_data,

View File

@@ -193,7 +193,7 @@ IDTypeInfo IDType_ID_WS = {
.foreach_id = workspace_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = workspace_blend_write,
.blend_read_data = workspace_blend_read_data,

View File

@@ -198,7 +198,7 @@ IDTypeInfo IDType_ID_WO = {
.foreach_id = world_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = world_blend_write,
.blend_read_data = world_blend_read_data,

View File

@@ -275,7 +275,7 @@ IDTypeInfo IDType_ID_WM = {
.foreach_id = window_manager_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_get = NULL,
.owner_pointer_get = NULL,
.blend_write = window_manager_blend_write,
.blend_read_data = window_manager_blend_read_data,