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