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:
authorSybren A. Stüvel <sybren@blender.org>2020-08-21 12:56:03 +0300
committerSybren A. Stüvel <sybren@blender.org>2020-08-21 13:23:13 +0300
commit3bc09c1c1ec9c1699ac872bc643d3e38c250803f (patch)
treed9812280b0bf6e7f9b835d2e670063a26a9d4ffd /source/blender/blenkernel/intern/scene.c
parente7767ba6be99a85349975b8da37b8cb8b9a3d6a9 (diff)
Cleanup: split `BKE_scene_get_depsgraph()` into two functions
Split the depsgraph allocation into a separate function `BKE_scene_ensure_depsgraph()`. Parameters are only passed to those functions that actually need them. This removes the the "if that boolean is `false` this pointer is allowed to be `NULL`" logic and more cleanly decouples code. No functional changes.
Diffstat (limited to 'source/blender/blenkernel/intern/scene.c')
-rw-r--r--source/blender/blenkernel/intern/scene.c54
1 files changed, 35 insertions, 19 deletions
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 552076f87ca..d11cc2289c8 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -1609,7 +1609,7 @@ void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph)
*/
void BKE_scene_view_layer_graph_evaluated_ensure(Main *bmain, Scene *scene, ViewLayer *view_layer)
{
- Depsgraph *depsgraph = BKE_scene_get_depsgraph(bmain, scene, view_layer, true);
+ Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
DEG_make_active(depsgraph);
BKE_scene_graph_update_tagged(depsgraph, bmain);
}
@@ -2243,11 +2243,9 @@ void BKE_scene_free_view_layer_depsgraph(Scene *scene, ViewLayer *view_layer)
/* Query depsgraph for a specific contexts. */
-static Depsgraph **scene_get_depsgraph_p(Main *bmain,
- Scene *scene,
+static Depsgraph **scene_get_depsgraph_p(Scene *scene,
ViewLayer *view_layer,
- const bool allocate_ghash_entry,
- const bool allocate_depsgraph)
+ const bool allocate_ghash_entry)
{
/* bmain may be NULL here! */
BLI_assert(scene != NULL);
@@ -2261,9 +2259,7 @@ static Depsgraph **scene_get_depsgraph_p(Main *bmain,
if (scene->depsgraph_hash == NULL) {
return NULL;
}
- /* Either ensure item is in the hash or simply return NULL if it's not,
- * depending on whether caller wants us to create depsgraph or not.
- */
+
DepsgraphKey key;
key.view_layer = view_layer;
@@ -2276,20 +2272,35 @@ static Depsgraph **scene_get_depsgraph_p(Main *bmain,
DepsgraphKey **key_ptr;
if (BLI_ghash_ensure_p_ex(
scene->depsgraph_hash, &key, (void ***)&key_ptr, (void ***)&depsgraph_ptr)) {
- /* Depsgraph was found in the ghash. */
- return depsgraph_ptr;
- }
-
- if (!allocate_depsgraph) {
- /* Not found and not allowed to allocate. */
- *depsgraph_ptr = NULL;
return depsgraph_ptr;
}
+ /* Depsgraph was not found in the ghash, but the key still needs allocating. */
*key_ptr = MEM_mallocN(sizeof(DepsgraphKey), __func__);
**key_ptr = key;
+ *depsgraph_ptr = NULL;
+ return depsgraph_ptr;
+}
+
+static Depsgraph **scene_ensure_depsgraph_p(Main *bmain, Scene *scene, ViewLayer *view_layer)
+{
+ BLI_assert(bmain != NULL);
+
+ Depsgraph **depsgraph_ptr = scene_get_depsgraph_p(scene, view_layer, true);
+ if (depsgraph_ptr == NULL) {
+ /* The scene has no depsgraph hash. */
+ return NULL;
+ }
+ if (*depsgraph_ptr != NULL) {
+ /* The depsgraph was found, no need to allocate. */
+ return depsgraph_ptr;
+ }
+
+ /* Allocate a new depsgraph. scene_get_depsgraph_p() already ensured that the pointer is stored
+ * in the scene's depsgraph hash. */
*depsgraph_ptr = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_VIEWPORT);
+
/* TODO(sergey): Would be cool to avoid string format print,
* but is a bit tricky because we can't know in advance whether
* we will ever enable debug messages for this depsgraph.
@@ -2301,9 +2312,15 @@ static Depsgraph **scene_get_depsgraph_p(Main *bmain,
return depsgraph_ptr;
}
-Depsgraph *BKE_scene_get_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer, bool allocate)
+Depsgraph *BKE_scene_get_depsgraph(Scene *scene, ViewLayer *view_layer)
+{
+ Depsgraph **depsgraph_ptr = scene_get_depsgraph_p(scene, view_layer, false);
+ return (depsgraph_ptr != NULL) ? *depsgraph_ptr : NULL;
+}
+
+Depsgraph *BKE_scene_ensure_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer)
{
- Depsgraph **depsgraph_ptr = scene_get_depsgraph_p(bmain, scene, view_layer, allocate, allocate);
+ Depsgraph **depsgraph_ptr = scene_ensure_depsgraph_p(bmain, scene, view_layer);
return (depsgraph_ptr != NULL) ? *depsgraph_ptr : NULL;
}
@@ -2369,8 +2386,7 @@ void BKE_scene_undo_depsgraphs_restore(Main *bmain, GHash *depsgraph_extract)
}
BLI_assert(*depsgraph_extract_ptr != NULL);
- Depsgraph **depsgraph_scene_ptr = scene_get_depsgraph_p(
- bmain, scene, view_layer, true, false);
+ Depsgraph **depsgraph_scene_ptr = scene_get_depsgraph_p(scene, view_layer, true);
BLI_assert(depsgraph_scene_ptr != NULL);
BLI_assert(*depsgraph_scene_ptr == NULL);