Commit: 3bc09c1c1ec9c1699ac872bc643d3e38c250803f
Author: Sybren A. Stüvel
Date: Fri Aug 21 11:56:03 2020 +0200
Branches: master
https://developer.blender.org/rB3bc09c1c1ec9c1699ac872bc643d3e38c250803f
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.
===================================================================
M source/blender/blenkernel/BKE_scene.h
M source/blender/blenkernel/intern/context.c
M source/blender/blenkernel/intern/scene.c
M source/blender/blenkernel/intern/sequencer.c
M source/blender/draw/intern/draw_manager.c
M source/blender/editors/render/render_update.c
M source/blender/editors/scene/scene_edit.c
M source/blender/editors/screen/screen_ops.c
M source/blender/editors/space_info/info_stats.c
M source/blender/editors/transform/transform_convert_object.c
M source/blender/io/collada/BlenderContext.cpp
M source/blender/makesrna/intern/rna_layer.c
M source/blender/makesrna/intern/rna_scene_api.c
M source/blender/makesrna/intern/rna_space_api.c
M source/blender/python/gpu/gpu_py_offscreen.c
M source/blender/render/intern/source/pipeline.c
M source/blender/windowmanager/intern/wm_draw.c
M source/blender/windowmanager/intern/wm_event_system.c
M source/blender/windowmanager/intern/wm_init_exit.c
M source/blender/windowmanager/xr/intern/wm_xr_session.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_scene.h
b/source/blender/blenkernel/BKE_scene.h
index 2a5e4527676..05966ec3989 100644
--- a/source/blender/blenkernel/BKE_scene.h
+++ b/source/blender/blenkernel/BKE_scene.h
@@ -219,10 +219,12 @@ void BKE_scene_ensure_depsgraph_hash(struct Scene *scene);
void BKE_scene_free_depsgraph_hash(struct Scene *scene);
void BKE_scene_free_view_layer_depsgraph(struct Scene *scene, struct ViewLayer
*view_layer);
-struct Depsgraph *BKE_scene_get_depsgraph(struct Main *bmain,
- struct Scene *scene,
- struct ViewLayer *view_layer,
- bool allocate);
+/* Do not allocate new depsgraph. */
+struct Depsgraph *BKE_scene_get_depsgraph(struct Scene *scene, struct
ViewLayer *view_layer);
+/* Allocate new depsgraph if necessary. */
+struct Depsgraph *BKE_scene_ensure_depsgraph(struct Main *bmain,
+ struct Scene *scene,
+ struct ViewLayer *view_layer);
struct GHash *BKE_scene_undo_depsgraphs_extract(struct Main *bmain);
void BKE_scene_undo_depsgraphs_restore(struct Main *bmain, struct GHash
*depsgraph_extract);
diff --git a/source/blender/blenkernel/intern/context.c
b/source/blender/blenkernel/intern/context.c
index e9ba3a5f873..dce14c4c082 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -1349,7 +1349,7 @@ Depsgraph *CTX_data_depsgraph_pointer(const bContext *C)
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
- Depsgraph *depsgraph = BKE_scene_get_depsgraph(bmain, scene, view_layer,
true);
+ Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
/* Dependency graph might have been just allocated, and hence it will not be
marked.
* This confuses redo system due to the lack of flushing changes back to the
original data.
* In the future we would need to check whether the CTX_wm_window(C) is in
editing mode (as an
@@ -1377,8 +1377,7 @@ Depsgraph *CTX_data_ensure_evaluated_depsgraph(const
bContext *C)
Depsgraph *CTX_data_depsgraph_on_load(const bContext *C)
{
- Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
- return BKE_scene_get_depsgraph(bmain, scene, view_layer, false);
+ return BKE_scene_get_depsgraph(scene, view_layer);
}
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);
diff --git a/source/blender/blenkernel/intern/sequencer.c
b/source/blender/blenkernel/intern/sequencer.c
index b4da0c5bd33..3e75f09fed6 100644
--- a/source/blender/blenkernel/intern/sequencer.c
+++ b/source/blender/blenkernel/intern/sequencer.c
@@ -3592,7 +3592,7 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData
*context,
}
/* opengl offscreen render */
- depsgraph = BKE_scene_get_depsgraph(context->bmain, scene, view_layer,
true);
+ depsgraph = BKE_scene_ensure_depsgraph(context->bmain, scene, view_layer);
BKE_scene_graph_update_for_newframe(depsgraph);
ibuf = sequencer_view3d_fn(
/* set for OpenGL render (NULL when scrubbing) */
diff --git a/source/blender/draw/intern/draw_manager.c
b/source/blender/draw/intern/draw_manager.c
index e17ec4f707e..b515a83959e 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -909,7 +909,7 @@ void DRW_cache_free_old_batches(Main *bmain)
for (scene = bmain->scenes.first; scene; scene = scene->id.next) {
for (view_layer = scene->view_layers.first; view_layer; view_layer =
view_layer->next) {
- Depsgraph *depsgraph = BKE_scene_get_depsgraph(bmain, scene, view_layer,
false);
+ Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer);
if (depsgraph == NULL) {
continue;
}
diff --git a/source/blender/editors/render/render_update.c
b/source/blender/editors/render/render_update.c
index 7d0ad42c703..ce454d5eac2 100644
--- a/source/blender/editors/render/render_update.c
+++ b/source/blender/editors/render/render_update.c
@@ -194,7 +194,7 @@ void ED_render_engine_changed(Main *bmain, const bool
update_scene_data)
update_ctx.scene = scene;
LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
/* TDODO(sergey): Iterate over depsgraphs instead? */
- update_ctx.depsgraph = BKE_scene_get_depsgraph(bmain, scene, view_layer,
true);
+ update_ctx.depsgraph = BKE_scene_ensure_depsgraph(bmain, scene,
view_layer);
update_ctx.view_layer = view_layer;
ED_render_id_flush_update(&update_ctx, &scene->id);
}
diff --git a/source/blender/editors/scene/scene_edit.c
b/source/blender/editors/scene/scene_edit.c
index d599c1cbcf0..47edb322701 100644
--- a/source/blender/editors/scene/scene_edit.c
+++ b/source/blender/editors/scene/scene_edit.c
@@ -116,7 +116,7 @@ bool ED_scene_delete(bContext *C, Main *bmain, Scene *scene)
/* Depsgraph updates after scene becomes active in a window. */
void ED_scene_change_update(Main *bmain, Scene *scene, ViewLayer *layer)
{
- Depsgraph *depsgraph = BKE_scene_get_depsgraph(bmain, scene, layer, true);
+ Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, layer);
BKE_scene_set_background(bmain, scene);
DEG_graph_relations_update(depsgraph);
diff --git a/source/blender/editors/screen/screen_ops.c
b/source/blender/editors/screen/screen_ops.c
index b39b0ca7db6..0022e0ef7b7 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -4432,7 +4432,7 @@ static int screen_animation_step(bContext *C, wmOperator
*UNUSED(op), const wmEv
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_dat
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs