Compositor: add pre/post/cancel handlers and background job info

Main motivation is from T54314 where there was no way to read from a
Viewer image datablock after the compositor has run.
The only solution there was to do a full rerender (which obviously takes
much longer). Adding a handler avoids having to rerender.

This uses new syntax from rBf4456a4d3c97 and also adds "COMPOSITE" as a
job type that can be queried by `bpy.app.is_job_running`.

NOTE: there is another issue when multiple viewers are used and these
get active via RNA (compo execution is not triggered there yet -- unlike
when a viewer is selected in the Editor -- this is an issue of
`ED_node_set_active` vs. only `nodeSetActive`, but this will be tackled
separately)

Maniphest Tasks: T54314

Differential Revision: https://developer.blender.org/D15078
This commit is contained in:
Philipp Oeser 2022-05-31 10:22:43 +02:00
parent 9babe39de9
commit 16d329da28
Notes: blender-bot 2023-09-13 08:48:34 +02:00
Referenced by commit 0bc95b7b40, Compositor: handle NODE_DO_OUTPUT in RNA when setting a node active
Referenced by issue #54314, Contents of "Viewer Node" image block do not get updated
Referenced by issue #54314, Contents of "Viewer Node" image block do not get updated
Referenced by issue #109168, Regression: Immediate Blender Crash in 4.0 when updating image data blocks during playback
4 changed files with 32 additions and 2 deletions

View File

@ -100,6 +100,9 @@ typedef enum {
BKE_CB_EVT_OBJECT_BAKE_PRE,
BKE_CB_EVT_OBJECT_BAKE_COMPLETE,
BKE_CB_EVT_OBJECT_BAKE_CANCEL,
BKE_CB_EVT_COMPOSITE_PRE,
BKE_CB_EVT_COMPOSITE_POST,
BKE_CB_EVT_COMPOSITE_CANCEL,
BKE_CB_EVT_TOT,
} eCbEvent;

View File

@ -15,6 +15,7 @@
#include "DNA_text_types.h"
#include "DNA_world_types.h"
#include "BKE_callbacks.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_image.h"
@ -275,6 +276,7 @@ static void compo_startjob(void *cjv,
// XXX BIF_store_spare();
/* 1 is do_previews */
BKE_callback_exec_id(cj->bmain, &scene->id, BKE_CB_EVT_COMPOSITE_PRE);
if ((cj->scene->r.scemode & R_MULTIVIEW) == 0) {
ntreeCompositExecTree(cj->scene, ntree, &cj->scene->r, false, true, "");
@ -293,6 +295,22 @@ static void compo_startjob(void *cjv,
ntree->progress = nullptr;
}
static void compo_canceljob(void *cjv)
{
CompoJob *cj = (CompoJob *)cjv;
Main *bmain = cj->bmain;
Scene *scene = cj->scene;
BKE_callback_exec_id(bmain, &scene->id, BKE_CB_EVT_COMPOSITE_CANCEL);
}
static void compo_completejob(void *cjv)
{
CompoJob *cj = (CompoJob *)cjv;
Main *bmain = cj->bmain;
Scene *scene = cj->scene;
BKE_callback_exec_id(bmain, &scene->id, BKE_CB_EVT_COMPOSITE_POST);
}
/** \} */
} // namespace blender::ed::space_node
@ -339,7 +357,13 @@ void ED_node_composite_job(const bContext *C, struct bNodeTree *nodetree, Scene
/* setup job */
WM_jobs_customdata_set(wm_job, cj, compo_freejob);
WM_jobs_timer(wm_job, 0.1, NC_SCENE | ND_COMPO_RESULT, NC_SCENE | ND_COMPO_RESULT);
WM_jobs_callbacks(wm_job, compo_startjob, compo_initjob, compo_updatejob, nullptr);
WM_jobs_callbacks_ex(wm_job,
compo_startjob,
compo_initjob,
compo_updatejob,
nullptr,
compo_completejob,
compo_canceljob);
WM_jobs_start(CTX_wm_manager(C), wm_job);
}

View File

@ -137,6 +137,7 @@ const EnumPropertyItem rna_enum_wm_job_type_items[] = {
{WM_JOB_TYPE_RENDER, "RENDER", 0, "Regular rendering", ""},
{WM_JOB_TYPE_RENDER_PREVIEW, "RENDER_PREVIEW", 0, "Rendering previews", ""},
{WM_JOB_TYPE_OBJECT_BAKE, "OBJECT_BAKE", 0, "Object Baking", ""},
{WM_JOB_TYPE_COMPOSITE, "COMPOSITE", 0, "Compositing", ""},
{0, NULL, 0, NULL, NULL},
};

View File

@ -66,10 +66,12 @@ static PyStructSequence_Field app_cb_info_fields[] = {
{"xr_session_start_pre", "on starting an xr session (before)"},
{"annotation_pre", "on drawing an annotation (before)"},
{"annotation_post", "on drawing an annotation (after)"},
{"object_bake_pre", "before starting a bake job"},
{"object_bake_complete", "on completing a bake job; will be called in the main thread"},
{"object_bake_cancel", "on canceling a bake job; will be called in the main thread"},
{"composite_pre", "on a compositing background job (before)"},
{"composite_post", "on a compositing background job (after)"},
{"composite_cancel", "on a compositing background job (cancel)"},
/* sets the permanent tag */
#define APP_CB_OTHER_FIELDS 1