diff options
7 files changed, 104 insertions, 9 deletions
diff --git a/source/blender/compositor/nodes/COM_CompositorNode.cpp b/source/blender/compositor/nodes/COM_CompositorNode.cpp index a78f96adfc6..81fb37cc238 100644 --- a/source/blender/compositor/nodes/COM_CompositorNode.cpp +++ b/source/blender/compositor/nodes/COM_CompositorNode.cpp @@ -32,6 +32,8 @@ CompositorNode::CompositorNode(bNode *editorNode) : Node(editorNode) void CompositorNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) { bNode *editorNode = this->getbNode(); + bool is_active = (editorNode->flag & NODE_DO_OUTPUT_RECALC) || + context->isRendering(); InputSocket *imageSocket = this->getInputSocket(0); InputSocket *alphaSocket = this->getInputSocket(1); @@ -42,10 +44,12 @@ void CompositorNode::convertToOperations(ExecutionSystem *graph, CompositorConte compositorOperation->setRenderData(context->getRenderData()); compositorOperation->setbNodeTree(context->getbNodeTree()); compositorOperation->setIgnoreAlpha(editorNode->custom2 & CMP_NODE_OUTPUT_IGNORE_ALPHA); + compositorOperation->setActive(is_active); imageSocket->relinkConnections(compositorOperation->getInputSocket(0), 0, graph); alphaSocket->relinkConnections(compositorOperation->getInputSocket(1)); depthSocket->relinkConnections(compositorOperation->getInputSocket(2)); graph->addOperation(compositorOperation); - addPreviewOperation(graph, context, compositorOperation->getInputSocket(0)); -} + if (is_active) + addPreviewOperation(graph, context, compositorOperation->getInputSocket(0)); +} diff --git a/source/blender/compositor/nodes/COM_SplitViewerNode.cpp b/source/blender/compositor/nodes/COM_SplitViewerNode.cpp index 37b888becca..0293f4926db 100644 --- a/source/blender/compositor/nodes/COM_SplitViewerNode.cpp +++ b/source/blender/compositor/nodes/COM_SplitViewerNode.cpp @@ -33,6 +33,11 @@ SplitViewerNode::SplitViewerNode(bNode *editorNode) : Node(editorNode) void SplitViewerNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) { + bNode *editorNode = this->getbNode(); + bool is_active = ((editorNode->flag & NODE_DO_OUTPUT_RECALC) && + (editorNode->flag & NODE_DO_OUTPUT) && this->isInActiveGroup()) || + context->isRendering(); + InputSocket *image1Socket = this->getInputSocket(0); InputSocket *image2Socket = this->getInputSocket(1); Image *image = (Image *)this->getbNode()->id; @@ -41,7 +46,7 @@ void SplitViewerNode::convertToOperations(ExecutionSystem *graph, CompositorCont SplitViewerOperation *splitViewerOperation = new SplitViewerOperation(); splitViewerOperation->setImage(image); splitViewerOperation->setImageUser(imageUser); - splitViewerOperation->setActive((this->getbNode()->flag & NODE_DO_OUTPUT) && this->isInActiveGroup()); + splitViewerOperation->setActive(is_active); splitViewerOperation->setSplitPercentage(this->getbNode()->custom1); splitViewerOperation->setViewSettings(context->getViewSettings()); @@ -56,7 +61,10 @@ void SplitViewerNode::convertToOperations(ExecutionSystem *graph, CompositorCont splitViewerOperation->setXSplit(!this->getbNode()->custom2); image1Socket->relinkConnections(splitViewerOperation->getInputSocket(0), 0, graph); image2Socket->relinkConnections(splitViewerOperation->getInputSocket(1), 1, graph); - addPreviewOperation(graph, context, splitViewerOperation->getInputSocket(0)); + + if (is_active) + addPreviewOperation(graph, context, splitViewerOperation->getInputSocket(0)); + graph->addOperation(splitViewerOperation); } } diff --git a/source/blender/compositor/nodes/COM_ViewerNode.cpp b/source/blender/compositor/nodes/COM_ViewerNode.cpp index 8f9e58fee13..2eb4c3a23ad 100644 --- a/source/blender/compositor/nodes/COM_ViewerNode.cpp +++ b/source/blender/compositor/nodes/COM_ViewerNode.cpp @@ -33,17 +33,21 @@ ViewerNode::ViewerNode(bNode *editorNode) : Node(editorNode) void ViewerNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) { + bNode *editorNode = this->getbNode(); + bool is_active = ((editorNode->flag & NODE_DO_OUTPUT_RECALC) && + (editorNode->flag & NODE_DO_OUTPUT) && this->isInActiveGroup()) || + context->isRendering(); + InputSocket *imageSocket = this->getInputSocket(0); InputSocket *alphaSocket = this->getInputSocket(1); InputSocket *depthSocket = this->getInputSocket(2); Image *image = (Image *)this->getbNode()->id; ImageUser *imageUser = (ImageUser *) this->getbNode()->storage; - bNode *editorNode = this->getbNode(); ViewerOperation *viewerOperation = new ViewerOperation(); viewerOperation->setbNodeTree(context->getbNodeTree()); viewerOperation->setImage(image); viewerOperation->setImageUser(imageUser); - viewerOperation->setActive((editorNode->flag & NODE_DO_OUTPUT) && this->isInActiveGroup()); + viewerOperation->setActive(is_active); viewerOperation->setChunkOrder((OrderOfChunks)editorNode->custom1); viewerOperation->setCenterX(editorNode->custom3); viewerOperation->setCenterY(editorNode->custom4); @@ -63,5 +67,7 @@ void ViewerNode::convertToOperations(ExecutionSystem *graph, CompositorContext * alphaSocket->relinkConnections(viewerOperation->getInputSocket(1)); depthSocket->relinkConnections(viewerOperation->getInputSocket(2)); graph->addOperation(viewerOperation); - addPreviewOperation(graph, context, viewerOperation->getInputSocket(0)); + + if (is_active) + addPreviewOperation(graph, context, viewerOperation->getInputSocket(0)); } diff --git a/source/blender/compositor/operations/COM_CompositorOperation.cpp b/source/blender/compositor/operations/COM_CompositorOperation.cpp index 43f491ad2d9..81e86efed42 100644 --- a/source/blender/compositor/operations/COM_CompositorOperation.cpp +++ b/source/blender/compositor/operations/COM_CompositorOperation.cpp @@ -50,12 +50,16 @@ CompositorOperation::CompositorOperation() : NodeOperation() this->m_depthInput = NULL; this->m_ignoreAlpha = false; + this->m_active = false; this->m_sceneName[0] = '\0'; } void CompositorOperation::initExecution() { + if (!this->m_active) + return; + // When initializing the tree during initial load the width and height can be zero. this->m_imageInput = getInputSocketReader(0); this->m_alphaInput = getInputSocketReader(1); @@ -70,6 +74,9 @@ void CompositorOperation::initExecution() void CompositorOperation::deinitExecution() { + if (!this->m_active) + return; + if (!isBreaked()) { Render *re = RE_GetRender(this->m_sceneName); RenderResult *rr = RE_AcquireResultWrite(re); diff --git a/source/blender/compositor/operations/COM_CompositorOperation.h b/source/blender/compositor/operations/COM_CompositorOperation.h index 27d29664610..d33e89ed742 100644 --- a/source/blender/compositor/operations/COM_CompositorOperation.h +++ b/source/blender/compositor/operations/COM_CompositorOperation.h @@ -66,19 +66,28 @@ private: */ SocketReader *m_depthInput; - /* Ignore any alpha input */ + /** + * @brief Ignore any alpha input + */ bool m_ignoreAlpha; + /** + * @brief operation is active for calculating final compo result + */ + bool m_active; public: CompositorOperation(); + const bool isActiveCompositorOutput() const { return this->m_active; } void executeRegion(rcti *rect, unsigned int tileNumber); void setSceneName(const char *sceneName) { BLI_strncpy(this->m_sceneName, sceneName, sizeof(this->m_sceneName)); } void setRenderData(const RenderData *rd) { this->m_rd = rd; } - bool isOutputOperation(bool rendering) const { return true; } + bool isOutputOperation(bool rendering) const { return this->isActiveCompositorOutput(); } void initExecution(); void deinitExecution(); const CompositorPriority getRenderPriority() const { return COM_PRIORITY_MEDIUM; } void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); void setIgnoreAlpha(bool value) { this->m_ignoreAlpha = value; } + void setActive(bool active) { this->m_active = active; } }; #endif + diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index 3e035331838..c74c160080c 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -90,6 +90,11 @@ /* ***************** composite job manager ********************** */ +enum { + COM_RECALC_COMPOSITE = 1, + COM_RECALC_VIEWER = 2 +}; + typedef struct CompoJob { Scene *scene; bNodeTree *ntree; @@ -98,8 +103,55 @@ typedef struct CompoJob { short *do_update; float *progress; short need_sync; + int recalc_flags; } CompoJob; +static void compo_tag_output_nodes(bNodeTree *nodetree, int recalc_flags) +{ + bNode *node; + + for (node = nodetree->nodes.first; node; node = node->next) { + if (node->type == CMP_NODE_COMPOSITE) { + if (recalc_flags & COM_RECALC_COMPOSITE) + node->flag |= NODE_DO_OUTPUT_RECALC; + } + else if (node->type == CMP_NODE_VIEWER) { + if (recalc_flags & COM_RECALC_VIEWER) + node->flag |= NODE_DO_OUTPUT_RECALC; + } + else if (node->type == NODE_GROUP) { + if (node->id) + compo_tag_output_nodes((bNodeTree *)node->id, recalc_flags); + } + } +} + +static int compo_get_recalc_flags(const bContext *C) +{ + bScreen *sc = CTX_wm_screen(C); + ScrArea *sa; + int recalc_flags = 0; + + for (sa = sc->areabase.first; sa; sa = sa->next) { + if (sa->spacetype == SPACE_IMAGE) { + SpaceImage *sima = sa->spacedata.first; + if (sima->image) { + if (sima->image->type == IMA_TYPE_R_RESULT) + recalc_flags |= COM_RECALC_COMPOSITE; + else if (sima->image->type == IMA_TYPE_COMPOSITE) + recalc_flags |= COM_RECALC_VIEWER; + } + } + else if (sa->spacetype == SPACE_NODE) { + SpaceNode *snode = sa->spacedata.first; + if (snode->flag & SNODE_BACKDRAW) + recalc_flags |= COM_RECALC_VIEWER; + } + } + + return recalc_flags; +} + /* called by compo, only to check job 'stop' value */ static int compo_breakjob(void *cjv) { @@ -148,6 +200,9 @@ static void compo_initjob(void *cjv) CompoJob *cj = cjv; cj->localtree = ntreeLocalize(cj->ntree); + + if (cj->recalc_flags) + compo_tag_output_nodes(cj->localtree, cj->recalc_flags); } /* called before redraw notifiers, it moves finished previews over */ @@ -234,6 +289,7 @@ void ED_node_composite_job(const bContext *C, struct bNodeTree *nodetree, Scene /* customdata for preview thread */ cj->scene = CTX_data_scene(C); cj->ntree = nodetree; + cj->recalc_flags = compo_get_recalc_flags(C); /* setup job */ WM_jobs_customdata_set(wm_job, cj, compo_freejob); diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 5ccdd5c6ac2..b6a5c758dc0 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -257,6 +257,11 @@ typedef struct bNode { */ #define NODE_INIT (1<<16) + /* do recalc of output, used to skip recalculation of unwanted + * composite out nodes when editing tree + */ +#define NODE_DO_OUTPUT_RECALC (1<<17) + /* node->update */ /* XXX NODE_UPDATE is a generic update flag. More fine-grained updates * might be used in the future, but currently all work the same way. |