Sequencer: Add option to render OpenGL preview with DoF
[blender-staging.git] / source / blender / editors / space_sequencer / sequencer_draw.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * Contributor(s): Blender Foundation, 2003-2009
22  *
23  * ***** END GPL LICENSE BLOCK *****
24  */
25
26 /** \file blender/editors/space_sequencer/sequencer_draw.c
27  *  \ingroup spseq
28  */
29
30
31 #include <string.h>
32 #include <math.h>
33
34 #include "BLI_blenlib.h"
35 #include "BLI_math.h"
36 #include "BLI_utildefines.h"
37 #include "BLI_threads.h"
38
39 #include "IMB_imbuf_types.h"
40
41 #include "DNA_scene_types.h"
42 #include "DNA_mask_types.h"
43 #include "DNA_object_types.h"
44 #include "DNA_screen_types.h"
45 #include "DNA_space_types.h"
46 #include "DNA_userdef_types.h"
47 #include "DNA_sound_types.h"
48
49 #include "BKE_context.h"
50 #include "BKE_global.h"
51 #include "BKE_main.h"
52 #include "BKE_sequencer.h"
53 #include "BKE_sound.h"
54 #include "BKE_scene.h"
55
56 #include "IMB_colormanagement.h"
57 #include "IMB_imbuf.h"
58
59 #include "BIF_gl.h"
60 #include "BIF_glutil.h"
61
62 #include "GPU_basic_shader.h"
63 #include "GPU_compositing.h"
64
65 #include "ED_anim_api.h"
66 #include "ED_gpencil.h"
67 #include "ED_markers.h"
68 #include "ED_mask.h"
69 #include "ED_sequencer.h"
70 #include "ED_screen.h"
71 #include "ED_space_api.h"
72
73 #include "UI_interface.h"
74 #include "UI_resources.h"
75 #include "UI_view2d.h"
76
77 #include "WM_api.h"
78
79 #include "MEM_guardedalloc.h"
80
81 /* own include */
82 #include "sequencer_intern.h"
83
84
85 #define SEQ_LEFTHANDLE   1
86 #define SEQ_RIGHTHANDLE  2
87
88 #define SEQ_HANDLE_SIZE_MIN  7.0f
89 #define SEQ_HANDLE_SIZE_MAX 40.0f
90
91
92 /* Note, Don't use SEQ_BEGIN/SEQ_END while drawing!
93  * it messes up transform, - Campbell */
94 #undef SEQ_BEGIN
95 #undef SEQP_BEGIN
96 #undef SEQ_END
97
98 static Sequence *special_seq_update = NULL;
99
100 void color3ubv_from_seq(Scene *curscene, Sequence *seq, unsigned char col[3])
101 {
102         unsigned char blendcol[3];
103         SolidColorVars *colvars = (SolidColorVars *)seq->effectdata;
104
105         switch (seq->type) {
106                 case SEQ_TYPE_IMAGE:
107                         UI_GetThemeColor3ubv(TH_SEQ_IMAGE, col);
108                         break;
109
110                 case SEQ_TYPE_META:
111                         UI_GetThemeColor3ubv(TH_SEQ_META, col);
112                         break;
113
114                 case SEQ_TYPE_MOVIE:
115                         UI_GetThemeColor3ubv(TH_SEQ_MOVIE, col);
116                         break;
117
118                 case SEQ_TYPE_MOVIECLIP:
119                         UI_GetThemeColor3ubv(TH_SEQ_MOVIECLIP, col);
120                         break;
121
122                 case SEQ_TYPE_MASK:
123                         UI_GetThemeColor3ubv(TH_SEQ_MASK, col); /* TODO */
124                         break;
125
126                 case SEQ_TYPE_SCENE:
127                         UI_GetThemeColor3ubv(TH_SEQ_SCENE, col);
128                 
129                         if (seq->scene == curscene) {
130                                 UI_GetColorPtrShade3ubv(col, col, 20);
131                         }
132                         break;
133                 
134                 /* transitions */
135                 case SEQ_TYPE_CROSS:
136                 case SEQ_TYPE_GAMCROSS:
137                 case SEQ_TYPE_WIPE:
138                         UI_GetThemeColor3ubv(TH_SEQ_TRANSITION, col);
139
140                         /* slightly offset hue to distinguish different effects */
141                         if (seq->type == SEQ_TYPE_CROSS)    rgb_byte_set_hue_float_offset(col, 0.04);
142                         if (seq->type == SEQ_TYPE_GAMCROSS) rgb_byte_set_hue_float_offset(col, 0.08);
143                         if (seq->type == SEQ_TYPE_WIPE)     rgb_byte_set_hue_float_offset(col, 0.12);
144                         break;
145
146                 /* effects */
147                 case SEQ_TYPE_TRANSFORM:
148                 case SEQ_TYPE_SPEED:
149                 case SEQ_TYPE_ADD:
150                 case SEQ_TYPE_SUB:
151                 case SEQ_TYPE_MUL:
152                 case SEQ_TYPE_ALPHAOVER:
153                 case SEQ_TYPE_ALPHAUNDER:
154                 case SEQ_TYPE_OVERDROP:
155                 case SEQ_TYPE_GLOW:
156                 case SEQ_TYPE_MULTICAM:
157                 case SEQ_TYPE_ADJUSTMENT:
158                 case SEQ_TYPE_GAUSSIAN_BLUR:
159                         UI_GetThemeColor3ubv(TH_SEQ_EFFECT, col);
160
161                         /* slightly offset hue to distinguish different effects */
162                         if      (seq->type == SEQ_TYPE_ADD)           rgb_byte_set_hue_float_offset(col, 0.04);
163                         else if (seq->type == SEQ_TYPE_SUB)           rgb_byte_set_hue_float_offset(col, 0.08);
164                         else if (seq->type == SEQ_TYPE_MUL)           rgb_byte_set_hue_float_offset(col, 0.12);
165                         else if (seq->type == SEQ_TYPE_ALPHAOVER)     rgb_byte_set_hue_float_offset(col, 0.16);
166                         else if (seq->type == SEQ_TYPE_ALPHAUNDER)    rgb_byte_set_hue_float_offset(col, 0.20);
167                         else if (seq->type == SEQ_TYPE_OVERDROP)      rgb_byte_set_hue_float_offset(col, 0.24);
168                         else if (seq->type == SEQ_TYPE_GLOW)          rgb_byte_set_hue_float_offset(col, 0.28);
169                         else if (seq->type == SEQ_TYPE_TRANSFORM)     rgb_byte_set_hue_float_offset(col, 0.36);
170                         else if (seq->type == SEQ_TYPE_MULTICAM)      rgb_byte_set_hue_float_offset(col, 0.32);
171                         else if (seq->type == SEQ_TYPE_ADJUSTMENT)    rgb_byte_set_hue_float_offset(col, 0.40);
172                         else if (seq->type == SEQ_TYPE_GAUSSIAN_BLUR) rgb_byte_set_hue_float_offset(col, 0.42);
173                         break;
174
175                 case SEQ_TYPE_COLOR:
176                         rgb_float_to_uchar(col, colvars->col);
177                         break;
178
179                 case SEQ_TYPE_SOUND_RAM:
180                         UI_GetThemeColor3ubv(TH_SEQ_AUDIO, col);
181                         blendcol[0] = blendcol[1] = blendcol[2] = 128;
182                         if (seq->flag & SEQ_MUTE) UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.5, 20);
183                         break;
184
185                 case SEQ_TYPE_TEXT:
186                         UI_GetThemeColor3ubv(TH_SEQ_TEXT, col);
187                         break;
188
189                 default:
190                         col[0] = 10; col[1] = 255; col[2] = 40;
191                         break;
192         }
193 }
194
195 static void drawseqwave(const bContext *C, SpaceSeq *sseq, Scene *scene, Sequence *seq, float x1, float y1, float x2, float y2, float stepsize)
196 {
197         /*
198          * x1 is the starting x value to draw the wave,
199          * x2 the end x value, same for y1 and y2
200          * stepsize is width of a pixel.
201          */
202         if (seq->sound && ((sseq->flag & SEQ_ALL_WAVEFORMS) || (seq->flag & SEQ_AUDIO_DRAW_WAVEFORM))) {
203                 int i, j, pos;
204                 int length = floor((x2 - x1) / stepsize) + 1;
205                 float ymid = (y1 + y2) / 2;
206                 float yscale = (y2 - y1) / 2;
207                 float samplestep;
208                 float startsample, endsample;
209                 float value1, value2;
210                 bSound *sound = seq->sound;
211                 
212                 SoundWaveform *waveform;
213                 
214                 if (!sound->spinlock) {
215                         sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock");
216                         BLI_spin_init(sound->spinlock);
217                 }
218                 
219                 BLI_spin_lock(sound->spinlock);
220                 if (!sound->waveform) {
221                         if (!(sound->flags & SOUND_FLAGS_WAVEFORM_LOADING)) {
222                                 /* prevent sounds from reloading */
223                                 sound->flags |= SOUND_FLAGS_WAVEFORM_LOADING;
224                                 BLI_spin_unlock(sound->spinlock);
225                                 sequencer_preview_add_sound(C, seq);
226                         }
227                         else {
228                                 BLI_spin_unlock(sound->spinlock);
229                         }
230                         return;  /* nothing to draw */
231                 }
232                 BLI_spin_unlock(sound->spinlock);
233                 
234                 waveform = sound->waveform;
235
236                 if (waveform->length == 0) {
237                         /* BKE_sound_read_waveform() set an empty SoundWaveform data in case it cannot generate a valid one...
238                          * See T45726. */
239                         return;
240                 }
241
242                 startsample = floor((seq->startofs + seq->anim_startofs) / FPS * SOUND_WAVE_SAMPLES_PER_SECOND);
243                 endsample = ceil((seq->startofs + seq->anim_startofs + seq->enddisp - seq->startdisp) / FPS * SOUND_WAVE_SAMPLES_PER_SECOND);
244                 samplestep = (endsample - startsample) * stepsize / (x2 - x1);
245
246                 if (length > floor((waveform->length - startsample) / samplestep))
247                         length = floor((waveform->length - startsample) / samplestep);
248
249                 glColor4f(1.0f, 1.0f, 1.0f, 0.5);
250                 glEnable(GL_BLEND);
251                 glBegin(GL_TRIANGLE_STRIP);
252                 for (i = 0; i < length; i++) {
253                         float sampleoffset = startsample + i * samplestep;
254                         pos = sampleoffset;
255
256                         value1 = waveform->data[pos * 3];
257                         value2 = waveform->data[pos * 3 + 1];
258
259                         if (samplestep > 1.0f) {
260                                 for (j = pos + 1; (j < waveform->length) && (j < pos + samplestep); j++) {
261                                         if (value1 > waveform->data[j * 3])
262                                                 value1 = waveform->data[j * 3];
263
264                                         if (value2 < waveform->data[j * 3 + 1])
265                                                 value2 = waveform->data[j * 3 + 1];
266                                 }
267                         }
268                         else {
269                                 /* use simple linear interpolation */
270                                 float f = sampleoffset - pos;
271                                 value1 = (1.0f - f) * value1 + f * waveform->data[pos * 3 + 3];
272                                 value2 = (1.0f - f) * value2 + f * waveform->data[pos * 3 + 4];
273                         }
274
275                         glVertex2f(x1 + i * stepsize, ymid + value1 * yscale);
276                         glVertex2f(x1 + i * stepsize, ymid + value2 * yscale);
277                 }
278                 glEnd();
279                 glDisable(GL_BLEND);
280         }
281 }
282
283 static void drawmeta_stipple(int value)
284 {
285         if (value) {
286                 GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
287                 GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_HALFTONE);
288                 
289                 glEnable(GL_LINE_STIPPLE);
290                 glLineStipple(1, 0x8888);
291         }
292         else {
293                 GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
294                 glDisable(GL_LINE_STIPPLE);
295         }
296 }
297
298 static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1, float x2, float y2)
299 {
300         /* note: this used to use SEQ_BEGIN/SEQ_END, but it messes up the
301          * seq->depth value, (needed by transform when doing overlap checks)
302          * so for now, just use the meta's immediate children, could be fixed but
303          * its only drawing - campbell */
304         Sequence *seq;
305         unsigned char col[4];
306
307         int chan_min = MAXSEQ;
308         int chan_max = 0;
309         int chan_range = 0;
310         float draw_range = y2 - y1;
311         float draw_height;
312         ListBase *seqbase;
313         int offset;
314
315         seqbase = BKE_sequence_seqbase_get(seqm, &offset);
316         if (!seqbase || BLI_listbase_is_empty(seqbase)) {
317                 return;
318         }
319
320         if (seqm->type == SEQ_TYPE_SCENE) {
321                 offset  = seqm->start - offset;
322         }
323         else {
324                 offset = 0;
325         }
326
327         glEnable(GL_BLEND);
328         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
329
330         if (seqm->flag & SEQ_MUTE)
331                 drawmeta_stipple(1);
332
333         for (seq = seqbase->first; seq; seq = seq->next) {
334                 chan_min = min_ii(chan_min, seq->machine);
335                 chan_max = max_ii(chan_max, seq->machine);
336         }
337
338         chan_range = (chan_max - chan_min) + 1;
339         draw_height = draw_range / chan_range;
340
341         col[3] = 196; /* alpha, used for all meta children */
342
343         for (seq = seqbase->first; seq; seq = seq->next) {
344                 const int startdisp = seq->startdisp + offset;
345                 const int enddisp   = seq->enddisp   + offset;
346
347                 if ((startdisp > x2 || enddisp < x1) == 0) {
348                         float y_chan = (seq->machine - chan_min) / (float)(chan_range) * draw_range;
349                         float x1_chan = startdisp;
350                         float x2_chan = enddisp;
351                         float y1_chan, y2_chan;
352
353                         if ((seqm->flag & SEQ_MUTE) == 0 && (seq->flag & SEQ_MUTE))
354                                 drawmeta_stipple(1);
355
356                         color3ubv_from_seq(scene, seq, col);
357
358                         glColor4ubv(col);
359                         
360                         /* clamp within parent sequence strip bounds */
361                         if (x1_chan < x1) x1_chan = x1;
362                         if (x2_chan > x2) x2_chan = x2;
363
364                         y1_chan = y1 + y_chan + (draw_height * SEQ_STRIP_OFSBOTTOM);
365                         y2_chan = y1 + y_chan + (draw_height * SEQ_STRIP_OFSTOP);
366
367                         glRectf(x1_chan,  y1_chan, x2_chan,  y2_chan);
368
369                         UI_GetColorPtrShade3ubv(col, col, -30);
370                         glColor4ubv(col);
371                         fdrawbox(x1_chan,  y1_chan, x2_chan,  y2_chan);
372
373                         if ((seqm->flag & SEQ_MUTE) == 0 && (seq->flag & SEQ_MUTE))
374                                 drawmeta_stipple(0);
375                 }
376         }
377
378         if (seqm->flag & SEQ_MUTE)
379                 drawmeta_stipple(0);
380         
381         glDisable(GL_BLEND);
382 }
383
384 /* clamp handles to defined size in pixel space */
385 static float draw_seq_handle_size_get_clamped(Sequence *seq, const float pixelx)
386 {
387         const float minhandle = pixelx * SEQ_HANDLE_SIZE_MIN;
388         const float maxhandle = pixelx * SEQ_HANDLE_SIZE_MAX;
389         float size = CLAMPIS(seq->handsize, minhandle, maxhandle);
390
391         /* ensure we're not greater than half width */
392         return min_ff(size, ((float)(seq->enddisp - seq->startdisp) / 2.0f) / pixelx);
393 }
394
395 /* draw a handle, for each end of a sequence strip */
396 static void draw_seq_handle(View2D *v2d, Sequence *seq, const float handsize_clamped, const short direction)
397 {
398         float v1[2], v2[2], v3[2], rx1 = 0, rx2 = 0; //for triangles and rect
399         float x1, x2, y1, y2;
400         unsigned int whichsel = 0;
401         
402         x1 = seq->startdisp;
403         x2 = seq->enddisp;
404         
405         y1 = seq->machine + SEQ_STRIP_OFSBOTTOM;
406         y2 = seq->machine + SEQ_STRIP_OFSTOP;
407
408         /* set up co-ordinates/dimensions for either left or right handle */
409         if (direction == SEQ_LEFTHANDLE) {
410                 rx1 = x1;
411                 rx2 = x1 + handsize_clamped * 0.75f;
412                 
413                 v1[0] = x1 + handsize_clamped / 4; v1[1] = y1 + ( ((y1 + y2) / 2.0f - y1) / 2);
414                 v2[0] = x1 + handsize_clamped / 4; v2[1] = y2 - ( ((y1 + y2) / 2.0f - y1) / 2);
415                 v3[0] = v2[0] + handsize_clamped / 4; v3[1] = (y1 + y2) / 2.0f;
416                 
417                 whichsel = SEQ_LEFTSEL;
418         }
419         else if (direction == SEQ_RIGHTHANDLE) {
420                 rx1 = x2 - handsize_clamped * 0.75f;
421                 rx2 = x2;
422                 
423                 v1[0] = x2 - handsize_clamped / 4; v1[1] = y1 + ( ((y1 + y2) / 2.0f - y1) / 2);
424                 v2[0] = x2 - handsize_clamped / 4; v2[1] = y2 - ( ((y1 + y2) / 2.0f - y1) / 2);
425                 v3[0] = v2[0] - handsize_clamped / 4; v3[1] = (y1 + y2) / 2.0f;
426                 
427                 whichsel = SEQ_RIGHTSEL;
428         }
429         
430         /* draw! */
431         if (!(seq->type & SEQ_TYPE_EFFECT) ||
432             BKE_sequence_effect_get_num_inputs(seq->type) == 0)
433         {
434                 glEnable(GL_BLEND);
435                 
436                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
437                 
438                 if (seq->flag & whichsel) glColor4ub(0, 0, 0, 80);
439                 else if (seq->flag & SELECT) glColor4ub(255, 255, 255, 30);
440                 else glColor4ub(0, 0, 0, 22);
441                 
442                 glRectf(rx1, y1, rx2, y2);
443                 
444                 if (seq->flag & whichsel) glColor4ub(255, 255, 255, 200);
445                 else glColor4ub(0, 0, 0, 50);
446                 
447                 glEnable(GL_POLYGON_SMOOTH);
448                 glBegin(GL_TRIANGLES);
449                 glVertex2fv(v1); glVertex2fv(v2); glVertex2fv(v3);
450                 glEnd();
451                 
452                 glDisable(GL_POLYGON_SMOOTH);
453                 glDisable(GL_BLEND);
454         }
455         
456         if ((G.moving & G_TRANSFORM_SEQ) || (seq->flag & whichsel)) {
457                 const char col[4] = {255, 255, 255, 255};
458                 char numstr[32];
459                 size_t numstr_len;
460
461                 if (direction == SEQ_LEFTHANDLE) {
462                         numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), "%d", seq->startdisp);
463                         x1 = rx1;
464                         y1 -= 0.45f;
465                 }
466                 else {
467                         numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), "%d", seq->enddisp - 1);
468                         x1 = x2 - handsize_clamped * 0.75f;
469                         y1 = y2 + 0.05f;
470                 }
471                 UI_view2d_text_cache_add(v2d, x1, y1, numstr, numstr_len, col);
472         }
473 }
474
475 /* draw info text on a sequence strip */
476 static void draw_seq_text(View2D *v2d, SpaceSeq *sseq, Sequence *seq, float x1, float x2, float y1, float y2, const unsigned char background_col[3])
477 {
478         rctf rect;
479         char str[32 + FILE_MAX];
480         size_t str_len;
481         const char *name = seq->name + 2;
482         char col[4];
483
484         /* note, all strings should include 'name' */
485         if (name[0] == '\0')
486                 name = BKE_sequence_give_name(seq);
487
488         if (seq->type == SEQ_TYPE_META || seq->type == SEQ_TYPE_ADJUSTMENT) {
489                 str_len = BLI_snprintf(str, sizeof(str), "%s | %d", name, seq->len);
490         }
491         else if (seq->type == SEQ_TYPE_SCENE) {
492                 if (seq->scene) {
493                         if (seq->scene_camera) {
494                                 str_len = BLI_snprintf(str, sizeof(str), "%s: %s (%s) | %d",
495                                                        name, seq->scene->id.name + 2, ((ID *)seq->scene_camera)->name + 2, seq->len);
496                         }
497                         else {
498                                 str_len = BLI_snprintf(str, sizeof(str), "%s: %s | %d",
499                                                        name, seq->scene->id.name + 2, seq->len);
500                         }
501                 }
502                 else {
503                         str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
504                                                name, seq->len);
505                 }
506         }
507         else if (seq->type == SEQ_TYPE_MOVIECLIP) {
508                 if (seq->clip && !STREQ(name, seq->clip->id.name + 2)) {
509                         str_len = BLI_snprintf(str, sizeof(str), "%s: %s | %d",
510                                                name, seq->clip->id.name + 2, seq->len);
511                 }
512                 else {
513                         str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
514                                                name, seq->len);
515                 }
516         }
517         else if (seq->type == SEQ_TYPE_MASK) {
518                 if (seq->mask && !STREQ(name, seq->mask->id.name + 2)) {
519                         str_len = BLI_snprintf(str, sizeof(str), "%s: %s | %d",
520                                                name, seq->mask->id.name + 2, seq->len);
521                 }
522                 else {
523                         str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
524                                                name, seq->len);
525                 }
526         }
527         else if (seq->type == SEQ_TYPE_MULTICAM) {
528                 str_len = BLI_snprintf(str, sizeof(str), "Cam %s: %d",
529                                        name, seq->multicam_source);
530         }
531         else if (seq->type == SEQ_TYPE_IMAGE) {
532                 str_len = BLI_snprintf(str, sizeof(str), "%s: %s%s | %d",
533                                        name, seq->strip->dir, seq->strip->stripdata->name, seq->len);
534         }
535         else if (seq->type == SEQ_TYPE_TEXT) {
536                 TextVars *textdata = seq->effectdata;
537                 str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
538                                        textdata->text, seq->startdisp);
539         }
540         else if (seq->type & SEQ_TYPE_EFFECT) {
541                 str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
542                                        name, seq->len);
543         }
544         else if (seq->type == SEQ_TYPE_SOUND_RAM) {
545                 /* If a waveform is drawn, we don't want to overlay it with text,
546                  * as it would make both hard to read. */
547                 if ((sseq->flag & SEQ_ALL_WAVEFORMS) || (seq->flag & SEQ_AUDIO_DRAW_WAVEFORM)) {
548                         str[0] = 0;
549                         str_len = 0;
550                 }
551                 else if (seq->sound) {
552                         str_len = BLI_snprintf(str, sizeof(str), "%s: %s | %d",
553                                                name, seq->sound->name, seq->len);
554                 }
555                 else {
556                         str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
557                                                name, seq->len);
558                 }
559         }
560         else if (seq->type == SEQ_TYPE_MOVIE) {
561                 str_len = BLI_snprintf(str, sizeof(str), "%s: %s%s | %d",
562                                        name, seq->strip->dir, seq->strip->stripdata->name, seq->len);
563         }
564         else {
565                 /* should never get here!, but might with files from future */
566                 BLI_assert(0);
567
568                 str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
569                                        name, seq->len);
570         }
571         
572         if (seq->flag & SELECT) {
573                 col[0] = col[1] = col[2] = 255;
574         }
575         else if ((((int)background_col[0] + (int)background_col[1] + (int)background_col[2]) / 3) < 50) {
576                 col[0] = col[1] = col[2] = 80; /* use lighter text color for dark background */
577         }
578         else {
579                 col[0] = col[1] = col[2] = 0;
580         }
581         col[3] = 255;
582
583         rect.xmin = x1;
584         rect.ymin = y1;
585         rect.xmax = x2;
586         rect.ymax = y2;
587
588         UI_view2d_text_cache_add_rectf(v2d, &rect, str, str_len, col);
589 }
590
591 /* draws a shaded strip, made from gradient + flat color + gradient */
592 void draw_shadedstrip(Sequence *seq, unsigned char col[3], float x1, float y1, float x2, float y2)
593 {
594         float ymid1, ymid2;
595         
596         if (seq->flag & SEQ_MUTE) {
597                 GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
598                 GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_HALFTONE);
599         }
600         
601         ymid1 = (y2 - y1) * 0.25f + y1;
602         ymid2 = (y2 - y1) * 0.65f + y1;
603         
604         glBegin(GL_QUADS);
605         
606         if (seq->flag & SEQ_INVALID_EFFECT) { col[0] = 255; col[1] = 0; col[2] = 255; }
607         else if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, -50);
608         /* else UI_GetColorPtrShade3ubv(col, col, 0); */ /* DO NOTHING */
609         
610         glColor3ubv(col);
611         
612         glVertex2f(x1, y1);
613         glVertex2f(x2, y1);
614
615         if (seq->flag & SEQ_INVALID_EFFECT) { col[0] = 255; col[1] = 0; col[2] = 255; }
616         else if (seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, 5);
617         else UI_GetColorPtrShade3ubv(col, col, -5);
618
619         glColor3ubv((GLubyte *)col);
620         
621         glVertex2f(x2, ymid1);
622         glVertex2f(x1, ymid1);
623         
624         glEnd();
625         
626         glRectf(x1,  ymid1,  x2,  ymid2);
627         
628         glBegin(GL_QUADS);
629         
630         glVertex2f(x1, ymid2);
631         glVertex2f(x2, ymid2);
632         
633         if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, -15);
634         else UI_GetColorPtrShade3ubv(col, col, 25);
635         
636         glColor3ubv((GLubyte *)col);
637         
638         glVertex2f(x2, y2);
639         glVertex2f(x1, y2);
640         
641         glEnd();
642         
643         if (seq->flag & SEQ_MUTE) {
644                 GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
645         }
646 }
647
648 void draw_sequence_extensions(Scene *scene, ARegion *ar, Sequence *seq)
649 {
650         float x1, x2, y1, y2, pixely, a;
651         unsigned char col[3], blendcol[3];
652         View2D *v2d = &ar->v2d;
653         
654         x1 = seq->startdisp;
655         x2 = seq->enddisp;
656         
657         y1 = seq->machine + SEQ_STRIP_OFSBOTTOM;
658         y2 = seq->machine + SEQ_STRIP_OFSTOP;
659         
660         pixely = BLI_rctf_size_y(&v2d->cur) / BLI_rcti_size_y(&v2d->mask);
661         
662         if (pixely <= 0) return;  /* can happen when the view is split/resized */
663         
664         blendcol[0] = blendcol[1] = blendcol[2] = 120;
665         
666         if (seq->startofs) {
667                 glEnable(GL_BLEND);
668                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
669                 
670                 color3ubv_from_seq(scene, seq, col);
671                 
672                 if (seq->flag & SELECT) {
673                         UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.3, -40);
674                         glColor4ub(col[0], col[1], col[2], 170);
675                 }
676                 else {
677                         UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.6, 0);
678                         glColor4ub(col[0], col[1], col[2], 110);
679                 }
680                 
681                 glRectf((float)(seq->start), y1 - SEQ_STRIP_OFSBOTTOM, x1, y1);
682                 
683                 if (seq->flag & SELECT) glColor4ub(col[0], col[1], col[2], 255);
684                 else glColor4ub(col[0], col[1], col[2], 160);
685                 
686                 fdrawbox((float)(seq->start), y1 - SEQ_STRIP_OFSBOTTOM, x1, y1);  //outline
687                 
688                 glDisable(GL_BLEND);
689         }
690         if (seq->endofs) {
691                 glEnable(GL_BLEND);
692                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
693                 
694                 color3ubv_from_seq(scene, seq, col);
695                 
696                 if (seq->flag & SELECT) {
697                         UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.3, -40);
698                         glColor4ub(col[0], col[1], col[2], 170);
699                 }
700                 else {
701                         UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.6, 0);
702                         glColor4ub(col[0], col[1], col[2], 110);
703                 }
704                 
705                 glRectf(x2, y2, (float)(seq->start + seq->len), y2 + SEQ_STRIP_OFSBOTTOM);
706                 
707                 if (seq->flag & SELECT) glColor4ub(col[0], col[1], col[2], 255);
708                 else glColor4ub(col[0], col[1], col[2], 160);
709                 
710                 fdrawbox(x2, y2, (float)(seq->start + seq->len), y2 + SEQ_STRIP_OFSBOTTOM); //outline
711                 
712                 glDisable(GL_BLEND);
713         }
714         if (seq->startstill) {
715                 color3ubv_from_seq(scene, seq, col);
716                 UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.75, 40);
717                 glColor3ubv((GLubyte *)col);
718                 
719                 draw_shadedstrip(seq, col, x1, y1, (float)(seq->start), y2);
720                 
721                 /* feint pinstripes, helps see exactly which is extended and which isn't,
722                  * especially when the extension is very small */
723                 if (seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, 24);
724                 else UI_GetColorPtrShade3ubv(col, col, -16);
725                 
726                 glColor3ubv((GLubyte *)col);
727                 
728                 for (a = y1; a < y2; a += pixely * 2.0f) {
729                         fdrawline(x1,  a,  (float)(seq->start),  a);
730                 }
731         }
732         if (seq->endstill) {
733                 color3ubv_from_seq(scene, seq, col);
734                 UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.75, 40);
735                 glColor3ubv((GLubyte *)col);
736                 
737                 draw_shadedstrip(seq, col, (float)(seq->start + seq->len), y1, x2, y2);
738                 
739                 /* feint pinstripes, helps see exactly which is extended and which isn't,
740                  * especially when the extension is very small */
741                 if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, 24);
742                 else UI_GetColorPtrShade3ubv(col, col, -16);
743                 
744                 glColor3ubv((GLubyte *)col);
745                 
746                 for (a = y1; a < y2; a += pixely * 2.0f) {
747                         fdrawline((float)(seq->start + seq->len),  a,  x2,  a);
748                 }
749         }
750 }
751
752
753 /*
754  * Draw a sequence strip, bounds check already made
755  * ARegion is currently only used to get the windows width in pixels
756  * so wave file sample drawing precision is zoom adjusted
757  */
758 static void draw_seq_strip(const bContext *C, SpaceSeq *sseq, Scene *scene, ARegion *ar, Sequence *seq, int outline_tint, float pixelx)
759 {
760         View2D *v2d = &ar->v2d;
761         float x1, x2, y1, y2;
762         unsigned char col[3], background_col[3], is_single_image;
763         const float handsize_clamped = draw_seq_handle_size_get_clamped(seq, pixelx);
764
765         /* we need to know if this is a single image/color or not for drawing */
766         is_single_image = (char)BKE_sequence_single_check(seq);
767         
768         /* body */
769         x1 = (seq->startstill) ? seq->start : seq->startdisp;
770         y1 = seq->machine + SEQ_STRIP_OFSBOTTOM;
771         x2 = (seq->endstill) ? (seq->start + seq->len) : seq->enddisp;
772         y2 = seq->machine + SEQ_STRIP_OFSTOP;
773
774
775         /* get the correct color per strip type*/
776         //color3ubv_from_seq(scene, seq, col);
777         color3ubv_from_seq(scene, seq, background_col);
778         
779         /* draw the main strip body */
780         if (is_single_image) {  /* single image */
781                 draw_shadedstrip(seq, background_col,
782                                  BKE_sequence_tx_get_final_left(seq, false), y1,
783                                  BKE_sequence_tx_get_final_right(seq, false), y2);
784         }
785         else {  /* normal operation */
786                 draw_shadedstrip(seq, background_col, x1, y1, x2, y2);
787         }
788
789         if (!is_single_image) {
790                 if ((sseq->draw_flag & SEQ_DRAW_OFFSET_EXT) || (seq == special_seq_update)) {
791                         draw_sequence_extensions(scene, ar, seq);
792                 }
793         }
794
795         draw_seq_handle(v2d, seq, handsize_clamped, SEQ_LEFTHANDLE);
796         draw_seq_handle(v2d, seq, handsize_clamped, SEQ_RIGHTHANDLE);
797         
798         /* draw the strip outline */
799         x1 = seq->startdisp;
800         x2 = seq->enddisp;
801         
802         /* draw sound wave */
803         if (seq->type == SEQ_TYPE_SOUND_RAM) {
804                 if (!(sseq->flag & SEQ_NO_WAVEFORMS)) {
805                         drawseqwave(C, sseq, scene, seq, x1, y1, x2, y2, BLI_rctf_size_x(&ar->v2d.cur) / ar->winx);
806                 }
807         }
808
809         /* draw lock */
810         if (seq->flag & SEQ_LOCK) {
811                 GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
812                 glEnable(GL_BLEND);
813
814                 /* light stripes */
815                 glColor4ub(255, 255, 255, 32);
816                 GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_DIAG_STRIPES);
817                 glRectf(x1, y1, x2, y2);
818
819                 /* dark stripes */
820                 glColor4ub(0, 0, 0, 32);
821                 GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_DIAG_STRIPES_SWAP);
822                 glRectf(x1, y1, x2, y2);
823
824                 GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
825                 glDisable(GL_BLEND);
826         }
827
828         if (!BKE_sequence_is_valid_check(seq)) {
829                 GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
830
831                 /* panic! */
832                 glColor4ub(255, 0, 0, 255);
833                 GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_DIAG_STRIPES);
834                 glRectf(x1, y1, x2, y2);
835
836                 GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
837         }
838
839         color3ubv_from_seq(scene, seq, col);
840         if ((G.moving & G_TRANSFORM_SEQ) && (seq->flag & SELECT)) {
841                 if (seq->flag & SEQ_OVERLAP) {
842                         col[0] = 255; col[1] = col[2] = 40;
843                 }
844                 else
845                         UI_GetColorPtrShade3ubv(col, col, 120 + outline_tint);
846         }
847         else
848                 UI_GetColorPtrShade3ubv(col, col, outline_tint);
849         
850         if ((seq->type == SEQ_TYPE_META) ||
851             ((seq->type == SEQ_TYPE_SCENE) && (seq->flag & SEQ_SCENE_STRIPS)))
852         {
853                 drawmeta_contents(scene, seq, x1, y1, x2, y2);
854         }
855
856         if (seq->flag & SEQ_MUTE) {
857                 glEnable(GL_LINE_STIPPLE);
858                 glLineStipple(1, 0x8888);
859         }
860         
861         glColor3ubv((GLubyte *)col);
862         
863         UI_draw_roundbox_shade_x(GL_LINE_LOOP, x1, y1, x2, y2, 0.0, 0.1, 0.0);
864         
865         if (seq->flag & SEQ_MUTE) {
866                 glDisable(GL_LINE_STIPPLE);
867         }
868         
869         /* calculate if seq is long enough to print a name */
870         x1 = seq->startdisp + handsize_clamped;
871         x2 = seq->enddisp   - handsize_clamped;
872
873         /* info text on the strip */
874         if (x1 < v2d->cur.xmin) x1 = v2d->cur.xmin;
875         else if (x1 > v2d->cur.xmax) x1 = v2d->cur.xmax;
876         if (x2 < v2d->cur.xmin) x2 = v2d->cur.xmin;
877         else if (x2 > v2d->cur.xmax) x2 = v2d->cur.xmax;
878
879         /* nice text here would require changing the view matrix for texture text */
880         if ((x2 - x1) / pixelx > 32) {
881                 draw_seq_text(v2d, sseq, seq, x1, x2, y1, y2, background_col);
882         }
883 }
884
885 void sequencer_special_update_set(Sequence *seq)
886 {
887         special_seq_update = seq;
888 }
889
890 Sequence *ED_sequencer_special_preview_get(void)
891 {
892         return special_seq_update;
893 }
894
895 void ED_sequencer_special_preview_set(bContext *C, const int mval[2])
896 {
897         Scene *scene = CTX_data_scene(C);
898         ARegion *ar = CTX_wm_region(C);
899         int hand;
900         Sequence *seq;
901         seq = find_nearest_seq(scene, &ar->v2d, &hand, mval);
902         sequencer_special_update_set(seq);
903 }
904
905 void ED_sequencer_special_preview_clear(void)
906 {
907         sequencer_special_update_set(NULL);
908 }
909
910 ImBuf *sequencer_ibuf_get(struct Main *bmain, Scene *scene, SpaceSeq *sseq, int cfra, int frame_ofs, const char *viewname)
911 {
912         SeqRenderData context = {0};
913         ImBuf *ibuf;
914         int rectx, recty;
915         float render_size;
916         float proxy_size = 100.0;
917         short is_break = G.is_break;
918
919         render_size = sseq->render_size;
920         if (render_size == 0) {
921                 render_size = scene->r.size;
922         }
923         else {
924                 proxy_size = render_size;
925         }
926
927         if (render_size < 0) {
928                 return NULL;
929         }
930
931         rectx = (render_size * (float)scene->r.xsch) / 100.0f + 0.5f;
932         recty = (render_size * (float)scene->r.ysch) / 100.0f + 0.5f;
933
934         BKE_sequencer_new_render_data(
935                 bmain->eval_ctx, bmain, scene,
936                 rectx, recty, proxy_size,
937                 &context);
938         context.view_id = BKE_scene_multiview_view_id_get(&scene->r, viewname);
939         if (scene->r.seq_flag & R_SEQ_CAMERA_DOF) {
940                 if (sseq->compositor == NULL) {
941                         sseq->compositor = GPU_fx_compositor_create();
942                 }
943                 context.gpu_fx = sseq->compositor;
944         }
945
946         /* sequencer could start rendering, in this case we need to be sure it wouldn't be canceled
947          * by Esc pressed somewhere in the past
948          */
949         G.is_break = false;
950
951         if (special_seq_update)
952                 ibuf = BKE_sequencer_give_ibuf_direct(&context, cfra + frame_ofs, special_seq_update);
953         else if (!U.prefetchframes) // XXX || (G.f & G_PLAYANIM) == 0) {
954                 ibuf = BKE_sequencer_give_ibuf(&context, cfra + frame_ofs, sseq->chanshown);
955         else
956                 ibuf = BKE_sequencer_give_ibuf_threaded(&context, cfra + frame_ofs, sseq->chanshown);
957
958         /* restore state so real rendering would be canceled (if needed) */
959         G.is_break = is_break;
960
961         return ibuf;
962 }
963
964 static void sequencer_check_scopes(SequencerScopes *scopes, ImBuf *ibuf)
965 {
966         if (scopes->reference_ibuf != ibuf) {
967                 if (scopes->zebra_ibuf) {
968                         IMB_freeImBuf(scopes->zebra_ibuf);
969                         scopes->zebra_ibuf = NULL;
970                 }
971
972                 if (scopes->waveform_ibuf) {
973                         IMB_freeImBuf(scopes->waveform_ibuf);
974                         scopes->waveform_ibuf = NULL;
975                 }
976
977                 if (scopes->sep_waveform_ibuf) {
978                         IMB_freeImBuf(scopes->sep_waveform_ibuf);
979                         scopes->sep_waveform_ibuf = NULL;
980                 }
981
982                 if (scopes->vector_ibuf) {
983                         IMB_freeImBuf(scopes->vector_ibuf);
984                         scopes->vector_ibuf = NULL;
985                 }
986
987                 if (scopes->histogram_ibuf) {
988                         IMB_freeImBuf(scopes->histogram_ibuf);
989                         scopes->histogram_ibuf = NULL;
990                 }
991         }
992 }
993
994 static ImBuf *sequencer_make_scope(Scene *scene, ImBuf *ibuf, ImBuf *(*make_scope_cb) (ImBuf *ibuf))
995 {
996         ImBuf *display_ibuf = IMB_dupImBuf(ibuf);
997         ImBuf *scope;
998         
999         IMB_colormanagement_imbuf_make_display_space(display_ibuf, &scene->view_settings,
1000                                                              &scene->display_settings);
1001
1002         scope = make_scope_cb(display_ibuf);
1003
1004         IMB_freeImBuf(display_ibuf);
1005
1006         return scope;
1007 }
1008
1009 static void sequencer_display_size(Scene *scene, SpaceSeq *sseq, float r_viewrect[2])
1010 {
1011         float render_size, proxy_size;
1012
1013         if (sseq->render_size == SEQ_PROXY_RENDER_SIZE_SCENE) {
1014                 render_size = (float)scene->r.size / 100.0f;
1015                 proxy_size = 1.0f;
1016         }
1017         else {
1018                 render_size = (float)sseq->render_size / 100.0f;
1019                 proxy_size = render_size;
1020         }
1021
1022         r_viewrect[0] = (render_size * (float)scene->r.xsch);
1023         r_viewrect[1] = (render_size * (float)scene->r.ysch);
1024
1025         /* rectx = viewrectx + 0.5f; */ /* UNUSED */
1026         /* recty = viewrecty + 0.5f; */ /* UNUSED */
1027
1028         if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1029                 r_viewrect[0] *= scene->r.xasp / scene->r.yasp;
1030                 r_viewrect[0] /= proxy_size;
1031                 r_viewrect[1] /= proxy_size;
1032         }
1033 }
1034
1035 static void sequencer_draw_gpencil(const bContext *C)
1036 {
1037         /* draw grease-pencil (image aligned) */
1038         ED_gpencil_draw_2dimage(C);
1039
1040         /* ortho at pixel level */
1041         UI_view2d_view_restore(C);
1042
1043         /* draw grease-pencil (screen aligned) */
1044         ED_gpencil_draw_view2d(C, 0);
1045 }
1046
1047 /* draws content borders plus safety borders if needed */
1048 static void sequencer_draw_borders(const SpaceSeq *sseq, const View2D *v2d, const Scene *scene)
1049 {
1050         float x1 = v2d->tot.xmin;
1051         float y1 = v2d->tot.ymin;
1052         float x2 = v2d->tot.xmax;
1053         float y2 = v2d->tot.ymax;
1054
1055         glLineWidth(1.0f);
1056
1057         /* border */
1058         setlinestyle(3);
1059
1060         UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 1.0, 0);
1061
1062         glBegin(GL_LINE_LOOP);
1063         glVertex2f(x1 - 0.5f, y1 - 0.5f);
1064         glVertex2f(x1 - 0.5f, y2 + 0.5f);
1065         glVertex2f(x2 + 0.5f, y2 + 0.5f);
1066         glVertex2f(x2 + 0.5f, y1 - 0.5f);
1067         glEnd();
1068
1069         /* safety border */
1070         if (sseq->flag & SEQ_SHOW_SAFE_MARGINS) {
1071                 UI_draw_safe_areas(
1072                         x1, x2, y1, y2,
1073                         scene->safe_areas.title,
1074                         scene->safe_areas.action);
1075
1076                 if (sseq->flag & SEQ_SHOW_SAFE_CENTER) {
1077                         UI_draw_safe_areas(
1078                                 x1, x2, y1, y2,
1079                                 scene->safe_areas.title_center,
1080                                 scene->safe_areas.action_center);
1081                 }
1082         }
1083
1084         setlinestyle(0);
1085 }
1086
1087 /* draws checkerboard background for transparent content */
1088 static void sequencer_draw_background(
1089         const SpaceSeq *sseq, View2D *v2d, const float viewrect[2], const bool draw_overlay)
1090 {
1091         /* setting up the view */
1092         UI_view2d_totRect_set(v2d, viewrect[0] + 0.5f, viewrect[1] + 0.5f);
1093         UI_view2d_curRect_validate(v2d);
1094         UI_view2d_view_ortho(v2d);
1095
1096         /* only draw alpha for main buffer */
1097         if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1098                 if ((sseq->flag & SEQ_USE_ALPHA) && !draw_overlay) {
1099                         glEnable(GL_BLEND);
1100                         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1101
1102                         fdrawcheckerboard(v2d->tot.xmin, v2d->tot.ymin, v2d->tot.xmax, v2d->tot.ymax);
1103                         glColor4f(1.0, 1.0, 1.0, 1.0);
1104                 }
1105         }
1106 }
1107
1108 void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq, int cfra, int frame_ofs, bool draw_overlay, bool draw_backdrop)
1109 {
1110         struct Main *bmain = CTX_data_main(C);
1111         struct ImBuf *ibuf = NULL;
1112         struct ImBuf *scope = NULL;
1113         struct View2D *v2d = &ar->v2d;
1114         /* int rectx, recty; */ /* UNUSED */
1115         float viewrect[2];
1116         float col[3];
1117         GLuint texid;
1118         void *display_buffer;
1119         void *cache_handle = NULL;
1120         const bool is_imbuf = ED_space_sequencer_check_show_imbuf(sseq);
1121         int format, type;
1122         bool glsl_used = false;
1123         const bool draw_gpencil = ((sseq->flag & SEQ_SHOW_GPENCIL) && sseq->gpd);
1124         const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME};
1125         bool draw_metadata = false;
1126
1127         if (G.is_rendering == false && (scene->r.seq_prev_type) == OB_RENDER) {
1128                 /* stop all running jobs, except screen one. currently previews frustrate Render
1129                  * needed to make so sequencer's rendering doesn't conflict with compositor
1130                  */
1131                 WM_jobs_kill_type(CTX_wm_manager(C), NULL, WM_JOB_TYPE_COMPOSITE);
1132
1133                 /* in case of final rendering used for preview, kill all previews,
1134                  * otherwise threading conflict will happen in rendering module
1135                  */
1136                 WM_jobs_kill_type(CTX_wm_manager(C), NULL, WM_JOB_TYPE_RENDER_PREVIEW);
1137         }
1138
1139         if ((!draw_overlay || sseq->overlay_type == SEQ_DRAW_OVERLAY_REFERENCE) && !draw_backdrop) {
1140                 UI_GetThemeColor3fv(TH_SEQ_PREVIEW, col);
1141                 glClearColor(col[0], col[1], col[2], 0.0);
1142                 glClear(GL_COLOR_BUFFER_BIT);
1143         }
1144
1145         /* without this colors can flicker from previous opengl state */
1146         glColor4ub(255, 255, 255, 255);
1147
1148         /* only initialize the preview if a render is in progress */
1149         if (G.is_rendering)
1150                 return;
1151
1152         if (sseq->render_size == SEQ_PROXY_RENDER_SIZE_NONE) {
1153                 return;
1154         }
1155
1156         /* for now we only support Left/Right */
1157         ibuf = sequencer_ibuf_get(bmain, scene, sseq, cfra, frame_ofs, names[sseq->multiview_eye]);
1158
1159         if ((ibuf == NULL) ||
1160             (ibuf->rect == NULL && ibuf->rect_float == NULL))
1161         {
1162                 /* gpencil can also be drawn without a valid imbuf */
1163                 if ((draw_gpencil && is_imbuf) && !draw_overlay) {
1164                         sequencer_display_size(scene, sseq, viewrect);
1165
1166                         sequencer_draw_background(sseq, v2d, viewrect, false);
1167                         sequencer_draw_borders(sseq, v2d, scene);
1168
1169                         sequencer_draw_gpencil(C);
1170                 }
1171                 return;
1172         }
1173
1174         sequencer_display_size(scene, sseq, viewrect);
1175
1176         if (!draw_backdrop && (sseq->mainb != SEQ_DRAW_IMG_IMBUF || sseq->zebra != 0)) {
1177                 SequencerScopes *scopes = &sseq->scopes;
1178
1179                 sequencer_check_scopes(scopes, ibuf);
1180
1181                 switch (sseq->mainb) {
1182                         case SEQ_DRAW_IMG_IMBUF:
1183                                 if (!scopes->zebra_ibuf) {
1184                                         ImBuf *display_ibuf = IMB_dupImBuf(ibuf);
1185
1186                                         if (display_ibuf->rect_float) {
1187                                                 IMB_colormanagement_imbuf_make_display_space(display_ibuf, &scene->view_settings,
1188                                                                                              &scene->display_settings);
1189                                         }
1190                                         scopes->zebra_ibuf = make_zebra_view_from_ibuf(display_ibuf, sseq->zebra);
1191                                         IMB_freeImBuf(display_ibuf);
1192                                 }
1193                                 scope = scopes->zebra_ibuf;
1194                                 break;
1195                         case SEQ_DRAW_IMG_WAVEFORM:
1196                                 if ((sseq->flag & SEQ_DRAW_COLOR_SEPARATED) != 0) {
1197                                         if (!scopes->sep_waveform_ibuf)
1198                                                 scopes->sep_waveform_ibuf = sequencer_make_scope(scene, ibuf, make_sep_waveform_view_from_ibuf);
1199                                         scope = scopes->sep_waveform_ibuf;
1200                                 }
1201                                 else {
1202                                         if (!scopes->waveform_ibuf)
1203                                                 scopes->waveform_ibuf = sequencer_make_scope(scene, ibuf, make_waveform_view_from_ibuf);
1204                                         scope = scopes->waveform_ibuf;
1205                                 }
1206                                 break;
1207                         case SEQ_DRAW_IMG_VECTORSCOPE:
1208                                 if (!scopes->vector_ibuf)
1209                                         scopes->vector_ibuf = sequencer_make_scope(scene, ibuf, make_vectorscope_view_from_ibuf);
1210                                 scope = scopes->vector_ibuf;
1211                                 break;
1212                         case SEQ_DRAW_IMG_HISTOGRAM:
1213                                 if (!scopes->histogram_ibuf)
1214                                         scopes->histogram_ibuf = sequencer_make_scope(scene, ibuf, make_histogram_view_from_ibuf);
1215                                 scope = scopes->histogram_ibuf;
1216                                 break;
1217                 }
1218
1219                 /* future files may have new scopes we don't catch above */
1220                 if (scope) {
1221                         scopes->reference_ibuf = ibuf;
1222                         if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1223                                 /* scopes drawn in image preview use viewrect from orig ibuf - currently that's only zebra */
1224                         }
1225                         else {
1226                                 viewrect[0] = scope->x;
1227                                 viewrect[1] = scope->y;
1228                         }
1229                 }
1230                 else {
1231                         scopes->reference_ibuf = NULL;
1232                 }
1233         }
1234
1235         if (!draw_backdrop) {
1236                 sequencer_draw_background(sseq, v2d, viewrect, draw_overlay);
1237         }
1238
1239         if (scope) {
1240                 IMB_freeImBuf(ibuf);
1241                 ibuf = scope;
1242
1243                 if (ibuf->rect_float && ibuf->rect == NULL) {
1244                         IMB_rect_from_float(ibuf);
1245                 }
1246
1247                 display_buffer = (unsigned char *)ibuf->rect;
1248                 format = GL_RGBA;
1249                 type = GL_UNSIGNED_BYTE;
1250         }
1251         else {
1252                 bool force_fallback = false;
1253
1254                 force_fallback |= (U.image_draw_method != IMAGE_DRAW_METHOD_GLSL);
1255                 force_fallback |= (ibuf->dither != 0.0f);
1256
1257                 if (force_fallback) {
1258                         /* Fallback to CPU based color space conversion */
1259                         glsl_used = false;
1260                         format = GL_RGBA;
1261                         type = GL_UNSIGNED_BYTE;
1262                         display_buffer = NULL;
1263                 }
1264                 else if (ibuf->rect_float) {
1265                         display_buffer = ibuf->rect_float;
1266
1267                         if (ibuf->channels == 4) {
1268                                 format = GL_RGBA;
1269                         }
1270                         else if (ibuf->channels == 3) {
1271                                 format = GL_RGB;
1272                         }
1273                         else {
1274                                 BLI_assert(!"Incompatible number of channels for float buffer in sequencer");
1275                                 format = GL_RGBA;
1276                                 display_buffer = NULL;
1277                         }
1278
1279                         type = GL_FLOAT;
1280
1281                         if (ibuf->float_colorspace) {
1282                                 glsl_used = IMB_colormanagement_setup_glsl_draw_from_space_ctx(C, ibuf->float_colorspace, ibuf->dither, true);
1283                         }
1284                         else {
1285                                 glsl_used = IMB_colormanagement_setup_glsl_draw_ctx(C, ibuf->dither, true);
1286                         }
1287                 }
1288                 else if (ibuf->rect) {
1289                         display_buffer = ibuf->rect;
1290                         format = GL_RGBA;
1291                         type = GL_UNSIGNED_BYTE;
1292
1293                         glsl_used = IMB_colormanagement_setup_glsl_draw_from_space_ctx(C, ibuf->rect_colorspace, ibuf->dither, false);
1294                 }
1295                 else {
1296                         format = GL_RGBA;
1297                         type = GL_UNSIGNED_BYTE;
1298                         display_buffer = NULL;
1299                 }
1300
1301                 /* there's a data to be displayed, but GLSL is not initialized
1302                  * properly, in this case we fallback to CPU-based display transform
1303                  */
1304                 if ((ibuf->rect || ibuf->rect_float) && !glsl_used) {
1305                         display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
1306                         format = GL_RGBA;
1307                         type = GL_UNSIGNED_BYTE;
1308                 }
1309         }
1310
1311         glColor4f(1.0, 1.0, 1.0, 1.0);
1312
1313         GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
1314         glGenTextures(1, (GLuint *)&texid);
1315
1316         glBindTexture(GL_TEXTURE_2D, texid);
1317
1318         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1319         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1320
1321         if (type == GL_FLOAT)
1322                 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, ibuf->x, ibuf->y, 0, format, type, display_buffer);
1323         else
1324                 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, format, type, display_buffer);
1325
1326         if (draw_backdrop) {
1327                 glMatrixMode(GL_PROJECTION);
1328                 glPushMatrix();
1329                 glLoadIdentity();
1330                 glMatrixMode(GL_MODELVIEW);
1331                 glPushMatrix();
1332                 glLoadIdentity();
1333         }
1334         glBegin(GL_QUADS);
1335
1336         if (draw_overlay) {
1337                 if (sseq->overlay_type == SEQ_DRAW_OVERLAY_RECT) {
1338                         rctf tot_clip;
1339                         tot_clip.xmin = v2d->tot.xmin + (fabsf(BLI_rctf_size_x(&v2d->tot)) * scene->ed->over_border.xmin);
1340                         tot_clip.ymin = v2d->tot.ymin + (fabsf(BLI_rctf_size_y(&v2d->tot)) * scene->ed->over_border.ymin);
1341                         tot_clip.xmax = v2d->tot.xmin + (fabsf(BLI_rctf_size_x(&v2d->tot)) * scene->ed->over_border.xmax);
1342                         tot_clip.ymax = v2d->tot.ymin + (fabsf(BLI_rctf_size_y(&v2d->tot)) * scene->ed->over_border.ymax);
1343
1344                         glTexCoord2f(scene->ed->over_border.xmin, scene->ed->over_border.ymin); glVertex2f(tot_clip.xmin, tot_clip.ymin);
1345                         glTexCoord2f(scene->ed->over_border.xmin, scene->ed->over_border.ymax); glVertex2f(tot_clip.xmin, tot_clip.ymax);
1346                         glTexCoord2f(scene->ed->over_border.xmax, scene->ed->over_border.ymax); glVertex2f(tot_clip.xmax, tot_clip.ymax);
1347                         glTexCoord2f(scene->ed->over_border.xmax, scene->ed->over_border.ymin); glVertex2f(tot_clip.xmax, tot_clip.ymin);
1348                 }
1349                 else if (sseq->overlay_type == SEQ_DRAW_OVERLAY_REFERENCE) {
1350                         glTexCoord2f(0.0f, 0.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymin);
1351                         glTexCoord2f(0.0f, 1.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymax);
1352                         glTexCoord2f(1.0f, 1.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymax);
1353                         glTexCoord2f(1.0f, 0.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymin);
1354                 }
1355         }
1356         else if (draw_backdrop) {
1357                 float aspect;
1358                 float image_aspect = viewrect[0] / viewrect[1];
1359                 float imagex, imagey;
1360
1361                 aspect = BLI_rcti_size_x(&ar->winrct) / (float)BLI_rcti_size_y(&ar->winrct);
1362
1363                 if (aspect >= image_aspect) {
1364                         imagex = image_aspect / aspect;
1365                         imagey = 1.0f;
1366                 }
1367                 else {
1368                         imagex = 1.0f;
1369                         imagey = aspect / image_aspect;
1370                 }
1371
1372                 glTexCoord2f(0.0f, 0.0f); glVertex2f(-imagex, -imagey);
1373                 glTexCoord2f(0.0f, 1.0f); glVertex2f(-imagex, imagey);
1374                 glTexCoord2f(1.0f, 1.0f); glVertex2f(imagex, imagey);
1375                 glTexCoord2f(1.0f, 0.0f); glVertex2f(imagex, -imagey);
1376         }
1377         else {
1378                 draw_metadata = ((sseq->flag & SEQ_SHOW_METADATA) != 0);
1379
1380                 glTexCoord2f(0.0f, 0.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymin);
1381                 glTexCoord2f(0.0f, 1.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymax);
1382                 glTexCoord2f(1.0f, 1.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymax);
1383                 glTexCoord2f(1.0f, 0.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymin);
1384         }
1385         glEnd();
1386
1387         glBindTexture(GL_TEXTURE_2D, 0);
1388         GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
1389         if (sseq->mainb == SEQ_DRAW_IMG_IMBUF && sseq->flag & SEQ_USE_ALPHA)
1390                 glDisable(GL_BLEND);
1391         glDeleteTextures(1, &texid);
1392
1393         if (glsl_used)
1394                 IMB_colormanagement_finish_glsl_draw();
1395
1396         if (cache_handle)
1397                 IMB_display_buffer_release(cache_handle);
1398
1399         if (!scope)
1400                 IMB_freeImBuf(ibuf);
1401
1402         if (draw_metadata) {
1403                 ED_region_image_metadata_draw(0.0, 0.0, ibuf, &v2d->tot, 1.0, 1.0);
1404         }
1405
1406         if (draw_backdrop) {
1407                 glPopMatrix();
1408                 glMatrixMode(GL_PROJECTION);
1409                 glPopMatrix();
1410                 glMatrixMode(GL_MODELVIEW);
1411                 return;
1412         }
1413
1414         if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1415                 sequencer_draw_borders(sseq, v2d, scene);
1416         }
1417
1418         if (draw_gpencil && is_imbuf) {
1419                 sequencer_draw_gpencil(C);
1420         }
1421         else {
1422                 /* ortho at pixel level */
1423                 UI_view2d_view_restore(C);
1424         }
1425
1426
1427         /* NOTE: sequencer mask editing isnt finished, the draw code is working but editing not,
1428          * for now just disable drawing since the strip frame will likely be offset */
1429
1430         //if (sc->mode == SC_MODE_MASKEDIT) {
1431         if (0 && sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1432                 Mask *mask = BKE_sequencer_mask_get(scene);
1433
1434                 if (mask) {
1435                         int width, height;
1436                         float aspx = 1.0f, aspy = 1.0f;
1437                         // ED_mask_get_size(C, &width, &height);
1438
1439                         //Scene *scene = CTX_data_scene(C);
1440                         width = (scene->r.size * scene->r.xsch) / 100;
1441                         height = (scene->r.size * scene->r.ysch) / 100;
1442
1443                         ED_mask_draw_region(mask, ar,
1444                                             0, 0, 0,  /* TODO */
1445                                             width, height,
1446                                             aspx, aspy,
1447                                             false, true,
1448                                             NULL, C);
1449                 }
1450         }
1451 }
1452
1453 #if 0
1454 void drawprefetchseqspace(Scene *scene, ARegion *UNUSED(ar), SpaceSeq *sseq)
1455 {
1456         int rectx, recty;
1457         int render_size = sseq->render_size;
1458         int proxy_size = 100.0; 
1459         if (render_size == 0) {
1460                 render_size = scene->r.size;
1461         }
1462         else {
1463                 proxy_size = render_size;
1464         }
1465         if (render_size < 0) {
1466                 return;
1467         }
1468
1469         rectx = (render_size * scene->r.xsch) / 100;
1470         recty = (render_size * scene->r.ysch) / 100;
1471
1472         if (sseq->mainb != SEQ_DRAW_SEQUENCE) {
1473                 give_ibuf_prefetch_request(
1474                     rectx, recty, (scene->r.cfra), sseq->chanshown,
1475                     proxy_size);
1476         }
1477 }
1478 #endif
1479
1480 /* draw backdrop of the sequencer strips view */
1481 static void draw_seq_backdrop(View2D *v2d)
1482 {
1483         int i;
1484         
1485         /* darker gray overlay over the view backdrop */
1486         UI_ThemeColorShade(TH_BACK, -20);
1487         glRectf(v2d->cur.xmin,  -1.0,  v2d->cur.xmax,  1.0);
1488
1489         /* Alternating horizontal stripes */
1490         i = max_ii(1, ((int)v2d->cur.ymin) - 1);
1491
1492         glBegin(GL_QUADS);
1493         while (i < v2d->cur.ymax) {
1494                 if (((int)i) & 1)
1495                         UI_ThemeColorShade(TH_BACK, -15);
1496                 else
1497                         UI_ThemeColorShade(TH_BACK, -25);
1498                         
1499                 glVertex2f(v2d->cur.xmax, i);
1500                 glVertex2f(v2d->cur.xmin, i);
1501                 glVertex2f(v2d->cur.xmin, i + 1);
1502                 glVertex2f(v2d->cur.xmax, i + 1);
1503
1504                 i += 1.0;
1505         }
1506         glEnd();
1507         
1508         /* Darker lines separating the horizontal bands */
1509         i = max_ii(1, ((int)v2d->cur.ymin) - 1);
1510         UI_ThemeColor(TH_GRID);
1511         
1512         glBegin(GL_LINES);
1513         while (i < v2d->cur.ymax) {
1514                 glVertex2f(v2d->cur.xmax, i);
1515                 glVertex2f(v2d->cur.xmin, i);
1516                         
1517                 i += 1.0;
1518         }
1519         glEnd();
1520 }
1521
1522 /* draw the contents of the sequencer strips view */
1523 static void draw_seq_strips(const bContext *C, Editing *ed, ARegion *ar)
1524 {
1525         Scene *scene = CTX_data_scene(C);
1526         View2D *v2d = &ar->v2d;
1527         SpaceSeq *sseq = CTX_wm_space_seq(C);
1528         Sequence *last_seq = BKE_sequencer_active_get(scene);
1529         int sel = 0, j;
1530         float pixelx = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask);
1531         
1532         /* loop through twice, first unselected, then selected */
1533         for (j = 0; j < 2; j++) {
1534                 Sequence *seq;
1535                 int outline_tint = (j) ? -60 : -150; /* highlighting around strip edges indicating selection */
1536                 
1537                 /* loop through strips, checking for those that are visible */
1538                 for (seq = ed->seqbasep->first; seq; seq = seq->next) {
1539                         /* boundbox and selection tests for NOT drawing the strip... */
1540                         if ((seq->flag & SELECT) != sel) continue;
1541                         else if (seq == last_seq) continue;
1542                         else if (min_ii(seq->startdisp, seq->start) > v2d->cur.xmax) continue;
1543                         else if (max_ii(seq->enddisp, seq->start + seq->len) < v2d->cur.xmin) continue;
1544                         else if (seq->machine + 1.0f < v2d->cur.ymin) continue;
1545                         else if (seq->machine > v2d->cur.ymax) continue;
1546                         
1547                         /* strip passed all tests unscathed... so draw it now */
1548                         draw_seq_strip(C, sseq, scene, ar, seq, outline_tint, pixelx);
1549                 }
1550                 
1551                 /* draw selected next time round */
1552                 sel = SELECT;
1553         }
1554         
1555         /* draw the last selected last (i.e. 'active' in other parts of Blender), removes some overlapping error */
1556         if (last_seq)
1557                 draw_seq_strip(C, sseq, scene, ar, last_seq, 120, pixelx);
1558
1559         /* draw highlight when previewing a single strip */
1560         if (special_seq_update) {
1561                 const Sequence *seq = special_seq_update;
1562                 glEnable(GL_BLEND);
1563                 glColor4ub(255, 255, 255, 48);
1564                 glRectf(seq->startdisp, seq->machine + SEQ_STRIP_OFSBOTTOM, seq->enddisp, seq->machine + SEQ_STRIP_OFSTOP);
1565                 glDisable(GL_BLEND);
1566         }
1567 }
1568
1569 static void seq_draw_sfra_efra(Scene *scene, View2D *v2d)
1570 {
1571         const Editing *ed = BKE_sequencer_editing_get(scene, false);
1572         const int frame_sta = PSFRA;
1573         const int frame_end = PEFRA + 1;
1574
1575         glEnable(GL_BLEND);
1576         
1577         /* draw darkened area outside of active timeline 
1578          * frame range used is preview range or scene range */
1579         UI_ThemeColorShadeAlpha(TH_BACK, -25, -100);
1580
1581         if (frame_sta < frame_end) {
1582                 glRectf(v2d->cur.xmin, v2d->cur.ymin, (float)frame_sta, v2d->cur.ymax);
1583                 glRectf((float)frame_end, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
1584         }
1585         else {
1586                 glRectf(v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
1587         }
1588
1589         UI_ThemeColorShade(TH_BACK, -60);
1590         /* thin lines where the actual frames are */
1591         fdrawline(frame_sta, v2d->cur.ymin, frame_sta, v2d->cur.ymax);
1592         fdrawline(frame_end, v2d->cur.ymin, frame_end, v2d->cur.ymax);
1593
1594         if (ed && !BLI_listbase_is_empty(&ed->metastack)) {
1595                 MetaStack *ms = ed->metastack.last;
1596
1597                 glColor4ub(255, 255, 255, 8);
1598                 glRectf(ms->disp_range[0], v2d->cur.ymin, ms->disp_range[1], v2d->cur.ymax);
1599
1600                 UI_ThemeColorShade(TH_BACK, -40);
1601
1602                 fdrawline(ms->disp_range[0], v2d->cur.ymin, ms->disp_range[0], v2d->cur.ymax);
1603                 fdrawline(ms->disp_range[1], v2d->cur.ymin, ms->disp_range[1], v2d->cur.ymax);
1604         }
1605
1606         glDisable(GL_BLEND);
1607 }
1608
1609 /* Draw Timeline/Strip Editor Mode for Sequencer */
1610 void draw_timeline_seq(const bContext *C, ARegion *ar)
1611 {
1612         Scene *scene = CTX_data_scene(C);
1613         Editing *ed = BKE_sequencer_editing_get(scene, false);
1614         SpaceSeq *sseq = CTX_wm_space_seq(C);
1615         View2D *v2d = &ar->v2d;
1616         View2DScrollers *scrollers;
1617         short unit = 0, flag = 0;
1618         float col[3];
1619         
1620         /* clear and setup matrix */
1621         UI_GetThemeColor3fv(TH_BACK, col);
1622         if (ed && ed->metastack.first) 
1623                 glClearColor(col[0], col[1], col[2] - 0.1f, 0.0f);
1624         else 
1625                 glClearColor(col[0], col[1], col[2], 0.0f);
1626         glClear(GL_COLOR_BUFFER_BIT);
1627
1628         UI_view2d_view_ortho(v2d);
1629         
1630         
1631         /* calculate extents of sequencer strips/data 
1632          * NOTE: needed for the scrollers later
1633          */
1634         boundbox_seq(scene, &v2d->tot);
1635         
1636         
1637         /* draw backdrop */
1638         draw_seq_backdrop(v2d);
1639         
1640         /* regular grid-pattern over the rest of the view (i.e. 1-second grid lines) */
1641         UI_view2d_constant_grid_draw(v2d, FPS);
1642
1643         /* Only draw backdrop in pure sequence view. */
1644         if (sseq->view == SEQ_VIEW_SEQUENCE && sseq->draw_flag & SEQ_DRAW_BACKDROP) {
1645                 draw_image_seq(C, scene, ar, sseq, scene->r.cfra, 0, false, true);
1646                 UI_view2d_view_ortho(v2d);
1647         }
1648                 
1649         ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
1650         
1651         seq_draw_sfra_efra(scene, v2d);
1652
1653         /* sequence strips (if there is data available to be drawn) */
1654         if (ed) {
1655                 /* draw the data */
1656                 draw_seq_strips(C, ed, ar);
1657                 
1658                 /* text draw cached (for sequence names), in pixelspace now */
1659                 UI_view2d_text_cache_draw(ar);
1660         }
1661         
1662         /* current frame */
1663         UI_view2d_view_ortho(v2d);
1664         if ((sseq->flag & SEQ_DRAWFRAMES) == 0)      flag |= DRAWCFRA_UNIT_SECONDS;
1665         if ((sseq->flag & SEQ_NO_DRAW_CFRANUM) == 0) flag |= DRAWCFRA_SHOW_NUMBOX;
1666         ANIM_draw_cfra(C, v2d, flag);
1667         
1668         /* markers */
1669         UI_view2d_view_orthoSpecial(ar, v2d, 1);
1670         ED_markers_draw(C, DRAW_MARKERS_LINES | DRAW_MARKERS_MARGIN);
1671         
1672         /* preview range */
1673         UI_view2d_view_ortho(v2d);
1674         ANIM_draw_previewrange(C, v2d, 1);
1675
1676         /* overlap playhead */
1677         if (scene->ed && scene->ed->over_flag & SEQ_EDIT_OVERLAY_SHOW) {
1678                 int cfra_over = (scene->ed->over_flag & SEQ_EDIT_OVERLAY_ABS) ? scene->ed->over_cfra : scene->r.cfra + scene->ed->over_ofs;
1679                 glColor3f(0.2, 0.2, 0.2);
1680                 // glRectf(cfra_over, v2d->cur.ymin, scene->ed->over_ofs + scene->r.cfra + 1, v2d->cur.ymax);
1681
1682                 glBegin(GL_LINES);
1683                 glVertex2f(cfra_over, v2d->cur.ymin);
1684                 glVertex2f(cfra_over, v2d->cur.ymax);
1685                 glEnd();
1686
1687         }
1688         
1689         /* callback */
1690         ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
1691
1692         /* reset view matrix */
1693         UI_view2d_view_restore(C);
1694
1695         /* scrollers */
1696         unit = (sseq->flag & SEQ_DRAWFRAMES) ? V2D_UNIT_FRAMES : V2D_UNIT_SECONDS;
1697         scrollers = UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_UNIT_VALUES, V2D_GRID_CLAMP);
1698         UI_view2d_scrollers_draw(C, v2d, scrollers);
1699         UI_view2d_scrollers_free(scrollers);
1700 }
1701
1702