[Bf-blender-cvs] [3bcafb6] soc-2016-cycles_denoising: Render API: Implement the denoising process as a job to keep the UI responsive

Lukas Stockner noreply at git.blender.org
Mon Jul 11 23:32:20 CEST 2016


Commit: 3bcafb6dc48def36d7e8a7f5dec5a04faf137715
Author: Lukas Stockner
Date:   Mon Jul 11 19:36:37 2016 +0200
Branches: soc-2016-cycles_denoising
https://developer.blender.org/rB3bcafb6dc48def36d7e8a7f5dec5a04faf137715

Render API: Implement the denoising process as a job to keep the UI responsive

===================================================================

M	intern/cycles/blender/blender_python.cpp
M	source/blender/editors/space_image/image_ops.c
M	source/blender/windowmanager/WM_api.h

===================================================================

diff --git a/intern/cycles/blender/blender_python.cpp b/intern/cycles/blender/blender_python.cpp
index 9fb39bd..2814fa5 100644
--- a/intern/cycles/blender/blender_python.cpp
+++ b/intern/cycles/blender/blender_python.cpp
@@ -717,8 +717,13 @@ static PyObject *postprocess_func(PyObject * /*self*/, PyObject *args)
 	BL::RenderResult b_rr(resultptr);
 
 	BlenderSession session(engine, userpref, scene);
+
+	python_thread_state_save(&session.python_thread_state);
+
 	session.denoise(b_rr);
 
+	python_thread_state_restore(&session.python_thread_state);
+
 	Py_RETURN_NONE;
 }
 
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 2c4c5f3..10aae98 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -3663,6 +3663,15 @@ void IMAGE_OT_clear_render_border(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+typedef struct PostprocessJob {
+	RenderResult *rr;
+	float *progress;
+
+	Scene *scene;
+	Image *ima;
+	ImageUser *iuser;
+} PostprocessJob;
+
 static int postprocess_poll(bContext *C)
 {
 	Scene *scene = CTX_data_scene(C);
@@ -3710,6 +3719,94 @@ static int postprocess_exec(bContext *C, wmOperator *UNUSED(op))
 	return OPERATOR_FINISHED;
 }
 
+static void postprocess_startjob(void *pj, short *stop, short *do_update, float *progress)
+{
+	PostprocessJob *job = pj;
+	job->progress = progress;
+
+	RE_engine_postprocess(job->scene, job->rr);
+}
+
+static void postprocess_endjob(void *pj) {
+	PostprocessJob *job = pj;
+	void *lock;
+	ImBuf *ibuf;
+
+	WM_main_add_notifier(NC_SCENE | ND_RENDER_RESULT, NULL);
+
+	ibuf = BKE_image_acquire_ibuf(job->ima, job->iuser, &lock);
+
+	if (ibuf)
+		ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
+	BKE_image_release_ibuf(job->ima, ibuf, lock);
+}
+
+static void postprocess_freejob(void *pj)
+{
+	PostprocessJob *job = pj;
+
+	BKE_image_release_renderresult(job->scene, job->ima);
+	MEM_freeN(pj);
+}
+
+static int postprocess_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+	wmJob *wm_job;
+	PostprocessJob *job;
+	Scene *scene = CTX_data_scene(C);
+	Image *ima = CTX_data_edit_image(C);
+	RenderResult *rr = BKE_image_acquire_renderresult(scene, ima);
+
+	if (WM_jobs_test(CTX_wm_manager(C), rr, WM_JOB_TYPE_POSTPROCESS))
+		return OPERATOR_CANCELLED;
+
+	WM_jobs_kill_all_except(CTX_wm_manager(C), CTX_wm_screen(C));
+	WM_cursor_wait(1);
+
+	job = MEM_callocN(sizeof(PostprocessJob), "postprocess job");
+	job->rr = rr;
+	job->scene = scene;
+	job->ima = ima;
+	job->iuser = &CTX_wm_space_image(C)->iuser;
+
+	wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), rr, "Postprocess", WM_JOB_EXCL_RENDER | WM_JOB_PRIORITY | WM_JOB_PROGRESS, WM_JOB_TYPE_POSTPROCESS);
+	WM_jobs_customdata_set(wm_job, job, postprocess_freejob);
+	WM_jobs_timer(wm_job, 0.2, NC_SCENE | ND_RENDER_RESULT, 0);
+	WM_jobs_callbacks(wm_job, postprocess_startjob, NULL, NULL, postprocess_endjob);
+
+	op->customdata = rr;
+
+	WM_jobs_start(CTX_wm_manager(C), wm_job);
+
+	WM_cursor_wait(0);
+
+	WM_event_add_modal_handler(C, op);
+
+	return OPERATOR_RUNNING_MODAL;
+}
+
+static int postprocess_modal(bContext *C, wmOperator *op, const wmEvent *event) {
+	RenderResult *rr = (RenderResult*) op->customdata;
+
+	if (0 == WM_jobs_test(CTX_wm_manager(C), rr, WM_JOB_TYPE_POSTPROCESS)) {
+		return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
+	}
+
+	switch (event->type) {
+		case ESCKEY:
+			return OPERATOR_RUNNING_MODAL;
+	}
+	return OPERATOR_PASS_THROUGH;
+}
+
+static void postprocess_cancel(bContext *C, wmOperator *op)
+{
+	wmWindowManager *wm = CTX_wm_manager(C);
+	RenderResult *rr = (RenderResult*) op->customdata;
+
+	WM_jobs_kill_type(wm, rr, WM_JOB_TYPE_POSTPROCESS);
+}
+
 void IMAGE_OT_postprocess(wmOperatorType *ot)
 {
 	/* identifiers */
@@ -3719,6 +3816,9 @@ void IMAGE_OT_postprocess(wmOperatorType *ot)
 
 	/* api callbacks */
 	ot->exec = postprocess_exec;
+	ot->invoke = postprocess_invoke;
+	ot->modal = postprocess_modal;
+	ot->cancel = postprocess_cancel;
 	ot->poll = postprocess_poll;
 
 	/* flags */
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 7a247d9..87b33b9 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -441,6 +441,7 @@ enum {
 	WM_JOB_TYPE_SEQ_BUILD_PREVIEW,
 	WM_JOB_TYPE_POINTCACHE,
 	WM_JOB_TYPE_DPAINT_BAKE,
+	WM_JOB_TYPE_POSTPROCESS,
 	/* add as needed, screencast, seq proxy build
 	 * if having hard coded values is a problem */
 };




More information about the Bf-blender-cvs mailing list