diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-11-28 15:04:21 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-11-28 16:24:56 +0300 |
commit | 9d6bd665e31badbc98ac4c86a4af4f1211d34587 (patch) | |
tree | ee8464e7afecec1888e7b081d0fc1198decfaa02 /source/blender | |
parent | db2a603f6ef8ffc6f0b72fe108710d88ccd2f85d (diff) |
Depsgraph: Wrap context used for editors update callback into a structure
This way we can extend it much easier.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 4 | ||||
-rw-r--r-- | source/blender/depsgraph/DEG_depsgraph.h | 16 | ||||
-rw-r--r-- | source/blender/depsgraph/intern/depsgraph.cc | 9 | ||||
-rw-r--r-- | source/blender/depsgraph/intern/depsgraph_intern.h | 9 | ||||
-rw-r--r-- | source/blender/depsgraph/intern/depsgraph_tag.cc | 19 | ||||
-rw-r--r-- | source/blender/depsgraph/intern/eval/deg_eval_flush.cc | 7 | ||||
-rw-r--r-- | source/blender/editors/include/ED_render.h | 10 | ||||
-rw-r--r-- | source/blender/editors/render/render_update.c | 35 |
8 files changed, 75 insertions, 34 deletions
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index a345a273cac..d2218adb120 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -1541,7 +1541,7 @@ void BKE_scene_graph_update_tagged(EvaluationContext *eval_ctx, /* Update sound system animation (TODO, move to depsgraph). */ BKE_sound_update_scene(bmain, scene); /* Inform editors about possible changes. */ - DEG_ids_check_recalc(bmain, scene, false); + DEG_ids_check_recalc(bmain, scene, view_layer, false); /* Clear recalc flags. */ DEG_ids_clear_recalc(bmain); } @@ -1588,7 +1588,7 @@ void BKE_scene_graph_update_for_newframe(EvaluationContext *eval_ctx, /* Notify editors and python about recalc. */ BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_FRAME_CHANGE_POST); /* Inform editors about possible changes. */ - DEG_ids_check_recalc(bmain, scene, true); + DEG_ids_check_recalc(bmain, scene, view_layer, true); /* clear recalc flags */ DEG_ids_clear_recalc(bmain); } diff --git a/source/blender/depsgraph/DEG_depsgraph.h b/source/blender/depsgraph/DEG_depsgraph.h index dc6afee409c..25e5714a7d7 100644 --- a/source/blender/depsgraph/DEG_depsgraph.h +++ b/source/blender/depsgraph/DEG_depsgraph.h @@ -198,6 +198,7 @@ void DEG_graph_flush_update(struct Main *bmain, Depsgraph *depsgraph); */ void DEG_ids_check_recalc(struct Main *bmain, struct Scene *scene, + struct ViewLayer *view_layer, bool time); /* ************************************************ */ @@ -248,10 +249,17 @@ bool DEG_needs_eval(Depsgraph *graph); * to do their own updates based on changes. */ -typedef void (*DEG_EditorUpdateIDCb)(struct Main *bmain, struct ID *id); -typedef void (*DEG_EditorUpdateSceneCb)(struct Main *bmain, - struct Scene *scene, - int updated); +typedef struct DEGEditorUpdateContext { + struct Main *bmain; + struct Scene *scene; + struct ViewLayer *view_layer; +} DEGEditorUpdateContext; + +typedef void (*DEG_EditorUpdateIDCb)( + const DEGEditorUpdateContext *update_ctx, + struct ID *id); +typedef void (*DEG_EditorUpdateSceneCb)( + const DEGEditorUpdateContext *update_ctx, int updated); /* Set callbacks which are being called when depsgraph changes. */ void DEG_editors_set_update_cb(DEG_EditorUpdateIDCb id_func, diff --git a/source/blender/depsgraph/intern/depsgraph.cc b/source/blender/depsgraph/intern/depsgraph.cc index d60d4ad5a6f..936fe58b1f2 100644 --- a/source/blender/depsgraph/intern/depsgraph.cc +++ b/source/blender/depsgraph/intern/depsgraph.cc @@ -476,17 +476,18 @@ ID *Depsgraph::get_cow_id(const ID *id_orig) const return id_node->id_cow; } -void deg_editors_id_update(Main *bmain, ID *id) +void deg_editors_id_update(const DEGEditorUpdateContext *update_ctx, ID *id) { if (deg_editor_update_id_cb != NULL) { - deg_editor_update_id_cb(bmain, id); + deg_editor_update_id_cb(update_ctx, id); } } -void deg_editors_scene_update(Main *bmain, Scene *scene, bool updated) +void deg_editors_scene_update(const DEGEditorUpdateContext *update_ctx, + bool updated) { if (deg_editor_update_scene_cb != NULL) { - deg_editor_update_scene_cb(bmain, scene, updated); + deg_editor_update_scene_cb(update_ctx, updated); } } diff --git a/source/blender/depsgraph/intern/depsgraph_intern.h b/source/blender/depsgraph/intern/depsgraph_intern.h index 5ab090f3b3d..e7e472ea5d6 100644 --- a/source/blender/depsgraph/intern/depsgraph_intern.h +++ b/source/blender/depsgraph/intern/depsgraph_intern.h @@ -46,8 +46,9 @@ extern "C" { #include "intern/nodes/deg_node_operation.h" #include "intern/depsgraph.h" -struct Main; +struct DEGEditorUpdateContext; struct Group; +struct Main; struct Scene; namespace DEG { @@ -109,9 +110,11 @@ DepsNodeFactory *deg_node_get_factory(const DepsNode *node); /* Editors Integration -------------------------------------------------- */ -void deg_editors_id_update(struct Main *bmain, struct ID *id); +void deg_editors_id_update(const DEGEditorUpdateContext *update_ctx, + struct ID *id); -void deg_editors_scene_update(struct Main *bmain, struct Scene *scene, bool updated); +void deg_editors_scene_update(const DEGEditorUpdateContext *update_ctx, + bool updated); /* Tagging helpers ------------------------------------------------------ */ diff --git a/source/blender/depsgraph/intern/depsgraph_tag.cc b/source/blender/depsgraph/intern/depsgraph_tag.cc index b21a65c8273..89e90e70a68 100644 --- a/source/blender/depsgraph/intern/depsgraph_tag.cc +++ b/source/blender/depsgraph/intern/depsgraph_tag.cc @@ -352,13 +352,17 @@ void id_tag_update_base_flags(Depsgraph *graph, IDDepsNode *id_node) } } -void id_tag_update_editors_update(Main *bmain, Depsgraph * /*graph*/, ID *id) +void id_tag_update_editors_update(Main *bmain, Depsgraph *graph, ID *id) { /* NOTE: We handle this immediately, without delaying anything, to be * sure we don't cause threading issues with OpenGL. */ /* TODO(sergey): Make sure this works for CoW-ed datablocks as well. */ - deg_editors_id_update(bmain, id); + DEGEditorUpdateContext update_ctx = {NULL}; + update_ctx.bmain = bmain; + update_ctx.scene = graph->scene; + update_ctx.view_layer = graph->view_layer; + deg_editors_id_update(&update_ctx, id); } void id_tag_update_ntree_special(Main *bmain, Depsgraph *graph, ID *id, int flag) @@ -564,7 +568,10 @@ void DEG_on_visible_update(Main *bmain, const bool UNUSED(do_time)) /* Check if something was changed in the database and inform * editors about this. */ -void DEG_ids_check_recalc(Main *bmain, Scene *scene, bool time) +void DEG_ids_check_recalc(Main *bmain, + Scene *scene, + ViewLayer *view_layer, + bool time) { ListBase *lbarray[MAX_LIBARRAY]; int a; @@ -582,7 +589,11 @@ void DEG_ids_check_recalc(Main *bmain, Scene *scene, bool time) } } - DEG::deg_editors_scene_update(bmain, scene, (updated || time)); + DEGEditorUpdateContext update_ctx = {NULL}; + update_ctx.bmain = bmain; + update_ctx.scene = scene; + update_ctx.view_layer = view_layer; + DEG::deg_editors_scene_update(&update_ctx, (updated || time)); } void DEG_ids_clear_recalc(Main *bmain) diff --git a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc index 2a815934e92..5a07e88670b 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc @@ -118,6 +118,11 @@ void deg_graph_flush_updates(Main *bmain, Depsgraph *graph) } GSET_FOREACH_END(); + DEGEditorUpdateContext update_ctx = {NULL}; + update_ctx.bmain = bmain; + update_ctx.scene = graph->scene; + update_ctx.view_layer = graph->view_layer; + int num_flushed_objects = 0; while (!queue.empty()) { OperationDepsNode *node = queue.front(); @@ -139,7 +144,7 @@ void deg_graph_flush_updates(Main *bmain, Depsgraph *graph) */ id_cow->tag |= (id_orig->tag & LIB_TAG_ID_RECALC_ALL); if (deg_copy_on_write_is_expanded(id_cow)) { - deg_editors_id_update(bmain, id_cow); + deg_editors_id_update(&update_ctx, id_cow); } lib_id_recalc_tag(bmain, id_orig); /* TODO(sergey): For until we've got proper data nodes in the graph. */ diff --git a/source/blender/editors/include/ED_render.h b/source/blender/editors/include/ED_render.h index 1898b9cb5d1..b7317d75cd4 100644 --- a/source/blender/editors/include/ED_render.h +++ b/source/blender/editors/include/ED_render.h @@ -31,6 +31,7 @@ #include "DNA_vec_types.h" struct bContext; +struct DEGEditorUpdateContext; struct ID; struct Main; struct MTex; @@ -43,12 +44,15 @@ struct wmWindowManager; void ED_operatortypes_render(void); -/* render_shading.c */ +/* render_update.c */ -void ED_render_id_flush_update(struct Main *bmain, struct ID *id); void ED_render_engine_changed(struct Main *bmain); void ED_render_engine_area_exit(struct Main *bmain, struct ScrArea *sa); -void ED_render_scene_update(struct Main *bmain, struct Scene *scene, int updated); + +/* Callbacks handling data update events coming from depsgraph. */ + +void ED_render_id_flush_update(const struct DEGEditorUpdateContext *update_ctx, struct ID *id); +void ED_render_scene_update(const struct DEGEditorUpdateContext *update_ctx, int updated); void ED_viewport_render_kill_jobs(struct wmWindowManager *wm, struct Main *bmain, bool free_database); struct Scene *ED_render_job_get_scene(const struct bContext *C); diff --git a/source/blender/editors/render/render_update.c b/source/blender/editors/render/render_update.c index 2a316e1c793..311e1dbe589 100644 --- a/source/blender/editors/render/render_update.c +++ b/source/blender/editors/render/render_update.c @@ -70,6 +70,8 @@ #include "ED_render.h" #include "ED_view3d.h" +#include "DEG_depsgraph.h" + #include "WM_api.h" #include "render_intern.h" // own include @@ -78,10 +80,12 @@ extern Material defmaterial; /***************************** Render Engines ********************************/ -void ED_render_scene_update(Main *bmain, Scene *scene, int updated) +void ED_render_scene_update(const DEGEditorUpdateContext *update_ctx, int updated) { /* viewport rendering update on data changes, happens after depsgraph * updates if there was any change. context is set to the 3d view */ + Main *bmain = update_ctx->bmain; + Scene *scene = update_ctx->scene; bContext *C; wmWindowManager *wm; wmWindow *win; @@ -182,18 +186,21 @@ void ED_render_engine_area_exit(Main *bmain, ScrArea *sa) void ED_render_engine_changed(Main *bmain) { /* on changing the render engine type, clear all running render engines */ - bScreen *sc; - ScrArea *sa; - Scene *scene; - - for (sc = bmain->screen.first; sc; sc = sc->id.next) - for (sa = sc->areabase.first; sa; sa = sa->next) + for (bScreen *sc = bmain->screen.first; sc; sc = sc->id.next) { + for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) { ED_render_engine_area_exit(bmain, sa); - + } + } RE_FreePersistentData(); - - for (scene = bmain->scene.first; scene; scene = scene->id.next) { - ED_render_id_flush_update(bmain, &scene->id); + /* Inform all render engines and draw managers. */ + DEGEditorUpdateContext update_ctx = {NULL}; + update_ctx.bmain = bmain; + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + update_ctx.scene = scene; + LINKLIST_FOREACH(ViewLayer *, view_layer, &scene->view_layers) { + update_ctx.view_layer = view_layer; + ED_render_id_flush_update(&update_ctx, &scene->id); + } if (scene->nodetree) { ntreeCompositUpdateRLayers(scene->nodetree); } @@ -519,13 +526,15 @@ static void scene_changed(Main *bmain, Scene *scene) } } -void ED_render_id_flush_update(Main *bmain, ID *id) +void ED_render_id_flush_update(const DEGEditorUpdateContext *update_ctx, ID *id) { /* this can be called from render or baking thread when a python script makes * changes, in that case we don't want to do any editor updates, and making * GPU changes is not possible because OpenGL only works in the main thread */ - if (!BLI_thread_is_main()) + if (!BLI_thread_is_main()) { return; + } + Main *bmain = update_ctx->bmain; switch (GS(id->name)) { case ID_MA: |