[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56271] trunk/blender/source/blender: Fix for #34739 and #35060, avoid ambiguity in compositor viewer nodes.

Lukas Toenne lukas.toenne at googlemail.com
Wed Apr 24 18:36:50 CEST 2013


Revision: 56271
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56271
Author:   lukastoenne
Date:     2013-04-24 16:36:50 +0000 (Wed, 24 Apr 2013)
Log Message:
-----------
Fix for #34739 and #35060, avoid ambiguity in compositor viewer nodes.

The design changes coming with pynodes for the node editor allow editing multiple node groups or pinning. This is great for working on different node groups without switching between them all the time, but it causes a problem for viewer nodes: these nodes all write to the same Image data by design, causing access conflicts and in some cases memory corruption. This was not a problem before pynodes because the editor would only allow 1 edited node group at any time. With the new flexibility of node editors this restriction is gone.

In order to avoid concurrent write access to the viewer image buffer and resolve the ambiguity this patch adds an "active viewer key" to the scene->nodetree (added in bNodeTree instead of Scene due to otherwise circular DNA includes). This key identifies a specific node tree/group instance, which enables the compositor to selectively enable only 1 viewer node.

The active viewer key is switched when opening/closing node groups (push/pop on the snode->treepath stack) or when selecting a viewer node. This way only the "last edited" viewer will be active.

Eventually it would be nicer if each viewer had its own buffer per node space so one could actually compare viewers without switching. But that is a major redesign of viewer nodes and images, not a quick fix for bcon4 ...

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_node.h
    trunk/blender/source/blender/blenkernel/intern/node.c
    trunk/blender/source/blender/compositor/intern/COM_CompositorContext.h
    trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp
    trunk/blender/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp
    trunk/blender/source/blender/compositor/intern/COM_compositor.cpp
    trunk/blender/source/blender/editors/include/ED_node.h
    trunk/blender/source/blender/editors/space_node/drawnode.c
    trunk/blender/source/blender/editors/space_node/node_draw.c
    trunk/blender/source/blender/editors/space_node/node_edit.c
    trunk/blender/source/blender/editors/space_node/node_intern.h
    trunk/blender/source/blender/editors/space_node/node_select.c
    trunk/blender/source/blender/editors/space_node/space_node.c
    trunk/blender/source/blender/makesdna/DNA_node_types.h
    trunk/blender/source/blender/render/intern/source/pipeline.c

Modified: trunk/blender/source/blender/blenkernel/BKE_node.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_node.h	2013-04-24 15:39:19 UTC (rev 56270)
+++ trunk/blender/source/blender/blenkernel/BKE_node.h	2013-04-24 16:36:50 UTC (rev 56271)
@@ -507,6 +507,7 @@
 typedef void (*bNodeInstanceValueFP)(void *value);
 
 extern const bNodeInstanceKey NODE_INSTANCE_KEY_BASE;
+extern const bNodeInstanceKey NODE_INSTANCE_KEY_NONE;
 
 bNodeInstanceKey       BKE_node_instance_key(bNodeInstanceKey parent_key, struct bNodeTree *ntree, struct bNode *node);
 

Modified: trunk/blender/source/blender/blenkernel/intern/node.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/node.c	2013-04-24 15:39:19 UTC (rev 56270)
+++ trunk/blender/source/blender/blenkernel/intern/node.c	2013-04-24 16:36:50 UTC (rev 56271)
@@ -2562,6 +2562,7 @@
 
 /* magic number for initial hash key */
 const bNodeInstanceKey NODE_INSTANCE_KEY_BASE = {5381};
+const bNodeInstanceKey NODE_INSTANCE_KEY_NONE = {0};
 
 /* Generate a hash key from ntree and node names
  * Uses the djb2 algorithm with xor by Bernstein:

Modified: trunk/blender/source/blender/compositor/intern/COM_CompositorContext.h
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_CompositorContext.h	2013-04-24 15:39:19 UTC (rev 56270)
+++ trunk/blender/source/blender/compositor/intern/COM_CompositorContext.h	2013-04-24 16:36:50 UTC (rev 56271)
@@ -84,6 +84,7 @@
 	/* @brief color management settings */
 	const ColorManagedViewSettings *m_viewSettings;
 	const ColorManagedDisplaySettings *m_displaySettings;
