Depsgraph: Wrap context used for editors update callback into a structure

This way we can extend it much easier.
This commit is contained in:
Sergey Sharybin 2017-11-28 13:04:21 +01:00
parent db2a603f6e
commit 9d6bd665e3
8 changed files with 75 additions and 34 deletions

View File

@ -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);
}

View File

@ -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,

View File

@ -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);
}
}

View File

@ -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 ------------------------------------------------------ */

View File

@ -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)

View File

@ -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. */

View File

@ -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);

View File

@ -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: