code cleanup: favor braces when blocks have mixed brace use.
[blender.git] / source / blender / editors / space_sequencer / sequencer_draw.c
index f927e83..7ebe04f 100644 (file)
@@ -62,6 +62,7 @@
 #include "ED_gpencil.h"
 #include "ED_markers.h"
 #include "ED_mask.h"
+#include "ED_sequencer.h"
 #include "ED_types.h"
 #include "ED_space_api.h"
 
@@ -285,8 +286,8 @@ static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1,
                drawmeta_stipple(1);
 
        for (seq = seqm->seqbase.first; seq; seq = seq->next) {
-               chan_min = MIN2(chan_min, seq->machine);
-               chan_max = MAX2(chan_max, seq->machine);
+               chan_min = min_ii(chan_min, seq->machine);
+               chan_max = max_ii(chan_max, seq->machine);
        }
 
        chan_range = (chan_max - chan_min) + 1;
@@ -355,7 +356,7 @@ static void draw_seq_handle(View2D *v2d, Sequence *seq, const float handsize_cla
        y2 = seq->machine + SEQ_STRIP_OFSTOP;
 
        /* set up co-ordinates/dimensions for either left or right handle */
-       if (direction == SEQ_LEFTHANDLE) {      
+       if (direction == SEQ_LEFTHANDLE) {
                rx1 = x1;
                rx2 = x1 + handsize_clamped * 0.75f;
                
@@ -415,7 +416,7 @@ static void draw_seq_handle(View2D *v2d, Sequence *seq, const float handsize_cla
                        y1 = y2 + 0.05f;
                }
                UI_view2d_text_cache_add(v2d, x1, y1, numstr, col);
-       }       
+       }
 }
 
 static void draw_seq_extensions(Scene *scene, ARegion *ar, Sequence *seq)
@@ -747,7 +748,7 @@ static void draw_seq_strip(Scene *scene, ARegion *ar, Sequence *seq, int outline
                glDisable(GL_BLEND);
        }
 
-       if (!BKE_seqence_is_valid_check(seq)) {
+       if (!BKE_sequence_is_valid_check(seq)) {
                glEnable(GL_POLYGON_STIPPLE);
 
                /* panic! */
@@ -810,9 +811,11 @@ static void UNUSED_FUNCTION(set_special_seq_update) (int val)
 
        /* if mouse over a sequence && LEFTMOUSE */
        if (val) {
-// XXX         special_seq_update= find_nearest_seq(&x);
+// XXX         special_seq_update = find_nearest_seq(&x);
+       }
+       else {
+               special_seq_update = NULL;
        }
-       else special_seq_update = NULL;
 }
 
 ImBuf *sequencer_ibuf_get(struct Main *bmain, Scene *scene, SpaceSeq *sseq, int cfra, int frame_ofs)
@@ -822,6 +825,7 @@ ImBuf *sequencer_ibuf_get(struct Main *bmain, Scene *scene, SpaceSeq *sseq, int
        int rectx, recty;
        float render_size = 0.0;
        float proxy_size = 100.0;
+       short is_break = G.is_break;
 
        render_size = sseq->render_size;
        if (render_size == 0) {
@@ -840,6 +844,11 @@ ImBuf *sequencer_ibuf_get(struct Main *bmain, Scene *scene, SpaceSeq *sseq, int
 
        context = BKE_sequencer_new_render_data(bmain, scene, rectx, recty, proxy_size);
 
+       /* sequencer could start rendering, in this case we need to be sure it wouldn't be canceled
+        * by Esc pressed somewhere in the past
+        */
+       G.is_break = FALSE;
+
        if (special_seq_update)
                ibuf = BKE_sequencer_give_ibuf_direct(context, cfra + frame_ofs, special_seq_update);
        else if (!U.prefetchframes) // XXX || (G.f & G_PLAYANIM) == 0) {
@@ -847,6 +856,9 @@ ImBuf *sequencer_ibuf_get(struct Main *bmain, Scene *scene, SpaceSeq *sseq, int
        else
                ibuf = BKE_sequencer_give_ibuf_threaded(context, cfra + frame_ofs, sseq->chanshown);
 
+       /* restore state so real rendering would be canceled (if needed) */
+       G.is_break = is_break;
+
        return ibuf;
 }
 
@@ -885,7 +897,10 @@ static ImBuf *sequencer_make_scope(Scene *scene, ImBuf *ibuf, ImBuf *(*make_scop
        ImBuf *display_ibuf = IMB_dupImBuf(ibuf);
        ImBuf *scope;
 
-       IMB_colormanagement_imbuf_make_display_space(display_ibuf, &scene->view_settings, &scene->display_settings);
+       if (display_ibuf->rect_float) {
+               IMB_colormanagement_imbuf_make_display_space(display_ibuf, &scene->view_settings,
+                                                            &scene->display_settings);
+       }
 
        scope = make_scope_cb(display_ibuf);
 
@@ -909,6 +924,21 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
        GLuint last_texid;
        unsigned char *display_buffer;
        void *cache_handle = NULL;
+       const int is_imbuf = ED_space_sequencer_check_show_imbuf(sseq);
+
+       if (G.is_rendering == FALSE && (scene->r.seq_flag & R_SEQ_GL_PREV) == 0) {
+               /* stop all running jobs, except screen one. currently previews frustrate Render
+                * needed to make so sequencer's rendering doesn't conflict with compositor
+                */
+               WM_jobs_kill_type(CTX_wm_manager(C), WM_JOB_TYPE_COMPOSITE);
+
+               if ((scene->r.seq_flag & R_SEQ_GL_PREV) == 0) {
+                       /* in case of final rendering used for preview, kill all previews,
+                        * otherwise threading conflict will happen in rendering module
+                        */
+                       WM_jobs_kill_type(CTX_wm_manager(C), WM_JOB_TYPE_RENDER_PREVIEW);
+               }
+       }
 
        render_size = sseq->render_size;
        if (render_size == 0) {
@@ -967,7 +997,10 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
                                if (!scopes->zebra_ibuf) {
                                        ImBuf *display_ibuf = IMB_dupImBuf(ibuf);
 
-                                       IMB_colormanagement_imbuf_make_display_space(display_ibuf, &scene->view_settings, &scene->display_settings);
+                                       if (display_ibuf->rect_float) {
+                                               IMB_colormanagement_imbuf_make_display_space(display_ibuf, &scene->view_settings,
+                                                                                            &scene->display_settings);
+                                       }
                                        scopes->zebra_ibuf = make_zebra_view_from_ibuf(display_ibuf, sseq->zebra);
                                        IMB_freeImBuf(display_ibuf);
                                }
@@ -1027,6 +1060,12 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, display_buffer);
+
+       if (sseq->flag & SEQ_USE_ALPHA) {
+               glEnable(GL_BLEND);
+               glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       }
+
        glBegin(GL_QUADS);
 
        if (draw_overlay) {
@@ -1058,6 +1097,8 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
        glEnd();
        glBindTexture(GL_TEXTURE_2D, last_texid);
        glDisable(GL_TEXTURE_2D);
+       if (sseq->flag & SEQ_USE_ALPHA)
+               glDisable(GL_BLEND);
        glDeleteTextures(1, &texid);
 
        if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
@@ -1103,8 +1144,12 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
                setlinestyle(0);
        }
        
-       /* draw grease-pencil (image aligned) */
-       draw_gpencil_2dimage(C);
+       if (sseq->flag & SEQ_SHOW_GPENCIL) {
+               if (is_imbuf) {
+                       /* draw grease-pencil (image aligned) */
+                       draw_gpencil_2dimage(C);
+               }
+       }
 
        if (!scope)
                IMB_freeImBuf(ibuf);
@@ -1112,9 +1157,12 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
        /* ortho at pixel level */
        UI_view2d_view_restore(C);
        
-       /* draw grease-pencil (screen aligned) */
-       draw_gpencil_view2d(C, 0);
-
+       if (sseq->flag & SEQ_SHOW_GPENCIL) {
+               if (is_imbuf) {
+                       /* draw grease-pencil (screen aligned) */
+                       draw_gpencil_view2d(C, 0);
+               }
+       }
 
 
        /* NOTE: sequencer mask editing isnt finished, the draw code is working but editing not,
@@ -1183,7 +1231,7 @@ static void draw_seq_backdrop(View2D *v2d)
        glRectf(v2d->cur.xmin,  -1.0,  v2d->cur.xmax,  1.0);
 
        /* Alternating horizontal stripes */
-       i = maxi(1, ((int)v2d->cur.ymin) - 1);
+       i = max_ii(1, ((int)v2d->cur.ymin) - 1);
 
        glBegin(GL_QUADS);
        while (i < v2d->cur.ymax) {
@@ -1202,7 +1250,7 @@ static void draw_seq_backdrop(View2D *v2d)
        glEnd();
        
        /* Darker lines separating the horizontal bands */
-       i = maxi(1, ((int)v2d->cur.ymin) - 1);
+       i = max_ii(1, ((int)v2d->cur.ymin) - 1);
        UI_ThemeColor(TH_GRID);
        
        glBegin(GL_LINES);
@@ -1234,8 +1282,8 @@ static void draw_seq_strips(const bContext *C, Editing *ed, ARegion *ar)
                        /* boundbox and selection tests for NOT drawing the strip... */
                        if ((seq->flag & SELECT) != sel) continue;
                        else if (seq == last_seq) continue;
-                       else if (MIN2(seq->startdisp, seq->start) > v2d->cur.xmax) continue;
-                       else if (MAX2(seq->enddisp, seq->start + seq->len) < v2d->cur.xmin) continue;
+                       else if (min_ii(seq->startdisp, seq->start) > v2d->cur.xmax) continue;
+                       else if (max_ii(seq->enddisp, seq->start + seq->len) < v2d->cur.xmin) continue;
                        else if (seq->machine + 1.0f < v2d->cur.ymin) continue;
                        else if (seq->machine > v2d->cur.ymax) continue;