Add USER flags to BKE_library_foreach_ID_link
authorCampbell Barton <ideasman42@gmail.com>
Thu, 8 Oct 2015 09:09:30 +0000 (20:09 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 8 Oct 2015 09:14:15 +0000 (20:14 +1100)
This way callbacks can know if adjusting user-count is needed.

source/blender/blenkernel/BKE_library_query.h
source/blender/blenkernel/intern/library_query.c

index 50958f8ee80efb547656737b7fd9004e2013a2e3..9daf16268c80ae9d22dc657e31f60609a1665dd4 100644 (file)
@@ -38,6 +38,16 @@ enum {
        IDWALK_NOP = 0,
        IDWALK_NEVER_NULL = (1 << 0),
        IDWALK_NEVER_SELF = (1 << 1),
+
+       /**
+        * Adjusts #ID.us reference-count.
+        * \note keep in sync with 'newlibadr_us' use in readfile.c
+        */
+       IDWALK_USER = (1 << 8),
+       /**
+        * Ensure #ID.us is at least 1 on use.
+        */
+       IDWALK_USER_ONE = (1 << 9),
 };
 
 /* Call a callback for each ID link which the given ID uses.
index 3ba53fa3f997cb84a65a8e2a87fab4ac8fc6d1ef..4e78c7b5049e1a350b3c8453024a6952e46c498d 100644 (file)
@@ -139,7 +139,7 @@ static void library_foreach_animationData(LibraryForeachIDData *data, AnimData *
 static void library_foreach_mtex(LibraryForeachIDData *data, MTex *mtex)
 {
        FOREACH_CALLBACK_INVOKE(data->self_id, mtex->object, data->flag, data->callback, data->user_data, IDWALK_NOP);
-       FOREACH_CALLBACK_INVOKE(data->self_id, mtex->tex, data->flag, data->callback, data->user_data, IDWALK_NOP);
+       FOREACH_CALLBACK_INVOKE(data->self_id, mtex->tex, data->flag, data->callback, data->user_data, IDWALK_USER);
 }
 
 
@@ -178,7 +178,7 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
                        Base *base;
 
                        CALLBACK_INVOKE(scene->camera, IDWALK_NOP);
-                       CALLBACK_INVOKE(scene->world, IDWALK_NOP);
+                       CALLBACK_INVOKE(scene->world, IDWALK_USER);
                        CALLBACK_INVOKE(scene->set, IDWALK_NOP);
                        if (scene->basact) {
                                CALLBACK_INVOKE(scene->basact->object, IDWALK_NOP);
@@ -190,10 +190,10 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
                                FreestyleLineSet *fls;
 
                                if (srl->mat_override) {
-                                       CALLBACK_INVOKE(srl->mat_override, IDWALK_NOP);
+                                       CALLBACK_INVOKE(srl->mat_override, IDWALK_USER);
                                }
                                if (srl->light_override) {
-                                       CALLBACK_INVOKE(srl->light_override, IDWALK_NOP);
+                                       CALLBACK_INVOKE(srl->light_override, IDWALK_USER);
                                }
                                for (fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) {
                                        if (fmc->script) {
@@ -202,10 +202,10 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
                                }
                                for (fls = srl->freestyleConfig.linesets.first; fls; fls = fls->next) {
                                        if (fls->group) {
-                                               CALLBACK_INVOKE(fls->group, IDWALK_NOP);
+                                               CALLBACK_INVOKE(fls->group, IDWALK_USER);
                                        }
                                        if (fls->linestyle) {
-                                               CALLBACK_INVOKE(fls->linestyle, IDWALK_NOP);
+                                               CALLBACK_INVOKE(fls->linestyle, IDWALK_USER);
                                        }
                                }
                        }
@@ -216,16 +216,16 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
                                {
                                        CALLBACK_INVOKE(seq->scene, IDWALK_NOP);
                                        CALLBACK_INVOKE(seq->scene_camera, IDWALK_NOP);
-                                       CALLBACK_INVOKE(seq->clip, IDWALK_NOP);
-                                       CALLBACK_INVOKE(seq->mask, IDWALK_NOP);
+                                       CALLBACK_INVOKE(seq->clip, IDWALK_USER);
+                                       CALLBACK_INVOKE(seq->mask, IDWALK_USER);
                                }
                                SEQ_END
                        }
 
-                       CALLBACK_INVOKE(scene->gpd, IDWALK_NOP);
+                       CALLBACK_INVOKE(scene->gpd, IDWALK_USER);
 
                        for (base = scene->base.first; base; base = base->next) {
-                               CALLBACK_INVOKE(base->object, IDWALK_NOP);
+                               CALLBACK_INVOKE(base->object, IDWALK_USER);
                        }
                        break;
                }
@@ -237,26 +237,26 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
                        /* object data special case */
                        if (object->type == OB_EMPTY) {
                                /* empty can have NULL or Image */
-                               CALLBACK_INVOKE_ID(object->data, IDWALK_NOP);
+                               CALLBACK_INVOKE_ID(object->data, IDWALK_USER);
                        }
                        else {
                                /* when set, this can't be NULL */
                                if (object->data) {
-                                       CALLBACK_INVOKE_ID(object->data, IDWALK_NEVER_NULL);
+                                       CALLBACK_INVOKE_ID(object->data, IDWALK_USER | IDWALK_NEVER_NULL);
                                }
                        }
 
                        CALLBACK_INVOKE(object->parent, IDWALK_NOP);
                        CALLBACK_INVOKE(object->track, IDWALK_NOP);
-                       CALLBACK_INVOKE(object->proxy, IDWALK_NOP);
+                       CALLBACK_INVOKE(object->proxy, IDWALK_USER);
                        CALLBACK_INVOKE(object->proxy_group, IDWALK_NOP);
                        CALLBACK_INVOKE(object->proxy_from, IDWALK_NOP);
-                       CALLBACK_INVOKE(object->poselib, IDWALK_NOP);
+                       CALLBACK_INVOKE(object->poselib, IDWALK_USER);
                        for (i = 0; i < object->totcol; i++) {
-                               CALLBACK_INVOKE(object->mat[i], IDWALK_NOP);
+                               CALLBACK_INVOKE(object->mat[i], IDWALK_USER);
                        }
-                       CALLBACK_INVOKE(object->gpd, IDWALK_NOP);
-                       CALLBACK_INVOKE(object->dup_group, IDWALK_NOP);
+                       CALLBACK_INVOKE(object->gpd, IDWALK_USER);
+                       CALLBACK_INVOKE(object->dup_group, IDWALK_USER);
 
                        if (object->particlesystem.first) {
                                ParticleSystem *psys;
@@ -267,14 +267,14 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
                        }
 
                        if (object->pd) {
-                               CALLBACK_INVOKE(object->pd->tex, IDWALK_NOP);
+                               CALLBACK_INVOKE(object->pd->tex, IDWALK_USER);
                                CALLBACK_INVOKE(object->pd->f_source, IDWALK_NOP);
                        }
 
                        if (object->pose) {
                                bPoseChannel *pchan;
                                for (pchan = object->pose->chanbase.first; pchan; pchan = pchan->next) {
-                                       CALLBACK_INVOKE(pchan->custom, IDWALK_NOP);
+                                       CALLBACK_INVOKE(pchan->custom, IDWALK_USER);
                                        BKE_constraints_id_loop(&pchan->constraints, library_foreach_constraintObjectLooper, &data);
                                }
                        }
@@ -299,10 +299,10 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
                case ID_ME:
                {
                        Mesh *mesh = (Mesh *) id;
-                       CALLBACK_INVOKE(mesh->texcomesh, IDWALK_NOP);
-                       CALLBACK_INVOKE(mesh->key, IDWALK_NOP);
+                       CALLBACK_INVOKE(mesh->texcomesh, IDWALK_USER);
+                       CALLBACK_INVOKE(mesh->key, IDWALK_USER);
                        for (i = 0; i < mesh->totcol; i++) {
-                               CALLBACK_INVOKE(mesh->mat[i], IDWALK_NOP);
+                               CALLBACK_INVOKE(mesh->mat[i], IDWALK_USER);
                        }
                        break;
                }
@@ -313,14 +313,14 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
                        CALLBACK_INVOKE(curve->bevobj, IDWALK_NOP);
                        CALLBACK_INVOKE(curve->taperobj, IDWALK_NOP);
                        CALLBACK_INVOKE(curve->textoncurve, IDWALK_NOP);
-                       CALLBACK_INVOKE(curve->key, IDWALK_NOP);
+                       CALLBACK_INVOKE(curve->key, IDWALK_USER);
                        for (i = 0; i < curve->totcol; i++) {
-                               CALLBACK_INVOKE(curve->mat[i], IDWALK_NOP);
+                               CALLBACK_INVOKE(curve->mat[i], IDWALK_USER);
                        }
-                       CALLBACK_INVOKE(curve->vfont, IDWALK_NOP);
-                       CALLBACK_INVOKE(curve->vfontb, IDWALK_NOP);
-                       CALLBACK_INVOKE(curve->vfonti, IDWALK_NOP);
-                       CALLBACK_INVOKE(curve->vfontbi, IDWALK_NOP);
+                       CALLBACK_INVOKE(curve->vfont, IDWALK_USER);
+                       CALLBACK_INVOKE(curve->vfontb, IDWALK_USER);
+                       CALLBACK_INVOKE(curve->vfonti, IDWALK_USER);
+                       CALLBACK_INVOKE(curve->vfontbi, IDWALK_USER);
                        break;
                }
 
@@ -328,7 +328,7 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
                {
                        MetaBall *metaball = (MetaBall *) id;
                        for (i = 0; i < metaball->totcol; i++) {
-                               CALLBACK_INVOKE(metaball->mat[i], IDWALK_NOP);
+                               CALLBACK_INVOKE(metaball->mat[i], IDWALK_USER);
                        }
                        break;
                }
@@ -342,7 +342,7 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
                                }
                        }
                        CALLBACK_INVOKE(material->nodetree, IDWALK_NOP);
-                       CALLBACK_INVOKE(material->group, IDWALK_NOP);
+                       CALLBACK_INVOKE(material->group, IDWALK_USER);
                        break;
                }
 
@@ -350,14 +350,14 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
                {
                        Tex *texture = (Tex *) id;
                        CALLBACK_INVOKE(texture->nodetree, IDWALK_NOP);
-                       CALLBACK_INVOKE(texture->ima, IDWALK_NOP);
+                       CALLBACK_INVOKE(texture->ima, IDWALK_USER);
                        break;
                }
 
                case ID_LT:
                {
                        Lattice *lattice = (Lattice *) id;
-                       CALLBACK_INVOKE(lattice->key, IDWALK_NOP);
+                       CALLBACK_INVOKE(lattice->key, IDWALK_USER);
                        break;
                }
 
