Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Toenne <lukas.toenne@googlemail.com>2013-04-24 20:36:50 +0400
committerLukas Toenne <lukas.toenne@googlemail.com>2013-04-24 20:36:50 +0400
commit6cdc12dc749bc1feeb44cb9f5740404605ae830e (patch)
tree2c53b06998eba1c035dad1bcba0ac0e489377edb /source/blender/editors/space_node
parent48b3dab64a2ccc5a344b46429df4803e7df4f155 (diff)
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 ...
Diffstat (limited to 'source/blender/editors/space_node')
-rw-r--r--source/blender/editors/space_node/drawnode.c236
-rw-r--r--source/blender/editors/space_node/node_draw.c4
-rw-r--r--source/blender/editors/space_node/node_edit.c3
-rw-r--r--source/blender/editors/space_node/node_intern.h2
-rw-r--r--source/blender/editors/space_node/node_select.c5
-rw-r--r--source/blender/editors/space_node/space_node.c14
6 files changed, 145 insertions, 119 deletions
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index d326bd6eca5..5ab8a248d63 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -2835,135 +2835,143 @@ void ED_init_node_socket_type_virtual(bNodeSocketType *stype)
/* ************** Generic drawing ************** */
-void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode)
-{
- 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;
-
- 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);
+void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeInstanceKey parent_key)
+{
+ 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;
- 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
- glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT, display_buffer);
-
+ glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT, display_buffer);
+
#ifdef __BIG_ENDIAN__
- glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
+ glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
#endif
- glPixelZoom(1.0f, 1.0f);
- }
- else if (snode->flag & SNODE_USE_ALPHA) {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glPixelZoom(snode->zoom, snode->zoom);
-
- glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST);
-
- glPixelZoom(1.0f, 1.0f);
- glDisable(GL_BLEND);
- }
- else {
- glPixelZoom(snode->zoom, snode->zoom);
-
- glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST);
-
- glPixelZoom(1.0f, 1.0f);
- }
-
- if (cache_handle)
- IMB_display_buffer_release(cache_handle);
+ glPixelZoom(1.0f, 1.0f);
}
-
- /** @note draw selected info on backdrop */
- if (snode->edittree) {
- bNode *node = snode->edittree->nodes.first;
- rctf *viewer_border = &snode->nodetree->viewer_border;
- while (node) {
- if (node->flag & NODE_SELECT) {
- if (node->typeinfo->uibackdropfunc) {
- node->typeinfo->uibackdropfunc(snode, ibuf, node, x, y);
- }
+ else if (snode->flag & SNODE_USE_ALPHA) {
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glPixelZoom(snode->zoom, snode->zoom);
+
+ glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST);
+
+ glPixelZoom(1.0f, 1.0f);
+ glDisable(GL_BLEND);
+ }
+ else {
+ glPixelZoom(snode->zoom, snode->zoom);
+
+ glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST);
+
+ glPixelZoom(1.0f, 1.0f);
+ }
+
+ if (cache_handle)
+ IMB_display_buffer_release(cache_handle);
+ }
+
+ /** @note draw selected info on backdrop */
+ if (snode->edittree) {
+ bNode *node = snode->edittree->nodes.first;
+ rctf *viewer_border = &snode->nodetree->viewer_border;
+ while (node) {
+ if (node->flag & NODE_SELECT) {
+ if (node->typeinfo->uibackdropfunc) {
+ node->typeinfo->uibackdropfunc(snode, ibuf, node, x, y);
}
- node = node->next;
- }
-
- if ((snode->nodetree->flag & NTREE_VIEWER_BORDER) &&
- viewer_border->xmin < viewer_border->xmax &&
- viewer_border->ymin < viewer_border->ymax)
- {
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- setlinestyle(3);
- cpack(0x4040FF);
-
- glRectf(x + snode->zoom * viewer_border->xmin * ibuf->x,
- y + snode->zoom * viewer_border->ymin * ibuf->y,
- x + snode->zoom * viewer_border->xmax * ibuf->x,
- y + snode->zoom * viewer_border->ymax * ibuf->y);
-
- setlinestyle(0);
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
+ node = node->next;
}
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
+ if ((snode->nodetree->flag & NTREE_VIEWER_BORDER) &&
+ viewer_border->xmin < viewer_border->xmax &&
+ viewer_border->ymin < viewer_border->ymax)
+ {
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+ setlinestyle(3);
+ cpack(0x4040FF);
+
+ glRectf(x + snode->zoom * viewer_border->xmin * ibuf->x,
+ y + snode->zoom * viewer_border->ymin * ibuf->y,
+ x + snode->zoom * viewer_border->xmax * ibuf->x,
+ y + snode->zoom * viewer_border->ymax * ibuf->y);
+
+ setlinestyle(0);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ }
}
-
- BKE_image_release_ibuf(ima, ibuf, lock);
+
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
}
+
+ BKE_image_release_ibuf(ima, ibuf, lock);
}
diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c
index 871d3751a4d..992caf5285f 100644
--- a/source/blender/editors/space_node/node_draw.c
+++ b/source/blender/editors/space_node/node_draw.c
@@ -1314,7 +1314,7 @@ void drawnodespace(const bContext *C, ARegion *ar)
UI_view2d_multi_grid_draw(v2d, (depth > 0 ? TH_NODE_GROUP : TH_BACK), U.widget_unit, 5, 2);
/* backdrop */
- draw_nodespace_back_pix(C, ar, snode);
+ draw_nodespace_back_pix(C, ar, snode, path->parent_key);
draw_nodetree(C, ar, ntree, path->parent_key);
}
@@ -1339,7 +1339,7 @@ void drawnodespace(const bContext *C, ARegion *ar)
UI_view2d_multi_grid_draw(v2d, TH_BACK, U.widget_unit, 5, 2);
/* backdrop */
- draw_nodespace_back_pix(C, ar, snode);
+ draw_nodespace_back_pix(C, ar, snode, NODE_INSTANCE_KEY_NONE);
}
ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c
index bf4a41e35c3..80504dda80b 100644
--- a/source/blender/editors/space_node/node_edit.c
+++ b/source/blender/editors/space_node/node_edit.c
@@ -253,7 +253,8 @@ static void compo_startjob(void *cjv, short *stop, short *do_update, float *prog
// XXX BIF_store_spare();
- ntreeCompositExecTree(ntree, &cj->scene->r, 0, 1, &scene->view_settings, &scene->display_settings); /* 1 is do_previews */
+ /* 1 is do_previews */
+ ntreeCompositExecTree(ntree, &cj->scene->r, FALSE, TRUE, &scene->view_settings, &scene->display_settings);
ntree->test_break = NULL;
ntree->stats_draw = NULL;
diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h
index 4b31f22b172..c31bb5ba832 100644
--- a/source/blender/editors/space_node/node_intern.h
+++ b/source/blender/editors/space_node/node_intern.h
@@ -136,7 +136,7 @@ void node_draw_link(struct View2D *v2d, struct SpaceNode *snode, struct bNodeLin
void node_draw_link_bezier(struct View2D *v2d, struct SpaceNode *snode, struct bNodeLink *link, int th_col1, int do_shaded, int th_col2, int do_triple, int th_col3);
int node_link_bezier_points(struct View2D *v2d, struct SpaceNode *snode, struct bNodeLink *link, float coord_array[][2], int resol);
// void node_draw_link_straight(View2D *v2d, SpaceNode *snode, bNodeLink *link, int th_col1, int do_shaded, int th_col2, int do_triple, int th_col3 );
-void draw_nodespace_back_pix(const struct bContext *C, struct ARegion *ar, struct SpaceNode *snode);
+void draw_nodespace_back_pix(const struct bContext *C, struct ARegion *ar, struct SpaceNode *snode, bNodeInstanceKey parent_key);
/* node_add.c */
diff --git a/source/blender/editors/space_node/node_select.c b/source/blender/editors/space_node/node_select.c
index 366fcce3dd5..ea745c47690 100644
--- a/source/blender/editors/space_node/node_select.c
+++ b/source/blender/editors/space_node/node_select.c
@@ -293,6 +293,7 @@ void node_select_single(bContext *C, bNode *node)
nodeSetSelected(node, TRUE);
ED_node_set_active(bmain, snode->edittree, node);
+ ED_node_set_active_viewer_key(snode);
ED_node_sort(snode->edittree);
@@ -374,8 +375,10 @@ static int node_mouse_select(Main *bmain, SpaceNode *snode, ARegion *ar, const i
}
/* update node order */
- if (selected)
+ if (selected) {
+ ED_node_set_active_viewer_key(snode);
ED_node_sort(snode->edittree);
+ }
return selected;
}
diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c
index e234b4255ed..ec5c4657b9c 100644
--- a/source/blender/editors/space_node/space_node.c
+++ b/source/blender/editors/space_node/space_node.c
@@ -90,6 +90,8 @@ void ED_node_tree_start(SpaceNode *snode, bNodeTree *ntree, ID *id, ID *from)
snode->id = id;
snode->from = from;
+ ED_node_set_active_viewer_key(snode);
+
WM_main_add_notifier(NC_SCENE | ND_NODES, NULL);
}
@@ -117,6 +119,8 @@ void ED_node_tree_push(SpaceNode *snode, bNodeTree *ntree, bNode *gnode)
/* update current tree */
snode->edittree = ntree;
+ ED_node_set_active_viewer_key(snode);
+
WM_main_add_notifier(NC_SCENE | ND_NODES, NULL);
}
@@ -135,6 +139,8 @@ void ED_node_tree_pop(SpaceNode *snode)
path = snode->treepath.last;
snode->edittree = path->nodetree;
+ ED_node_set_active_viewer_key(snode);
+
/* listener updates the View2D center from edittree */
WM_main_add_notifier(NC_SCENE | ND_NODES, NULL);
}
@@ -208,6 +214,14 @@ void ED_node_tree_path_get_fixedbuf(SpaceNode *snode, char *value, int max_lengt
}
}
+void ED_node_set_active_viewer_key(SpaceNode *snode)
+{
+ bNodeTreePath *path = snode->treepath.last;
+ if (snode->nodetree && path) {
+ snode->nodetree->active_viewer_key = path->parent_key;
+ }
+}
+
void snode_group_offset(SpaceNode *snode, float *x, float *y)
{
bNodeTreePath *path = snode->treepath.last;