+
 public:
 	/**
 	 * @brief constructor initializes the context with default values.

Modified: trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp	2013-04-24 15:39:19 UTC (rev 56270)
+++ trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp	2013-04-24 16:36:50 UTC (rev 56271)
@@ -53,16 +53,6 @@
 	this->m_context.setbNodeTree(editingtree);
 	this->m_context.setPreviewHash(editingtree->previews);
 	this->m_context.setFastCalculation(fastcalculation);
-#if 0	/* XXX TODO find a better way to define visible output nodes from all editors */
-	bNode *gnode;
-	for (gnode = (bNode *)editingtree->nodes.first; gnode; gnode = gnode->next) {
-		if (gnode->type == NODE_GROUP && gnode->typeinfo->group_edit_get(gnode)) {
-			this->m_context.setActivegNode(gnode);
-			break;
-		}
-	}
-#endif
-
 	/* initialize the CompositorContext */
 	if (rendering) {
 		this->m_context.setQuality((CompositorQuality)editingtree->render_quality);

Modified: trunk/blender/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp	2013-04-24 15:39:19 UTC (rev 56270)
+++ trunk/blender/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp	2013-04-24 16:36:50 UTC (rev 56271)
@@ -47,12 +47,12 @@
 	vector<Node *>& nodes = system.getNodes();
 	vector<SocketConnection *>& links = system.getConnections();
 	
+	bool is_active_group = (parent_key.value == system.getContext().getbNodeTree()->active_viewer_key.value);
+	
 	/* add all nodes of the tree to the node list */
 	bNode *node = (bNode *)tree->nodes.first;
 	while (node != NULL) {
-		/* XXX TODO replace isActiveGroup by a more accurate check, all visible editors should do this! */
-		bool isActiveGroup = true;
-		Node *nnode = addNode(nodes, node, isActiveGroup, system.getContext().isFastCalculation());
+		Node *nnode = addNode(nodes, node, is_active_group, system.getContext().isFastCalculation());
 		if (nnode) {
 			nnode->setbNodeTree(tree);
 			nnode->setInstanceKey(BKE_node_instance_key(parent_key, tree, node));

Modified: trunk/blender/source/blender/compositor/intern/COM_compositor.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_compositor.cpp	2013-04-24 15:39:19 UTC (rev 56270)
+++ trunk/blender/source/blender/compositor/intern/COM_compositor.cpp	2013-04-24 16:36:50 UTC (rev 56271)
@@ -92,7 +92,8 @@
 		}
 	}
 
-	ExecutionSystem *system = new ExecutionSystem(rd, editingtree, rendering, false, viewSettings, displaySettings);
+	ExecutionSystem *system = new ExecutionSystem(rd, editingtree, rendering, false,
+	                                              viewSettings, displaySettings);
 	system->execute();
 	delete system;
 

Modified: trunk/blender/source/blender/editors/include/ED_node.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_node.h	2013-04-24 15:39:19 UTC (rev 56270)
+++ trunk/blender/source/blender/editors/include/ED_node.h	2013-04-24 16:36:50 UTC (rev 56271)
@@ -65,6 +65,8 @@
 int ED_node_tree_depth(struct SpaceNode *snode);
 struct bNodeTree *ED_node_tree_get(struct SpaceNode *snode, int level);
 
+void ED_node_set_active_viewer_key(struct SpaceNode *snode);
+
 /* drawnode.c */
 void ED_node_init_butfuncs(void);
 void ED_init_custom_node_type(struct bNodeType *ntype);

Modified: trunk/blender/source/blender/editors/space_node/drawnode.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/drawnode.c	2013-04-24 15:39:19 UTC (rev 56270)
+++ trunk/blender/source/blender/editors/space_node/drawnode.c	2013-04-24 16:36:50 UTC (rev 56271)
@@ -2835,135 +2835,143 @@
 
 /* ************** Generic drawing ************** */
 
-void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode)
+void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeInstanceKey parent_key)
 {
-	if ((snode->flag & SNODE_BACKDRAW) && ED_node_is_compositor(snode)) {
-		Image *ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
-		void *lock;
-		ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
-		if (ibuf) {
-			float x, y; 
+	bNodeInstanceKey active_viewer_key = (snode->nodetree ? snode->nodetree->active_viewer_key : NODE_INSTANCE_KEY_NONE);
+	Image *ima;
+	void *lock;
+	ImBuf *ibuf;
+	
+	if (!(snode->flag & SNODE_BACKDRAW) || !ED_node_is_compositor(snode))
+		return;
+	
+	if (parent_key.value != active_viewer_key.value)
+		return;
+	
+	ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
+	ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
+	if (ibuf) {
+		float x, y; 
+		
+		glMatrixMode(GL_PROJECTION);
+		glPushMatrix();
+		glMatrixMode(GL_MODELVIEW);
+		glPushMatrix();
+		
+		/* keep this, saves us from a version patch */
+		if (snode->zoom == 0.0f) snode->zoom = 1.0f;
+		
+		/* somehow the offset has to be calculated inverse */
+		
+		glaDefine2DArea(&ar->winrct);
+		/* ortho at pixel level curarea */
+		wmOrtho2(-GLA_PIXEL_OFS, ar->winx - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, ar->winy - GLA_PIXEL_OFS);
+		
+		x = (ar->winx - snode->zoom * ibuf->x) / 2 + snode->xof;
+		y = (ar->winy - snode->zoom * ibuf->y) / 2 + snode->yof;
+		
+		if (ibuf->rect || ibuf->rect_float) {
+			unsigned char *display_buffer = NULL;
+			void *cache_handle = NULL;
 			
-			glMatrixMode(GL_PROJECTION);
-			glPushMatrix();
-			glMatrixMode(GL_MODELVIEW);
-			glPushMatrix();
-
-			/* keep this, saves us from a version patch */
-			if (snode->zoom == 0.0f) snode->zoom = 1.0f;
-			
-			/* somehow the offset has to be calculated inverse */
-			
-			glaDefine2DArea(&ar->winrct);
-			/* ortho at pixel level curarea */
-			wmOrtho2(-GLA_PIXEL_OFS, ar->winx - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, ar->winy - GLA_PIXEL_OFS);
-			
-			x = (ar->winx - snode->zoom * ibuf->x) / 2 + snode->xof;
-			y = (ar->winy - snode->zoom * ibuf->y) / 2 + snode->yof;
-
-			if (ibuf->rect || ibuf->rect_float) {
-				unsigned char *display_buffer = NULL;
-				void *cache_handle = NULL;
-
-				if (snode->flag & (SNODE_SHOW_R | SNODE_SHOW_G | SNODE_SHOW_B)) {
-					int ofs;
-
-					display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
-
+			if (snode->flag & (SNODE_SHOW_R | SNODE_SHOW_G | SNODE_SHOW_B)) {
+				int ofs;
+				
+				display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
+				
 #ifdef __BIG_ENDIAN__
-					if      (snode->flag & SNODE_SHOW_R) ofs = 2;
-					else if (snode->flag & SNODE_SHOW_G) ofs = 1;
-					else                                 ofs = 0;
+				if      (snode->flag & SNODE_SHOW_R) ofs = 2;
+				else if (snode->flag & SNODE_SHOW_G) ofs = 1;
+				else                                 ofs = 0;
 #else
-					if      (snode->flag & SNODE_SHOW_R) ofs = 1;
-					else if (snode->flag & SNODE_SHOW_G) ofs = 2;
-					else                                 ofs = 3;
+				if      (snode->flag & SNODE_SHOW_R) ofs = 1;
+				else if (snode->flag & SNODE_SHOW_G) ofs = 2;
+				else                                 ofs = 3;
 #endif
-
-					glPixelZoom(snode->zoom, snode->zoom);
-					/* swap bytes, so alpha is most significant one, then just draw it as luminance int */
-
-					glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT,
-					                  display_buffer + ofs);
-
-					glPixelZoom(1.0f, 1.0f);
-				}
-				else if (snode->flag & SNODE_SHOW_ALPHA) {
-					display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
-
-					glPixelZoom(snode->zoom, snode->zoom);
-					/* swap bytes, so alpha is most significant one, then just draw it as luminance int */
+				
+				glPixelZoom(snode->zoom, snode->zoom);
+				/* swap bytes, so alpha is most significant one, then just draw it as luminance int */
+				
+				glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT,
+				                  display_buffer + ofs);
+				
+				glPixelZoom(1.0f, 1.0f);
+			}
+			else if (snode->flag & SNODE_SHOW_ALPHA) {
+				display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
+				
+				glPixelZoom(snode->zoom, snode->zoom);
+				/* swap bytes, so alpha is most significant one, then just draw it as luminance int */
 #ifdef __BIG_ENDIAN__
-					glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
+				glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
 #endif

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list