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