Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2021-07-12 17:03:46 +0300
committerBastien Montagne <bastien@blender.org>2021-07-26 18:36:46 +0300
commitabf3ce811f6e33213a51941b477668750d45c5b4 (patch)
treefb7d706710472120312d5d4e2e5cf6062f588541 /source/blender/blenkernel/intern/layer.c
parentcee67f3be2b3af987a34bb48f909ffad51c4eb0f (diff)
LayerCollections: Add a way to prevent their resync with Collection hierarchy.
This is an easy & safe, yet not-so-nice way to address the LayerCollections vs. Collections hierarchy resync problem. Currently this resync is enforced everytime something changes in the Collections hierarchy, which is extremely inneficient, and can even produce 'loss' of LayerCollection data during complex Collection processes. Current example is during Library Overrides resync process. New code: * Makes resync significantly faster (between 10 and 15%). * Fixes 'disappearing' layer collections settings on sub-collections' layers. NOTE: This is not a proper fix for the underlying issue. However, implementing and testing the 'lazy update' solution as proposed by {T73411} requires a significant amount of time (especially in testing and tracking all places where code would need to ensure LayerCollections are up-to-date), which is not possible currently. Differential Revision: https://developer.blender.org/D11889
Diffstat (limited to 'source/blender/blenkernel/intern/layer.c')
-rw-r--r--source/blender/blenkernel/intern/layer.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index 28282aaa823..0a0705649bc 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -737,6 +737,35 @@ int BKE_layer_collection_findindex(ViewLayer *view_layer, const LayerCollection
* in at least one layer collection. That list is also synchronized here, and
* stores state like selection. */
+/* This API allows to temporarily forbid resync of LayerCollections.
+ *
+ * This can greatly improve performances in cases where those functions get
+ * called a lot (e.g. during massive remappings of IDs).
+ *
+ * Usage of these should be done very carefully though. In particular, calling
+ * code must ensures it resync LayerCollections before any UI/Eevnt loop
+ * handling can happen.
+ *
+ * WARNING: This is not threadsafe at all, only use from main thread.
+ *
+ * NOTE: This is a quick and safe band-aid around the long-known issue
+ * regarding this resync process.
+ * Proper fix would be to make resync itself lazy, i.e. only happen
+ * when actually needed.
+ * See also T73411.
+ */
+static bool no_resync = false;
+
+void BKE_layer_collection_resync_forbid(void)
+{
+ no_resync = true;
+}
+
+void BKE_layer_collection_resync_allow(void)
+{
+ no_resync = false;
+}
+
static void layer_collection_objects_sync(ViewLayer *view_layer,
LayerCollection *layer,
ListBase *r_lb_new_object_bases,
@@ -933,6 +962,10 @@ static void layer_collection_sync(ViewLayer *view_layer,
*/
void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer)
{
+ if (no_resync) {
+ return;
+ }
+
if (!scene->master_collection) {
/* Happens for old files that don't have versioning applied yet. */
return;
@@ -997,6 +1030,10 @@ void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer)
void BKE_scene_collection_sync(const Scene *scene)
{
+ if (no_resync) {
+ return;
+ }
+
LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
BKE_layer_collection_sync(scene, view_layer);
}
@@ -1004,6 +1041,10 @@ void BKE_scene_collection_sync(const Scene *scene)
void BKE_main_collection_sync(const Main *bmain)
{
+ if (no_resync) {
+ return;
+ }
+
/* TODO: if a single collection changed, figure out which
* scenes it belongs to and only update those. */
@@ -1018,6 +1059,10 @@ void BKE_main_collection_sync(const Main *bmain)
void BKE_main_collection_sync_remap(const Main *bmain)
{
+ if (no_resync) {
+ return;
+ }
+
/* On remapping of object or collection pointers free caches. */
/* TODO: try to make this faster */
@@ -1320,6 +1365,10 @@ static void layer_collection_local_sync(ViewLayer *view_layer,
void BKE_layer_collection_local_sync(ViewLayer *view_layer, const View3D *v3d)
{
+ if (no_resync) {
+ return;
+ }
+
const unsigned short local_collections_uuid = v3d->local_collections_uuid;
/* Reset flags and set the bases visible by default. */
@@ -1337,6 +1386,10 @@ void BKE_layer_collection_local_sync(ViewLayer *view_layer, const View3D *v3d)
*/
void BKE_layer_collection_local_sync_all(const Main *bmain)
{
+ if (no_resync) {
+ return;
+ }
+
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {