bugfix [#23068] Image editor: Update Automatically not updating the compositor.
authorCampbell Barton <ideasman42@gmail.com>
Mon, 13 Sep 2010 06:08:26 +0000 (06:08 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 13 Sep 2010 06:08:26 +0000 (06:08 +0000)
       [#23637] Replacing an image used in the compositor crashes
       [#23343] changes in images doesn't update compositor image nodes

source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/image.c
source/blender/blenkernel/intern/node.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/space_node/node_edit.c
source/blender/editors/space_node/space_node.c

index 4bd4cc3..7b4925b 100644 (file)
@@ -192,7 +192,7 @@ int                         nodeSetActiveID(struct bNodeTree *ntree, short idtype, struct ID *id);
 void                   nodeClearActiveID(struct bNodeTree *ntree, short idtype);
 
 void                   NodeTagChanged(struct bNodeTree *ntree, struct bNode *node);
-void                   NodeTagIDChanged(struct bNodeTree *ntree, struct ID *id);
+int                            NodeTagIDChanged(struct bNodeTree *ntree, struct ID *id);
 
 /* ************** Groups ****************** */
 
index 0e282aa..e77183d 100644 (file)
@@ -69,6 +69,7 @@
 #include "BKE_main.h"
 #include "BKE_packedFile.h"
 #include "BKE_scene.h"
+#include "BKE_node.h"
 
 //XXX #include "BIF_editseq.h"
 
@@ -1447,6 +1448,17 @@ void BKE_image_signal(Image *ima, ImageUser *iuser, int signal)
                }
                break;
        }
+       
+       /* dont use notifiers because they are not 100% sure to succseed
+        * this also makes sure all scenes are accounted for. */
+       {
+               Scene *scene;
+               for(scene= G.main->scene.first; scene; scene= scene->id.next) {
+                       if(scene->nodetree) {
+                               NodeTagIDChanged(scene->nodetree, &ima->id);
+                       }
+               }
+       }
 }
 
 /* if layer or pass changes, we need an index for the imbufs list */
index 5af2c64..135ddba 100644 (file)
@@ -1787,18 +1787,25 @@ void NodeTagChanged(bNodeTree *ntree, bNode *node)
        }
 }
 
-void NodeTagIDChanged(bNodeTree *ntree, ID *id)
+int NodeTagIDChanged(bNodeTree *ntree, ID *id)
 {
+       int change = FALSE;
+
        if(id==NULL)
-               return;
+               return change;
        
        if(ntree->type==NTREE_COMPOSIT) {
                bNode *node;
                
-               for(node= ntree->nodes.first; node; node= node->next)
-                       if(node->id==id)
+               for(node= ntree->nodes.first; node; node= node->next) {
+                       if(node->id==id) {
+                               change= TRUE;
                                NodeTagChanged(ntree, node);
+                       }
+               }
        }
+       
+       return change;
 }
 
 
index 418bac6..4760796 100644 (file)
@@ -4534,29 +4534,8 @@ static void paint_redraw(bContext *C, ImagePaintState *s, int final)
                if(s->image)
                        GPU_free_image(s->image);
 
+               /* compositor listener deals with updating */
                WM_event_add_notifier(C, NC_IMAGE|NA_EDITED, s->image);
-
-               // XXX node update
-#if 0
-               if(!s->sima && s->image) {
-                       /* after paint, tag Image or RenderResult nodes changed */
-                       if(s->scene->nodetree) {
-                               imagepaint_composite_tags(s->scene->nodetree, image, &s->sima->iuser);
-                       }
-                       /* signal composite (hurmf, need an allqueue?) */
-                       if(s->sima->lock) {
-                               ScrArea *sa;
-                               for(sa=s->screen->areabase.first; sa; sa= sa->next) {
-                                       if(sa->spacetype==SPACE_NODE) {
-                                               if(((SpaceNode *)sa->spacedata.first)->treetype==NTREE_COMPOSIT) {
-                                                       addqueue(sa->win, UI_BUT_EVENT, B_NODE_TREE_EXEC);
-                                                       break;
-                                               }
-                                       }
-                               }
-                       }
-               }               
-#endif
        }
        else {
                if(!s->sima || !s->sima->lock)
index 829c74f..5aa512e 100644 (file)
@@ -1919,33 +1919,6 @@ void NODE_OT_read_fullsamplelayers(wmOperatorType *ot)
 }
 
 
-/* ************************* */
-
-void imagepaint_composite_tags(bNodeTree *ntree, Image *image, ImageUser *iuser)
-{
-       bNode *node;
-       
-       if(ntree==NULL)
-               return;
-       
-       /* search for renderresults */
-       if(image->type==IMA_TYPE_R_RESULT) {
-               for(node= ntree->nodes.first; node; node= node->next) {
-                       if(node->type==CMP_NODE_R_LAYERS && node->id==NULL) {
-                               /* imageuser comes from ImageWin, so indexes are offset 1 */
-                               if(node->custom1==iuser->layer-1)
-                                       NodeTagChanged(ntree, node);
-                       }
-               }
-       }
-       else {
-               for(node= ntree->nodes.first; node; node= node->next) {
-                       if(node->id== &image->id)
-                               NodeTagChanged(ntree, node);
-               }
-       }
-}
-
 /* ****************** Make Group operator ******************* */
 
 static int node_group_make_exec(bContext *C, wmOperator *op)
index d9a4dda..c94fcb5 100644 (file)
@@ -42,6 +42,7 @@
 
 #include "BKE_context.h"
 #include "BKE_screen.h"
+#include "BKE_node.h"
 
 #include "ED_render.h"
 #include "ED_screen.h"
@@ -158,7 +159,10 @@ static void node_init(struct wmWindowManager *wm, ScrArea *sa)
 
 static void node_area_listener(ScrArea *sa, wmNotifier *wmn)
 {
-       
+       /* note, ED_area_tag_refresh will re-execute compositor */
+       /* XXX, should edit some to check for the nodeTree type, especially  NC_NODE|NA_EDITED which refreshes all types */
+       SpaceNode *snode= sa->spacedata.first;
+
        /* preview renders */
        switch(wmn->category) {
                case NC_SCENE:
@@ -200,6 +204,20 @@ static void node_area_listener(ScrArea *sa, wmNotifier *wmn)
                        if (wmn->action == NA_EDITED)
                                ED_area_tag_refresh(sa);
                        break;
+
+               case NC_IMAGE:
+                       if (wmn->action == NA_EDITED) {
+                               if(snode->treetype==NTREE_COMPOSIT) {
+                                       Scene *scene= wmn->window->screen->scene;
+                                       
+                                       /* note that NodeTagIDChanged is alredy called by BKE_image_signal() on all
+                                        * scenes so really this is just to know if the images is used in the compo else
+                                        * painting on images could become very slow when the compositor is open. */
+                                       if(NodeTagIDChanged(scene->nodetree, wmn->reference))
+                                               ED_area_tag_refresh(sa);
+                               }
+                       }
+                       break;
        }
 }