[Bf-blender-cvs] [12b36168957] blender-v3.3-release: IDType `get_owner`: add an optional hint about owner ID.

Bastien Montagne noreply at git.blender.org
Fri Aug 12 12:37:16 CEST 2022


Commit: 12b36168957dd27c253251555c29e8523b94fbe8
Author: Bastien Montagne
Date:   Fri Aug 12 10:39:03 2022 +0200
Branches: blender-v3.3-release
https://developer.blender.org/rB12b36168957dd27c253251555c29e8523b94fbe8

IDType `get_owner`: add an optional hint about owner ID.

In some cases, there is a chance code already knows who might be the
owner of the given ID, in which case it can be more efficient to check
it first (especially in cases like embedded node trees or scene
collections, where the only other way is to loop over all possible
owners currently).

Will be used in next commit in some Outliner fix.

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

M	source/blender/blenkernel/BKE_idtype.h
M	source/blender/blenkernel/BKE_lib_override.h
M	source/blender/blenkernel/intern/collection.c
M	source/blender/blenkernel/intern/key.c
M	source/blender/blenkernel/intern/lib_override.cc
M	source/blender/blenkernel/intern/lib_query.c
M	source/blender/blenkernel/intern/node.cc
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/space_outliner/outliner_collections.cc
M	source/blender/makesrna/intern/rna_path.cc
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h
index 30f7ed45859..04ea94cbfb4 100644
--- a/source/blender/blenkernel/BKE_idtype.h
+++ b/source/blender/blenkernel/BKE_idtype.h
@@ -85,7 +85,11 @@ typedef void (*IDTypeForeachCacheFunction)(struct ID *id,
 
 typedef void (*IDTypeForeachPathFunction)(struct ID *id, struct BPathForeachPathData *bpath_data);
 
-typedef struct ID *(*IDTypeEmbeddedOwnerGetFunction)(struct Main *bmain, struct ID *id);
+/** \param owner_id_hint: If non-NULL, a potential owner of the given embedded ID. Can speed up
+ * look-up of the owner ID in some cases. */
+typedef struct ID *(*IDTypeEmbeddedOwnerGetFunction)(struct Main *bmain,
+                                                     struct ID *id,
+                                                     struct ID *owner_id_hint);
 
 typedef void (*IDTypeBlendWriteFunction)(struct BlendWriter *writer,
                                          struct ID *id,
diff --git a/source/blender/blenkernel/BKE_lib_override.h b/source/blender/blenkernel/BKE_lib_override.h
index 9ad5a32e6f0..38469fd1b8e 100644
--- a/source/blender/blenkernel/BKE_lib_override.h
+++ b/source/blender/blenkernel/BKE_lib_override.h
@@ -66,10 +66,12 @@ void BKE_lib_override_library_free(struct IDOverrideLibrary **override, bool do_
  * \note This is especially useful when `id` is a non-real override (e.g. embedded ID like a master
  * collection or root node tree, or a shape key).
  *
+ * \param owner_id_hint If not NULL, a potential owner for the given override-embedded `id`.
  * \param r_owner_id If given, will be set with the actual ID owning the return liboverride data.
  */
 IDOverrideLibrary *BKE_lib_override_library_get(struct Main *bmain,
                                                 struct ID *id,
+                                                struct ID *owner_id_hint,
                                                 struct ID **r_owner_id);
 
 /**
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 09085fa8ffb..4967e3482c6 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -162,7 +162,7 @@ static void collection_foreach_id(ID *id, LibraryForeachIDData *data)
   }
 }
 
-static ID *collection_owner_get(Main *bmain, ID *id)
+static ID *collection_owner_get(Main *bmain, ID *id, ID *owner_id_hint)
 {
   if ((id->flag & LIB_EMBEDDED_DATA) == 0) {
     return id;
@@ -172,6 +172,11 @@ static ID *collection_owner_get(Main *bmain, ID *id)
   Collection *master_collection = (Collection *)id;
   BLI_assert((master_collection->flag & COLLECTION_IS_MASTER) != 0);
 
+  if (owner_id_hint != NULL && GS(owner_id_hint->name) == ID_SCE &&
+      ((Scene *)owner_id_hint)->master_collection == master_collection) {
+    return owner_id_hint;
+  }
+
   LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
     if (scene->master_collection == master_collection) {
       return &scene->id;
@@ -713,7 +718,8 @@ void BKE_collection_new_name_get(Collection *collection_parent, char *rname)
     name = BLI_strdup(DATA_("Collection"));
   }
   else if (collection_parent->flag & COLLECTION_IS_MASTER) {
-    name = BLI_sprintfN(DATA_("Collection %d"), BLI_listbase_count(&collection_parent->children) + 1);
+    name = BLI_sprintfN(DATA_("Collection %d"),
+                        BLI_listbase_count(&collection_parent->children) + 1);
   }
   else {
     const int number = BLI_listbase_count(&collection_parent->children) + 1;
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index 07ce4e46e9b..461a6f15ca1 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -91,7 +91,7 @@ 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(Main *UNUSED(bmain), ID *id)
+static ID *shapekey_owner_get(Main *UNUSED(bmain), ID *id, ID *UNUSED(owner_id_hint))
 {
   return ((Key *)id)->from;
 }
diff --git a/source/blender/blenkernel/intern/lib_override.cc b/source/blender/blenkernel/intern/lib_override.cc
index 758a317e415..05a00fb54fd 100644
--- a/source/blender/blenkernel/intern/lib_override.cc
+++ b/source/blender/blenkernel/intern/lib_override.cc
@@ -94,6 +94,7 @@ BLI_INLINE void lib_override_object_posemode_transfer(ID *id_dst, ID *id_src)
 /** Get override data for a given ID. Needed because of our beloved shape keys snowflake. */
 BLI_INLINE const IDOverrideLibrary *BKE_lib_override_library_get(const Main *bmain,
                                                                  const ID *id,
+                                                                 const ID *owner_id_hint,
                                                                  const ID **r_owner_id)
 {
   if (r_owner_id != nullptr) {
@@ -104,7 +105,8 @@ BLI_INLINE const IDOverrideLibrary *BKE_lib_override_library_get(const Main *bma
     if (id_type->owner_get != nullptr) {
       /* The #IDTypeInfo::owner_get callback should not modify the arguments, so casting away const
        * is okay. */
-      const ID *owner_id = id_type->owner_get(const_cast<Main *>(bmain), const_cast<ID *>(id));
+      const ID *owner_id = id_type->owner_get(
+          const_cast<Main *>(bmain), const_cast<ID *>(id), const_cast<ID *>(owner_id_hint));
       if (r_owner_id != nullptr) {
         *r_owner_id = owner_id;
       }
@@ -115,13 +117,17 @@ BLI_INLINE const IDOverrideLibrary *BKE_lib_override_library_get(const Main *bma
   return id->override_library;
 }
 
-IDOverrideLibrary *BKE_lib_override_library_get(Main *bmain, ID *id, ID **r_owner_id)
+IDOverrideLibrary *BKE_lib_override_library_get(Main *bmain,
+                                                ID *id,
+                                                ID *owner_id_hint,
+                                                ID **r_owner_id)
 {
   /* Reuse the implementation of the const access function, which does not change the arguments.
    * Add const explicitly to make it clear to the compiler to avoid just calling this function. */
   return const_cast<IDOverrideLibrary *>(
       BKE_lib_override_library_get(const_cast<const Main *>(bmain),
                                    const_cast<const ID *>(id),
+                                   const_cast<const ID *>(owner_id_hint),
                                    const_cast<const ID **>(r_owner_id)));
 }
 
@@ -319,7 +325,7 @@ bool BKE_lib_override_library_is_system_defined(const Main *bmain, const ID *id)
 {
   if (ID_IS_OVERRIDE_LIBRARY(id)) {
     const ID *override_owner_id;
-    BKE_lib_override_library_get(bmain, id, &override_owner_id);
+    BKE_lib_override_library_get(bmain, id, nullptr, &override_owner_id);
     return (override_owner_id->override_library->flag & IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED) !=
            0;
   }
@@ -1087,8 +1093,9 @@ static void lib_override_overrides_group_tag_recursive(LibOverrideGroupTagData *
     }
 
     const Library *reference_lib =
-        BKE_lib_override_library_get(bmain, id_owner, nullptr)->reference->lib;
-    const ID *to_id_reference = BKE_lib_override_library_get(bmain, to_id, nullptr)->reference;
+        BKE_lib_override_library_get(bmain, id_owner, nullptr, nullptr)->reference->lib;
+    const ID *to_id_reference =
+        BKE_lib_override_library_get(bmain, to_id, nullptr, nullptr)->reference;
     if (to_id_reference->lib != reference_lib) {
       /* We do not override data-blocks from other libraries, nor do we process them. */
       continue;
@@ -1439,7 +1446,7 @@ static ID *lib_override_root_find(Main *bmain, ID *id, const int curr_level, int
     BLI_assert(id->flag & LIB_EMBEDDED_DATA_LIB_OVERRIDE);
     ID *id_owner;
     int best_level_placeholder = 0;
-    BKE_lib_override_library_get(bmain, id, &id_owner);
+    BKE_lib_override_library_get(bmain, id, nullptr, &id_owner);
     return lib_override_root_find(bmain, id_owner, curr_level + 1, &best_level_placeholder);
   }
   /* This way we won't process again that ID, should we encounter it again through another
@@ -1478,7 +1485,7 @@ static ID *lib_override_root_find(Main *bmain, ID *id, const int curr_level, int
     BLI_assert(id->flag & LIB_EMBEDDED_DATA_LIB_OVERRIDE);
     ID *id_owner;
     int best_level_placeholder = 0;
-    BKE_lib_override_library_get(bmain, best_root_id_candidate, &id_owner);
+    BKE_lib_override_library_get(bmain, best_root_id_candidate, nullptr, &id_owner);
     best_root_id_candidate = lib_override_root_find(
         bmain, id_owner, curr_level + 1, &best_level_placeholder);
   }
@@ -1795,7 +1802,8 @@ static bool lib_override_library_resync(Main *bmain,
         /* While this should not happen in typical cases (and won't be properly supported here),
          * user is free to do all kind of very bad things, including having different local
          * overrides of a same linked ID in a same hierarchy. */
-        IDOverrideLibrary *id_override_library = BKE_lib_override_library_get(bmain, id, nullptr);
+        IDOverrideLibrary *id_override_library = BKE_lib_override_library_get(
+            bmain, id, nullptr, nullptr);
 
         if (id_override_library->hierarchy_root != id_root->override_library->hierarchy_root) {
           continue;
@@ -2177,7 +2185,7 @@ static ID *lib_override_library_main_resync_root_get(Main *bmain, ID *id)
   if (!ID_IS_OVERRIDE_LIBRARY_REAL(id)) {
     const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id);
     if (id_type->owner_get != nullptr) {
-      id = id_type->owner_get(bmain, id);
+      id = id_type->owner_get(bmain, id, nullptr);
     }
     BLI_assert(ID_IS_OVERRIDE_LIBRARY_REAL(id));
   }
diff --git a/source/blender/blenkernel/intern/lib_query.c b/source/blender/blenkernel/intern/lib_query.c
index a869bf4c4b0..6b9d2afe87a 100644
--- a/source/blender/blenkernel/intern/lib_query.c
+++ b/source/blender/blenkernel/intern/lib_query.c
@@ -713,7 +713,7 @@ static void lib_query_unused_ids_tag_recurse(Main *bmain,
       /* Directly 'by-pass' to actual real ID owner. */
       const IDTypeInfo *type_info_from = BKE_idtype_get

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list