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