@@ -390,7 +390,7 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
                case ID_SCR:
                {
                        bScreen *screen = (bScreen *) id;
-                       CALLBACK_INVOKE(screen->scene, IDWALK_NOP);
+                       CALLBACK_INVOKE(screen->scene, IDWALK_USER_ONE);
                        break;
                }
 
@@ -409,7 +409,7 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
                case ID_SPK:
                {
                        Speaker *speaker = (Speaker *) id;
-                       CALLBACK_INVOKE(speaker->sound, IDWALK_NOP);
+                       CALLBACK_INVOKE(speaker->sound, IDWALK_USER);
                        break;
                }
 
@@ -428,7 +428,7 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
                        bNodeTree *ntree = (bNodeTree *) id;
                        bNode *node;
                        for (node = ntree->nodes.first; node; node = node->next) {
-                               CALLBACK_INVOKE_ID(node->id, IDWALK_NOP);
+                               CALLBACK_INVOKE_ID(node->id, IDWALK_USER);
                        }
                        break;
                }
@@ -460,13 +460,13 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
                        MovieTracking *tracking = &clip->tracking;
                        MovieTrackingObject *object;
 
-                       CALLBACK_INVOKE(clip->gpd, IDWALK_NOP);
+                       CALLBACK_INVOKE(clip->gpd, IDWALK_USER);
                        for (object = tracking->objects.first; object; object = object->next) {
                                ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object);
                                MovieTrackingTrack *track;
 
                                for (track = tracksbase->first; track; track = track->next) {
-                                       CALLBACK_INVOKE(track->gpd, IDWALK_NOP);
+                                       CALLBACK_INVOKE(track->gpd, IDWALK_USER);
                                }
                        }
                        break;
@@ -482,7 +482,7 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
                                for (mask_spline = mask_layer->splines.first; mask_spline; mask_spline = mask_spline->next) {
                                        for (i = 0; i < mask_spline->tot_point; i++) {
                                                MaskSplinePoint *point = &mask_spline->points[i];
-                                               CALLBACK_INVOKE_ID(point->parent.id, IDWALK_NOP);
+                                               CALLBACK_INVOKE_ID(point->parent.id, IDWALK_USER);
                                        }
                                }
                        }