Blender V5.3
sequencer_preview_draw.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10#include <cmath>
11#include <cstring>
12
13#include "BLF_api.hh"
14
15#include "BLI_index_range.hh"
16#include "BLI_math_matrix.hh"
20#include "BLI_rect.hh"
21#include "BLI_utildefines.hh"
22#include "BLI_vector.hh"
23
24#include "DNA_scene_types.h"
25#include "DNA_screen_types.h"
26#include "DNA_sequence_types.h"
27#include "DNA_space_types.h"
28#include "DNA_view2d_types.h"
29
30#include "BKE_context.hh"
31#include "BKE_global.hh"
32#include "BKE_scene.hh"
33#include "BKE_screen.hh"
34
36#include "IMB_imbuf.hh"
37#include "IMB_imbuf_types.hh"
38
39#include "OCIO_scope.hh"
40
41#include "PRF_profile.hh"
42
43#include "GPU_compute.hh"
44#include "GPU_debug.hh"
45#include "GPU_framebuffer.hh"
46#include "GPU_immediate.hh"
47#include "GPU_immediate_util.hh"
48#include "GPU_matrix.hh"
49#include "GPU_primitive.hh"
50#include "GPU_shader_shared.hh"
51#include "GPU_state.hh"
52#include "GPU_viewport.hh"
53
54#include "ED_gpencil_legacy.hh"
55#include "ED_screen.hh"
56#include "ED_sequencer.hh"
57#include "ED_space_api.hh"
58#include "ED_time_scrub_ui.hh"
59#include "ED_util.hh"
60#include "ED_view3d.hh"
61
62#include "SEQ_channels.hh"
63#include "SEQ_effects.hh"
64#include "SEQ_iterator.hh"
65#include "SEQ_prefetch.hh"
66#include "SEQ_preview_cache.hh"
67#include "SEQ_proxy.hh"
68#include "SEQ_render.hh"
69#include "SEQ_select.hh"
70#include "SEQ_sequencer.hh"
71#include "SEQ_transform.hh"
72
73#include "UI_interface.hh"
74#include "UI_resources.hh"
75#include "UI_view2d.hh"
76
77#include "WM_api.hh"
78#include "WM_types.hh"
79
80#include "sequencer_intern.hh"
82#include "sequencer_scopes.hh"
83
84namespace blender::ed::vse {
85static Strip *special_seq_update = nullptr;
86
88{
89 special_seq_update = strip;
90}
91
96
97void special_preview_set(bContext *C, const int mval[2])
98{
100 if (!seq::editing_get(scene)) {
101 return;
102 }
103
104 ARegion *region = CTX_wm_region(C);
105 Strip *strip = strip_under_mouse_get(scene, &region->v2d, mval);
106 if (strip != nullptr && strip->type != STRIP_TYPE_SOUND) {
108 }
109}
110
115
116ImBuf *sequencer_ibuf_get(const bContext *C, const int timeline_frame, const char *viewname)
117{
118 Main *bmain = CTX_data_main(C);
119 ARegion *region = CTX_wm_region(C);
120 Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C);
122 SpaceSeq *sseq = CTX_wm_space_seq(C);
123 bScreen *screen = CTX_wm_screen(C);
124
125 seq::RenderData context = {nullptr};
126 ImBuf *ibuf;
127 short is_break = G.is_break;
129 sseq->render_size);
130 if (render_size_mode == SEQ_RENDER_SIZE_NONE) {
131 return nullptr;
132 }
133
134 const float render_scale = seq::get_render_scale_factor(render_size_mode, scene->r.size);
135 int rectx = roundf(render_scale * scene->r.xsch);
136 int recty = roundf(render_scale * scene->r.ysch);
137
139 bmain, depsgraph, scene, rectx, recty, render_size_mode, nullptr, &context);
140 context.view_id = BKE_scene_multiview_view_id_get(&scene->r, viewname);
141 context.use_proxies = (sseq->flag & SEQ_USE_PROXIES) != 0;
142 context.is_playing = screen->animtimer != nullptr;
143 context.is_scrubbing = screen->scrubbing;
144
145 /* Sequencer could start rendering, in this case we need to be sure it wouldn't be
146 * canceled by Escape pressed somewhere in the past. */
147 G.is_break = false;
148
151 if (viewport) {
152 /* Unbind viewport to release the DRW context. */
153 GPU_viewport_unbind(viewport);
154 }
155 else {
156 /* Rendering can change OGL context. Save & Restore frame-buffer. */
158 }
159
160 if (special_preview_get()) {
161 ibuf = seq::render_give_ibuf_direct(&context, timeline_frame, special_preview_get());
162 }
163 else {
164 ibuf = seq::render_give_ibuf(&context, timeline_frame, sseq->chanshown);
165 }
166
167 if (viewport) {
168 /* Follows same logic as wm_draw_window_offscreen to make sure to restore the same
169 * viewport. */
170 int view = (sseq->multiview_eye == STEREO_RIGHT_ID) ? 1 : 0;
171 GPU_viewport_bind(viewport, view, &region->winrct);
172 }
173 else if (fb) {
175 }
176
177 /* Restore state so real rendering would be canceled if needed. */
178 G.is_break = is_break;
179
180 return ibuf;
181}
182
183static void sequencer_display_size(const RenderData &render_data, float r_viewrect[2])
184{
185 r_viewrect[0] = float(render_data.xsch);
186 r_viewrect[1] = float(render_data.ysch);
187
188 r_viewrect[0] *= render_data.xasp / render_data.yasp;
189}
190
192{
193 /* Draw grease-pencil (image aligned). */
195
196 /* Orthographic at pixel level. */
198
199 /* Draw grease-pencil (screen aligned). */
201}
202
207 const View2D &v2d,
208 const Scene *scene)
209{
210 const float x1 = v2d.tot.xmin;
211 const float y1 = v2d.tot.ymin;
212 const float x2 = v2d.tot.xmax;
213 const float y2 = v2d.tot.ymax;
214
215 GPU_line_width(1.0f);
216
217 /* Draw border. */
218 const uint shdr_pos = GPU_vertformat_attr_add(
219 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
220
222
223 float viewport_size[4];
224 GPU_viewport_size_get_f(viewport_size);
225 immUniform2f("viewport_size", viewport_size[2] / UI_SCALE_FAC, viewport_size[3] / UI_SCALE_FAC);
226
228 immUniform1i("colors_len", 0); /* Simple dashes. */
229 immUniform1f("dash_width", 6.0f);
230 immUniform1f("udash_factor", 0.5f);
231
232 imm_draw_box_wire_2d(shdr_pos, x1 - 0.5f, y1 - 0.5f, x2 + 0.5f, y2 + 0.5f);
233
234 rctf rect;
235 rect.xmin = x1;
236 rect.xmax = x2;
237 rect.ymin = y1;
238 rect.ymax = y2;
239
240 /* Draw safety border. */
243 ui::draw_safe_areas(shdr_pos, &rect, scene->safe_areas.title, scene->safe_areas.action);
244
247 shdr_pos, &rect, scene->safe_areas.title_center, scene->safe_areas.action_center);
248 }
249 }
250
251 /* Draw composition guides. */
255 &rect,
257 }
258
260}
261
262#if 0
263void sequencer_draw_maskedit(const bContext *C, Scene *scene, ARegion *region, SpaceSeq *sseq)
264{
265 /* NOTE: sequencer mask editing isn't finished, the draw code is working but editing not.
266 * For now just disable drawing since the strip frame will likely be offset. */
267
268 // if (sc->mode == SC_MODE_MASKEDIT)
269 if (0 && sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
270 Mask *mask = SEQ_active_mask_get(scene);
271
272 if (mask) {
273 int width, height;
274 float aspx = 1.0f, aspy = 1.0f;
275 // ED_mask_get_size(C, &width, &height);
276
277 // Scene *scene = CTX_data_sequencer_scene(C);
278 BKE_render_resolution(&scene->r, false, &width, &height);
279
281 region,
282 true,
283 0,
284 0,
285 0, /* TODO */
286 width,
287 height,
288 aspx,
289 aspy,
290 false,
291 true,
292 nullptr,
293 C);
294 }
295 }
296}
297#endif
298
299/* Force redraw, when prefetching and using cache view. */
300static void seq_prefetch_wm_notify(const bContext *C, Scene *scene)
301{
302 if (seq::prefetch_need_redraw(C, scene)) {
304 }
305}
306
307static void sequencer_stop_running_jobs(const bContext *C, Scene *scene)
308{
309 if (G.is_rendering == false && (scene->r.seq_prev_type) == OB_RENDER) {
310 /* Stop all running jobs, except screen one. Currently previews frustrate Render.
311 * Need to make so sequencers rendering doesn't conflict with compositor. */
313
314 /* In case of final rendering used for preview, kill all previews,
315 * otherwise threading conflict will happen in rendering module. */
317 }
318}
319
324
325/* Semantic utility to get a rectangle with positions that correspond to a full frame drawn in the
326 * preview region. */
328{
329 return region.v2d.tot;
330}
331
332/* Semantic utility to generate rectangle with UV coordinates that cover an entire 0 .. 1
333 * rectangle. */
335{
336 rctf texture_coord;
337 BLI_rctf_init(&texture_coord, 0.0f, 1.0f, 0.0f, 1.0f);
338 return texture_coord;
339}
340
341/* Get rectangle positions within preview region that are to be used to draw reference frame.
342 *
343 * If the frame overlay is set to RECTANGLE this function returns coordinates of the rectangle
344 * where partial reference frame is to be drawn.
345 *
346 * If the frame overlay is set to REFERENCE this function returns full-frame rectangle, same as
347 * preview_get_full_position().
348 *
349 * If the frame overlay is set to REFERENCE or is disabled the return value is valid but
350 * corresponds to an undefined state.
351 */
352static rctf preview_get_reference_position(const SpaceSeq &space_sequencer,
353 const Editing &editing,
354 const ARegion &region)
355{
356 const View2D &v2d = region.v2d;
357
358 BLI_assert(ELEM(space_sequencer.overlay_frame_type,
361
362 if (space_sequencer.overlay_frame_type == SEQ_OVERLAY_FRAME_TYPE_RECT) {
364 const float xmin = v2d.tot.xmin;
365 const float ymin = v2d.tot.ymin;
366
367 const float width = BLI_rctf_size_x(&v2d.tot);
368 const float height = BLI_rctf_size_y(&v2d.tot);
369
370 position.xmax = xmin + width * editing.overlay_frame_rect.xmax;
371 position.xmin = xmin + width * editing.overlay_frame_rect.xmin;
372 position.ymax = ymin + height * editing.overlay_frame_rect.ymax;
373 position.ymin = ymin + height * editing.overlay_frame_rect.ymin;
374
375 return position;
376 }
377
378 return v2d.tot;
379}
380
381/* Return rectangle with UV coordinates that are to be used to draw reference frame.
382 *
383 * If the frame overlay is set to rectangle the return value contains vUV coordinates of the
384 * rectangle within the reference frame.
385 *
386 * If the frame overlay is set to REFERENCE this function returns full-frame UV rectangle, same as
387 * preview_get_full_texture_coord().
388 *
389 * If the frame overlay is set to REFERENCE or is disabled the return value is valid but
390 * corresponds to an undefined state.
391 */
393 const Editing &editing)
394{
395 if (space_sequencer.overlay_frame_type == SEQ_OVERLAY_FRAME_TYPE_RECT) {
396 return editing.overlay_frame_rect;
397 }
398
399 rctf texture_coord;
400 BLI_rctf_init(&texture_coord, 0.0f, 1.0f, 0.0f, 1.0f);
401
402 return texture_coord;
403}
404
405static void draw_histogram(ARegion &region,
406 const ScopeHistogram &hist,
407 SeqQuadsBatch &quads,
408 const rctf &area,
409 const ColorManagedViewSettings *view_settings,
410 const ColorManagedDisplaySettings *display_settings)
411{
412 if (hist.data.is_empty()) {
413 return;
414 }
415
416 const ocio::ScopeInfo scope_info = IMB_colormanagement_get_scope_info(display_settings,
417 view_settings);
418
419 /* Grid lines from scope info graticules, with labels centered on each line. */
420 const uchar col_grid[4] = {128, 128, 128, 128};
421 const float w = area.xmax - area.xmin;
422
423 /* Ensure font matches what view2d_text_cache_draw will use, so that text
424 * measurements are accurate. */
425 const int font_id = BLF_set_default();
426 float text_scale_x, text_scale_y;
427 ui::view2d_pixel_size_get(&region.v2d, &text_scale_x, &text_scale_y);
428
429 float prev_label_right = -FLT_MAX;
430
431 for (const ocio::ScopeGraticule &graticule : scope_info.graticules) {
432 const float x = area.xmin + w * graticule.value;
433 const size_t buf_len = strlen(graticule.label);
434 float text_width, text_height;
435 BLF_width_and_height(font_id, graticule.label, buf_len, &text_width, &text_height);
436 text_width *= text_scale_x;
437 text_height *= text_scale_y;
438 const float gap = text_height * 1.5f;
439
440 const float label_left = x - text_width * 0.5f;
441 const bool show_label = label_left > prev_label_right;
442
443 quads.add_line(x, area.ymin, x, show_label ? area.ymax - gap : area.ymax, col_grid);
444 if (show_label) {
446 label_left,
447 area.ymax - gap * 0.5f - text_height * 0.5f,
448 graticule.label,
449 buf_len,
450 col_grid);
451 prev_label_right = x + text_width * 0.5f + text_height;
452 }
453 }
454
455 /* Border. */
456 const uchar col_border[4] = {64, 64, 64, 128};
457 quads.add_wire_quad(area.xmin, area.ymin, area.xmax, area.ymax, col_border);
458
459 /* Histogram area for each R/G/B channels, additively blended. */
460 quads.draw();
462 for (int ch = 0; ch < 3; ++ch) {
463 if (hist.max_value[ch] == 0) {
464 continue;
465 }
466 uchar col_line[4] = {32, 32, 32, 255};
467 uchar col_area[4] = {64, 64, 64, 128};
468 col_line[ch] = 224;
469 col_area[ch] = 224;
470 const float y_scale = (area.ymax - area.ymin) / hist.max_value[ch] * 0.95f;
471 const float yb = area.ymin;
472 for (int bin = 0; bin < ScopeHistogram::NUM_BINS; bin++) {
473 const uint bin_val = hist.data[bin][ch];
474 if (bin_val == 0) {
475 continue;
476 }
477 const float f0 = ScopeHistogram::bin_to_float(bin);
478 const float f1 = ScopeHistogram::bin_to_float(bin + 1);
479 const float x0 = area.xmin + f0 * w;
480 const float x1 = area.xmin + f1 * w;
481
482 const float y = area.ymin + bin_val * y_scale;
483 quads.add_quad(x0, yb, x0, y, x1, yb, x1, y, col_area);
484 quads.add_line(x0, y, x1, y, col_line);
485 }
486 }
487 quads.draw();
489
491}
492
493static float2 rgb_to_cbcr(const float3x3 &yuv_matrix, const float3 &rgb)
494{
495 const float3 yuv = yuv_matrix * rgb;
496 return float2(yuv.y, yuv.z);
497}
498
500 SeqQuadsBatch &quads,
501 const rctf &area,
502 const ColorManagedViewSettings *view_settings,
503 const ColorManagedDisplaySettings *display_settings)
504{
505 const ocio::ScopeInfo scope_info = IMB_colormanagement_get_scope_info(display_settings,
506 view_settings);
507
508 const uchar col_grid[4] = {128, 128, 128, 128};
509 const float x0 = area.xmin;
510 const float x1 = area.xmax;
511 const float h = area.ymax - area.ymin;
512
513 const int font_id = BLF_set_default();
514 float text_scale_x, text_scale_y;
515 ui::view2d_pixel_size_get(&region->v2d, &text_scale_x, &text_scale_y);
516
517 float prev_label_top = -FLT_MAX;
518
519 for (const ocio::ScopeGraticule &graticule : scope_info.graticules) {
520 const float y = area.ymin + h * graticule.value;
521 const size_t buf_len = strlen(graticule.label);
522 float text_width_px, text_height_px;
523 BLF_width_and_height(font_id, graticule.label, buf_len, &text_width_px, &text_height_px);
524 const float text_width = text_width_px * text_scale_x;
525 const float text_height = text_height_px * text_scale_y;
526 const float pad_x = text_height_px * text_scale_x;
527 const float gap = text_width + pad_x;
528
529 const float label_bottom = y - text_height * 0.5f;
530 const bool show_label = label_bottom > prev_label_top;
531
532 quads.add_line(x0 + gap, y, x1, y, col_grid);
533 if (show_label) {
535 x0 + (gap - text_width) * 0.5f,
536 y - text_height * 0.5f,
537 graticule.label,
538 buf_len,
539 col_grid);
540 prev_label_top = y + text_height * 0.5f + text_height;
541 }
542 }
543
544 quads.draw();
546}
547
549 SeqQuadsBatch &quads,
550 const rctf &area,
551 const ocio::ScopeInfo &scope_info)
552{
553 const float skin_rad = DEG2RADF(123.0f); /* angle in radians of the skin tone line */
554
555 const float w = BLI_rctf_size_x(&area);
556 const float h = BLI_rctf_size_y(&area);
557 const float2 center{BLI_rctf_cent_x(&area), BLI_rctf_cent_y(&area)};
558 const float radius = ((w < h) ? w : h) * 0.5f;
559
560 const float3x3 &yuv_matrix = scope_info.yuv_matrix;
561 const float3x3 inv_yuv_to_rec709 = scope_info.scope_gamut_to_rec709 * math::invert(yuv_matrix);
562
563 /* Precalculate circle points/colors. */
564 constexpr int circle_delta = 6;
565 constexpr int num_circle_points = 360 / circle_delta;
566 float2 circle_pos[num_circle_points];
567 float3 circle_col[num_circle_points];
568 for (int i = 0; i < num_circle_points; i++) {
569 float a = DEG2RADF(i * circle_delta);
570 float x = cosf(a);
571 float y = sinf(a);
572 circle_pos[i] = float2(x, y);
573
574 float3 yuv = float3(0.5f, x, y);
575 float3 col = inv_yuv_to_rec709 * yuv;
576 circle_col[i] = col;
577 }
578
579 /* Draw colored background and outer ring, additively blended
580 * since vectorscope image is already drawn. */
582
583 constexpr float alpha_f = 0.8f;
584 constexpr uchar alpha_b = uchar(alpha_f * 255.0f);
585 const uchar4 col_center(50, 50, 50, alpha_b);
586
587 uchar4 col1(0, 0, 0, alpha_b);
588 uchar4 col2(0, 0, 0, alpha_b);
589 uchar4 col3(0, 0, 0, alpha_b);
590
591 /* Background: since the quads batch utility draws quads, draw two
592 * segments of the circle (two triangles) in one iteration. */
593 constexpr float mul_background = 0.2f;
594 for (int i = 0; i < num_circle_points; i += 2) {
595 int idx1 = i;
596 int idx2 = (i + 1) % num_circle_points;
597 int idx3 = (i + 2) % num_circle_points;
598 float2 pt1 = center + circle_pos[idx1] * radius;
599 float2 pt2 = center + circle_pos[idx2] * radius;
600 float2 pt3 = center + circle_pos[idx3] * radius;
601 float3 rgb1 = circle_col[idx1] * mul_background;
602 float3 rgb2 = circle_col[idx2] * mul_background;
603 float3 rgb3 = circle_col[idx3] * mul_background;
604 rgb_float_to_uchar(col1, rgb1);
605 rgb_float_to_uchar(col2, rgb2);
606 rgb_float_to_uchar(col3, rgb3);
607 quads.add_quad(pt1.x,
608 pt1.y,
609 pt2.x,
610 pt2.y,
611 center.x,
612 center.y,
613 pt3.x,
614 pt3.y,
615 col1,
616 col2,
617 col_center,
618 col3);
619 }
620
621 /* Outer ring. */
622 const float outer_radius = radius * 1.02f;
623 for (int i = 0; i < num_circle_points; i++) {
624 int idx1 = i;
625 int idx2 = (i + 1) % num_circle_points;
626 float2 pt1a = center + circle_pos[idx1] * radius;
627 float2 pt2a = center + circle_pos[idx2] * radius;
628 float2 pt1b = center + circle_pos[idx1] * outer_radius;
629 float2 pt2b = center + circle_pos[idx2] * outer_radius;
630 float3 rgb1 = circle_col[idx1];
631 float3 rgb2 = circle_col[idx2];
632 rgb_float_to_uchar(col1, rgb1);
633 rgb_float_to_uchar(col2, rgb2);
634 quads.add_quad(
635 pt1a.x, pt1a.y, pt1b.x, pt1b.y, pt2a.x, pt2a.y, pt2b.x, pt2b.y, col1, col1, col2, col2);
636 }
637
638 quads.draw();
639
640 /* Draw grid and other labels using regular alpha blending. */
642 const uchar4 col_grid(128, 128, 128, 128);
643
644 /* Cross. */
645 quads.add_line(center.x - radius, center.y, center.x + radius, center.y, col_grid);
646 quads.add_line(center.x, center.y - radius, center.x, center.y + radius, col_grid);
647
648 /* Inner circles. */
649 for (int j = 1; j < 5; j++) {
650 float r = radius * j * 0.2f;
651 for (int i = 0; i < num_circle_points; i++) {
652 int idx1 = i;
653 int idx2 = (i + 1) % num_circle_points;
654 float2 pt1 = center + circle_pos[idx1] * r;
655 float2 pt2 = center + circle_pos[idx2] * r;
656 quads.add_line(pt1.x, pt1.y, pt2.x, pt2.y, col_grid);
657 }
658 }
659
660 /* "Safe" (0.75 saturation) primary color locations and labels. */
661 const float3 primaries[6] = {
662 {1, 0, 0},
663 {1, 1, 0},
664 {0, 1, 0},
665 {0, 1, 1},
666 {0, 0, 1},
667 {1, 0, 1},
668 };
669 const char *names = "RYGCBM";
670
671 /* Calculate size of single text letter. */
672 char buf[2] = {'M', 0};
673 float text_scale_x, text_scale_y;
674 ui::view2d_pixel_size_get(&region->v2d, &text_scale_x, &text_scale_y);
675 float text_width, text_height;
676 BLF_width_and_height(BLF_default(), buf, 1, &text_width, &text_height);
677 text_width *= text_scale_x;
678 text_height *= text_scale_y;
679
680 const uchar4 col_target(128, 128, 128, 192);
681 const float delta = radius * 0.01f;
682 for (int i = 0; i < 6; i++) {
683 float3 safe = primaries[i] * 0.75f;
684 float2 pos = center + rgb_to_cbcr(yuv_matrix, safe) * (radius * 2);
685 quads.add_wire_quad(pos.x - delta, pos.y - delta, pos.x + delta, pos.y + delta, col_target);
686
687 buf[0] = names[i];
689 pos.x + delta * 1.2f + text_width / 4,
690 pos.y - text_height / 2,
691 buf,
692 1,
693 col_target);
694 }
695
696 /* Skin tone line. */
697 const uchar4 col_tone(255, 102, 0, 128);
698 quads.add_line(center.x,
699 center.y,
700 center.x + cosf(skin_rad) * radius,
701 center.y + sinf(skin_rad) * radius,
702 col_tone);
703
704 quads.draw();
706}
707
709{
710 switch (type) {
712 return "VSE Vectorscope";
714 return "VSE Waveform";
716 return "VSE Parade";
718 return "VSE Histogram";
720 return "VSE Overexposed";
721 default:
722 return "VSE Scope";
723 }
724}
725
726static void sequencer_draw_scopes(Scene *scene,
727 const SpaceSeq &space_sequencer,
728 const ColorManagedViewSettings &view_settings,
729 const ColorManagedDisplaySettings &display_settings,
730 ARegion &region,
731 int timeline_frame,
732 int image_width,
733 int image_height,
734 bool premultiplied)
735{
737
738 /* Get display-space texture for scope values (positions, histogram bins).
739 * Falls back to the raw input texture if no color management is needed. */
741 scene, timeline_frame, space_sequencer.multiview_eye, 0, image_width, image_height);
742 if (scope_texture == nullptr) {
743 scope_texture = seq::preview_cache_get_gpu_texture(scene,
744 timeline_frame,
745 space_sequencer.multiview_eye,
746 space_sequencer.chanshown,
747 image_width,
748 image_height);
749 }
750
751 SeqQuadsBatch quads;
752 const SeqScopes *scopes = &space_sequencer.runtime->scopes;
753
754 bool use_blend = (space_sequencer.mainb == SEQ_DRAW_IMG_IMBUF &&
755 space_sequencer.flag & SEQ_USE_ALPHA) ||
756 (space_sequencer.mainb != SEQ_DRAW_IMG_IMBUF);
757
758 const rctf preview = preview_get_full_position(region);
759
760 /* Draw black rectangle over scopes area. */
761 if (space_sequencer.mainb != SEQ_DRAW_IMG_IMBUF) {
763 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
764 uchar black[4] = {0, 0, 0, 255};
766 immUniformColor4ubv(black);
767 immRectf(pos, preview.xmin, preview.ymin, preview.xmax, preview.ymax);
769 }
770
771 if (use_blend) {
773 }
774
775 if (scope_texture) {
776 if (space_sequencer.mainb == SEQ_DRAW_IMG_IMBUF) {
777 /* Draw overexposed overlay. */
779 GPUVertFormat *imm_format = immVertexFormat();
780 const uint pos = GPU_vertformat_attr_add(imm_format, "pos", gpu::VertAttrType::SFLOAT_32_32);
781 const uint tex_coord = GPU_vertformat_attr_add(
782 imm_format, "texCoord", gpu::VertAttrType::SFLOAT_32_32);
783
785 immUniform1i("img_premultiplied", premultiplied ? 1 : 0);
786 immUniform1f("zebra_limit", space_sequencer.zebra / 100.0f);
787
788 GPU_texture_bind(scope_texture, 0);
789 rctf uv;
790 BLI_rctf_init(&uv, 0.0f, 1.0f, 0.0f, 1.0f);
791 immRectf_with_texco(pos, tex_coord, preview, uv);
792 GPU_texture_unbind(scope_texture);
794 }
795 else if (space_sequencer.mainb != SEQ_DRAW_IMG_HISTOGRAM) {
796 /* Draw point-based scopes using a compute shader based rasterizer (using
797 * regular GPU pipeline to draw many points, where thousands of them can
798 * hit the same pixels, is very inefficient, especially on tile-based GPUs).
799 *
800 * Compute shader rasterizer does atomic adds of fixed point colors into
801 * a screen size buffer, then a fragment shader resolve pass outputs the
802 * final colors. */
803 const float point_size = (BLI_rcti_size_x(&region.v2d.mask) + 1) /
804 BLI_rctf_size_x(&region.v2d.cur);
805
806 const ocio::ScopeInfo scope_info = IMB_colormanagement_get_scope_info(&display_settings,
807 &view_settings);
808
809 int viewport_size_i[4];
810 GPU_viewport_size_get_i(viewport_size_i);
811 const int2 viewport_size = int2(viewport_size_i[2], viewport_size_i[3]);
812 const int2 image_size = int2(image_width, image_height);
814 space_sequencer.render_size);
815 const float render_scale = seq::get_render_scale_factor(render_size_mode, scene->r.size);
816
817 gpu::StorageBuf *raster_ssbo = GPU_storagebuf_create_ex(viewport_size.x * viewport_size.y *
818 sizeof(SeqScopeRasterData),
819 nullptr,
821 "Scopes Raster");
822 GPU_storagebuf_clear_to_zero(raster_ssbo);
823 /* Compute shader rasterization. */
824 {
828
829 const int raster_ssbo_location = GPU_shader_get_ssbo_binding(shader, "raster_buf");
830 GPU_storagebuf_bind(raster_ssbo, raster_ssbo_location);
831 const int image_location = GPU_shader_get_sampler_binding(shader, "image");
832 GPU_texture_bind(scope_texture, image_location);
833
834 GPU_shader_uniform_1i(shader, "view_width", viewport_size.x);
835 GPU_shader_uniform_1i(shader, "view_height", viewport_size.y);
836 GPU_shader_uniform_3fv(shader, "scope_luma_coeffs", scope_info.luma_coefficients);
838 shader, "scope_gamut_to_rec709", scope_info.scope_gamut_to_rec709.ptr());
839 GPU_shader_uniform_mat3(shader, "scope_yuv_matrix", scope_info.yuv_matrix.ptr());
840 GPU_shader_uniform_1b(shader, "scope_is_hdr", scope_info.is_hdr);
841 GPU_shader_uniform_1f(shader, "scope_point_size", point_size);
842 GPU_shader_uniform_1b(shader, "img_premultiplied", premultiplied);
843 GPU_shader_uniform_1i(shader, "image_width", image_width);
844 GPU_shader_uniform_1i(shader, "image_height", image_height);
845 GPU_shader_uniform_1i(shader, "scope_mode", space_sequencer.mainb);
846 GPU_shader_uniform_1f(shader, "inv_render_scale", 1.0f / render_scale);
847
848 const int2 groups_to_dispatch = math::divide_ceil(image_size, int2(16));
849 GPU_compute_dispatch(shader, groups_to_dispatch.x, groups_to_dispatch.y, 1);
850
852 GPU_storagebuf_unbind(raster_ssbo);
853 /* Make computed results consistently visible in the following resolve pass. */
855 }
856
857 /* Resolve pass. */
858 {
859 if (use_blend) {
861 }
862
863 /* Depending on resolution of the image, different amounts of pixels are expected
864 * to hit the same locations of the scope. Adjust the scope transparency mapping
865 * exponent so that the scope has decent visibility without saturating or being too dark:
866 * 0.07 at height=2160 (4K) and up, 0.5 at height=360 and below, and interpolating between
867 * those. */
868 float alpha = math::clamp(ratiof(360.0f, 2160.0f, image_height), 0.0f, 1.0f);
869 float exponent = math::interpolate(0.5f, 0.07f, alpha);
870
873
874 const int raster_ssbo_location = GPU_shader_get_ssbo_binding(shader, "raster_buf");
875 GPU_storagebuf_bind(raster_ssbo, raster_ssbo_location);
876
877 gpu::Batch *batch = GPU_batch_create_procedural(GPU_PRIM_TRIS, 3);
878
880 GPU_batch_uniform_1i(batch, "view_width", viewport_size.x);
881 GPU_batch_uniform_1i(batch, "view_height", viewport_size.y);
882 GPU_batch_uniform_1f(batch, "alpha_exponent", exponent);
883 GPU_batch_draw(batch);
884
885 GPU_batch_discard(batch);
886 GPU_storagebuf_unbind(raster_ssbo);
887 }
888
889 GPU_storagebuf_free(raster_ssbo);
890 }
891 }
892
893 /* Draw scope graticules. */
894 if (use_blend) {
896 }
897
898 if (space_sequencer.mainb == SEQ_DRAW_IMG_HISTOGRAM) {
899 draw_histogram(region,
900 scopes->histogram,
901 quads,
902 preview,
903 &scene->view_settings,
904 &scene->display_settings);
905 }
907 use_blend = true;
909 &region, quads, preview, &scene->view_settings, &scene->display_settings);
910 }
911 if (space_sequencer.mainb == SEQ_DRAW_IMG_VECTORSCOPE) {
912 use_blend = true;
913 const ocio::ScopeInfo scope_info = IMB_colormanagement_get_scope_info(&display_settings,
914 &view_settings);
915 draw_vectorscope_graticule(&region, quads, preview, scope_info);
916 }
917
918 quads.draw();
919
920 if (use_blend) {
922 }
924}
925
926static void update_gpu_scopes(const ImBuf *input_ibuf,
927 gpu::Texture *input_texture,
928 const ColorManagedViewSettings &view_settings,
929 const ColorManagedDisplaySettings &display_settings,
930 const SpaceSeq &space_sequencer,
931 Scene *scene,
932 int timeline_frame)
933{
934 PRF_scope_with_name("SeqUpdateGPUScopes", ProfileCategory::Draw);
935 BLI_assert(input_ibuf && input_texture);
936
937 /* Display space GPU texture is already calculated. */
938 const int width = GPU_texture_width(input_texture);
939 const int height = GPU_texture_height(input_texture);
941 scene,
942 timeline_frame,
943 space_sequencer.multiview_eye,
944 space_sequencer.chanshown,
945 width,
946 height);
947 if (scope_texture != nullptr) {
948 return;
949 }
950
951 /* Create GPU texture. */
953 const gpu::TextureFormat format = gpu::TextureFormat::SFLOAT_16_16_16_16;
954 scope_texture = GPU_texture_create_2d(
955 "seq_scope_display_buf", width, height, 1, format, usage, nullptr);
956 if (scope_texture == nullptr) {
957 return;
958 }
959 GPU_texture_filter_mode(scope_texture, false);
960
963 GPU_matrix_ortho_set(0.0f, 1.0f, 0.0f, 1.0f, -1.0, 1.0f);
965
966 gpu::FrameBuffer *fb = nullptr;
969
970 GPUVertFormat *imm_format = immVertexFormat();
971 const uint pos = GPU_vertformat_attr_add(imm_format, "pos", gpu::VertAttrType::SFLOAT_32_32);
972 const uint tex_coord = GPU_vertformat_attr_add(
973 imm_format, "texCoord", gpu::VertAttrType::SFLOAT_32_32);
974
975 const ColorSpace *input_colorspace = input_ibuf->float_data() ?
976 input_ibuf->float_buffer.colorspace :
977 input_ibuf->byte_buffer.colorspace;
978 const bool predivide = input_ibuf->float_data() != nullptr;
980 &display_settings,
981 input_colorspace,
982 0.0f,
983 predivide,
984 false,
986 {
987 GPU_texture_bind(input_texture, 0);
988 const rctf position{0.0f, 1.0f, 0.0f, 1.0f};
989 const rctf texture_coord{0.0f, 1.0f, 0.0f, 1.0f};
990 immRectf_with_texco(pos, tex_coord, position, texture_coord);
991 GPU_texture_unbind(input_texture);
993 }
994
996
999
1001 timeline_frame,
1002 space_sequencer.multiview_eye,
1003 space_sequencer.chanshown,
1004 scope_texture);
1005}
1006
1007static void update_cpu_scopes(const SpaceSeq &space_sequencer,
1008 const ColorManagedViewSettings &view_settings,
1009 const ColorManagedDisplaySettings &display_settings,
1010 const ImBuf &ibuf,
1011 const int timeline_frame)
1012
1013{
1014 SeqScopes &scopes = space_sequencer.runtime->scopes;
1015 if (scopes.last_ibuf == &ibuf && scopes.last_timeline_frame == timeline_frame) {
1016 /* Nothing to do: scopes already calculated for this image/frame. */
1017 return;
1018 }
1019
1020 PRF_scope_with_name("SeqUpdateCPUScopes", ProfileCategory::Draw);
1021
1022 scopes.cleanup();
1023 if (space_sequencer.mainb == SEQ_DRAW_IMG_HISTOGRAM) {
1024 scopes.histogram.calc_from_ibuf(&ibuf, view_settings, display_settings);
1025 }
1026 scopes.last_ibuf = &ibuf;
1027 scopes.last_timeline_frame = timeline_frame;
1028}
1029
1031 Strip *strip,
1032 bool is_active_seq)
1033{
1034
1035 if ((strip->flag & SEQ_SELECT) == 0) {
1036 return;
1037 }
1038
1040 strip);
1041
1042 /* Origin. */
1044 GPUVertFormat *format = immVertexFormat();
1045 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
1047 immUniform1f("outlineWidth", 1.5f);
1048 immUniformColor3f(1.0f, 1.0f, 1.0f);
1049 immUniform4f("outlineColor", 0.0f, 0.0f, 0.0f, 1.0f);
1050 immUniform1f("size", 7.0f * U.pixelsize);
1052 immVertex2f(pos, origin[0], origin[1]);
1053 immEnd();
1056
1057 /* Outline. */
1059 strip);
1060
1061 GPU_line_smooth(true);
1063 GPU_line_width(2);
1065
1066 float col[3];
1067 if (is_active_seq) {
1069 }
1070 else {
1072 }
1073 immUniformColor3fv(col);
1075 immVertex2f(pos, strip_image_quad[0].x, strip_image_quad[0].y);
1076 immVertex2f(pos, strip_image_quad[1].x, strip_image_quad[1].y);
1077 immVertex2f(pos, strip_image_quad[2].x, strip_image_quad[2].y);
1078 immVertex2f(pos, strip_image_quad[3].x, strip_image_quad[3].y);
1079 immEnd();
1081 GPU_line_width(1);
1083 GPU_line_smooth(false);
1084}
1085
1086static void text_selection_draw(const bContext *C, const Strip *strip, uint pos)
1087{
1088 const TextVars *data = static_cast<TextVars *>(strip->effectdata);
1089 const seq::TextVarsRuntime *runtime = data->runtime;
1090 const Scene *scene = CTX_data_sequencer_scene(C);
1091
1092 if (data->selection_start_offset == -1 || strip_text_selection_range_get(data).is_empty()) {
1093 return;
1094 }
1095
1097 const int2 selection_start = strip_text_cursor_offset_to_position(runtime, sel_range.first());
1098 const int2 selection_end = strip_text_cursor_offset_to_position(runtime, sel_range.last());
1099 const int line_start = selection_start.y;
1100 const int line_end = selection_end.y;
1101
1102 for (int line_index = line_start; line_index <= line_end; line_index++) {
1103 const seq::LineInfo line = runtime->lines[line_index];
1104 seq::CharInfo character_start = line.characters.first();
1105 seq::CharInfo character_end = line.characters.last();
1106
1107 if (line_index == selection_start.y) {
1108 character_start = line.characters[selection_start.x];
1109 }
1110 if (line_index == selection_end.y) {
1111 character_end = line.characters[selection_end.x];
1112 }
1113
1114 const float line_y = character_start.position.y + runtime->font_descender;
1115
1116 const float2 view_offs{-scene->r.xsch / 2.0f, -scene->r.ysch / 2.0f};
1117 float3x3 transform_mat = seq::image_transform_matrix_get(scene, strip);
1118 float2 selection_quad[4] = {
1119 {character_start.position.x, line_y},
1120 {character_start.position.x, line_y + runtime->line_height},
1121 {character_end.position.x + character_end.advance_x, line_y + runtime->line_height},
1122 {character_end.position.x + character_end.advance_x, line_y},
1123 };
1124
1127
1128 for (int i : IndexRange(0, 4)) {
1129 selection_quad[i] += view_offs;
1130 selection_quad[i] = math::transform_point(transform_mat, selection_quad[i]);
1131 }
1132 for (int i : {0, 1, 2, 2, 3, 0}) {
1133 immVertex2f(pos, selection_quad[i][0], selection_quad[i][1]);
1134 }
1135
1136 immEnd();
1137 }
1138}
1139
1140static float2 coords_region_view_align(const View2D *v2d, const float2 coords)
1141{
1142 int2 coords_view;
1143 ui::view2d_view_to_region(v2d, coords.x, coords.y, &coords_view.x, &coords_view.y);
1144 coords_view.x = std::round(coords_view.x);
1145 coords_view.y = std::round(coords_view.y);
1146 float2 coords_region_aligned;
1148 v2d, coords_view.x, coords_view.y, &coords_region_aligned.x, &coords_region_aligned.y);
1149 return coords_region_aligned;
1150}
1151
1152static void text_edit_draw_cursor(const bContext *C, const Strip *strip, uint pos)
1153{
1154 const TextVars *data = static_cast<TextVars *>(strip->effectdata);
1155 const seq::TextVarsRuntime *runtime = data->runtime;
1156 const Scene *scene = CTX_data_sequencer_scene(C);
1157
1158 const float2 view_offs{-scene->r.xsch / 2.0f, -scene->r.ysch / 2.0f};
1159 float3x3 transform_mat = seq::image_transform_matrix_get(scene, strip);
1160 const int2 cursor_position = strip_text_cursor_offset_to_position(runtime, data->cursor_offset);
1161 const float cursor_width = 10;
1162 float2 cursor_coords = runtime->lines[cursor_position.y].characters[cursor_position.x].position;
1163 /* Clamp cursor coords to be inside of text boundbox. Compensate for cursor width, but also line
1164 * width hardcoded in shader. */
1165 const float bound_left = float(runtime->text_boundbox.xmin) + U.pixelsize;
1166 const float bound_right = float(runtime->text_boundbox.xmax) - (cursor_width + U.pixelsize);
1167 /* Note: do not use std::clamp since due to math above left can become larger than right. */
1168 cursor_coords.x = std::max(cursor_coords.x, bound_left);
1169 cursor_coords.x = std::min(cursor_coords.x, bound_right);
1170
1171 cursor_coords = coords_region_view_align(ui::view2d_fromcontext(C), cursor_coords);
1172
1173 float2 cursor_quad[4] = {
1174 {cursor_coords.x, cursor_coords.y},
1175 {cursor_coords.x, cursor_coords.y + runtime->line_height},
1176 {cursor_coords.x + cursor_width, cursor_coords.y + runtime->line_height},
1177 {cursor_coords.x + cursor_width, cursor_coords.y},
1178 };
1179 const float2 descender_offs{0.0f, float(runtime->font_descender)};
1180
1183
1184 for (int i : IndexRange(0, 4)) {
1185 cursor_quad[i] += descender_offs + view_offs;
1186 cursor_quad[i] = math::transform_point(transform_mat, cursor_quad[i]);
1187 }
1188 for (int i : {0, 1, 2, 2, 3, 0}) {
1189 immVertex2f(pos, cursor_quad[i][0], cursor_quad[i][1]);
1190 }
1191
1192 immEnd();
1193}
1194
1195static void text_edit_draw(const bContext *C)
1196{
1197 if (!sequencer_text_editing_active_poll(const_cast<bContext *>(C))) {
1198 return;
1199 }
1201 if (!seq::effects_can_render_text(strip)) {
1202 return;
1203 }
1204
1205 GPUVertFormat *format = immVertexFormat();
1206 const uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
1207 GPU_line_smooth(true);
1210
1211 std::scoped_lock runtime_lock(seq::text_runtime_mutex_get());
1212 text_selection_draw(C, strip, pos);
1213 text_edit_draw_cursor(C, strip, pos);
1214
1217 GPU_line_smooth(false);
1218}
1219
1220/* Draw empty preview region.
1221 * The entire region is cleared with the TH_SEQ_PREVIEW color.
1222 *
1223 * Used in cases when there is no editing, or when the display is set to NONE. */
1225{
1227 BLI_assert(viewport);
1228
1230 GPU_framebuffer_bind_no_srgb(overlay_fb);
1231
1233}
1234
1235/* Begin drawing the sequence preview region.
1236 * Initializes the drawing state which is common for color render and overlay drawing.
1237 *
1238 * #preview_draw_end() is to be called after drawing is done. */
1239static void preview_draw_begin(const bContext *C,
1240 const RenderData &render_data,
1241 const ColorManagedViewSettings &view_settings,
1242 const ColorManagedDisplaySettings &display_settings,
1243 ARegion &region,
1244 eSpaceSeq_RegionType preview_type)
1245{
1247
1249 BLI_assert(viewport);
1250
1251 /* Configure color space used by the viewport.
1252 * This also checks for HDR support and enables it for the viewport when found and needed. */
1254 viewport, &view_settings, &display_settings, render_data.dither_intensity);
1255
1257
1258 /* Setup view. */
1259 View2D &v2d = region.v2d;
1260 float viewrect[2];
1261 /* For histogram and wave/parade scopes, allow arbitrary zoom. */
1264 }
1265 else {
1267 }
1268 sequencer_display_size(render_data, viewrect);
1269 ui::view2d_totRect_set(&v2d, roundf(viewrect[0]), roundf(viewrect[1]));
1272}
1273
1279
1280/* Configure current GPU state to draw on the color render frame-buffer of the viewport. */
1282{
1284 BLI_assert(viewport);
1285
1287 GPU_framebuffer_bind(render_fb);
1288
1289 GPU_framebuffer_clear_color(render_fb, double4(0.0));
1290}
1291
1292/* Configure current GPU state to draw on the overlay frame-buffer of the viewport. */
1294{
1296 BLI_assert(viewport);
1297
1299 GPU_framebuffer_bind_no_srgb(overlay_fb);
1300
1302}
1303
1304/* Draw the given texture on the currently bound frame-buffer without any changes to its pixels
1305 * colors.
1306 *
1307 * The position denotes coordinates of a rectangle used to display the texture.
1308 * The texture_coord contains UV coordinates of the input texture which are mapped to the corners
1309 * of the rectangle. */
1311 const rctf &position,
1312 const rctf &texture_coord)
1313{
1314 GPUVertFormat *imm_format = immVertexFormat();
1315 const uint pos = GPU_vertformat_attr_add(imm_format, "pos", gpu::VertAttrType::SFLOAT_32_32);
1316 const uint tex_coord = GPU_vertformat_attr_add(
1317 imm_format, "texCoord", gpu::VertAttrType::SFLOAT_32_32);
1318
1320 immUniformColor3f(1.0f, 1.0f, 1.0f);
1321
1323
1324 immRectf_with_texco(pos, tex_coord, position, texture_coord);
1325
1328}
1329
1330/* Draw the given texture on the currently bound frame-buffer and convert its colors to linear
1331 * space in the fragment shader. This makes it suitable to be further processed by a GPUViewport
1332 *
1333 * The position denotes coordinates of a rectangle used to display the texture.
1334 * The texture_coord contains UV coordinates of the input texture which are mapped to the corners
1335 * of the rectangle. */
1337 const char *texture_colorspace_name,
1338 const bool predivide,
1339 const rctf &position,
1340 const rctf &texture_coord)
1341{
1342 GPUVertFormat *imm_format = immVertexFormat();
1343 const uint pos = GPU_vertformat_attr_add(imm_format, "pos", gpu::VertAttrType::SFLOAT_32_32);
1344 const uint tex_coord = GPU_vertformat_attr_add(
1345 imm_format, "texCoord", gpu::VertAttrType::SFLOAT_32_32);
1346
1347 if (!IMB_colormanagement_setup_glsl_draw_to_scene_linear(texture_colorspace_name, predivide)) {
1348 /* An error happened when configuring GPU side color space conversion. Return and allow the
1349 * view to be black, so that it is obvious something went wrong and that a bug report is to
1350 * be submitted.
1351 *
1352 * Note that fallback OCIO implementation is handled on a higher level. */
1353 return;
1354 }
1355
1357
1358 immRectf_with_texco(pos, tex_coord, position, texture_coord);
1359
1361
1363}
1364
1365/* Draw overlays for the currently displayed images in the preview. */
1367 const Scene *scene,
1368 const Editing &editing,
1369 const int timeline_frame)
1370{
1371 /* do strip independent checks only once */
1372 SpaceSeq *sseq = CTX_wm_space_seq(C);
1373 const ARegion *region = CTX_wm_region(C);
1375 return;
1376 }
1378 return;
1379 }
1380 if ((sseq->flag & SEQ_SHOW_OVERLAY) == 0 ||
1382 {
1383 return;
1384 }
1385 if (ELEM(sseq->mainb,
1390 {
1391 return;
1392 }
1393
1394 ListBaseT<SeqTimelineChannel> *channels = seq::channels_displayed_get(&editing);
1396 scene, channels, editing.current_strips(), timeline_frame, 0);
1397 Strip *active_seq = seq::select_active_get(scene);
1398
1399 for (Strip *strip : strips) {
1400 strip_draw_image_origin_and_outline(C, strip, strip == active_seq);
1401 }
1403}
1404
1405static bool is_cursor_visible(const SpaceSeq &sseq)
1406{
1407 if (G.moving & G_TRANSFORM_CURSOR) {
1408 return true;
1409 }
1410
1411 if ((sseq.flag & SEQ_SHOW_OVERLAY) &&
1413 {
1414 return true;
1415 }
1416 return false;
1417}
1418
1422static void draw_cursor_2d(const ARegion *region, const float2 &cursor)
1423{
1424 int co[2];
1425 ui::view2d_view_to_region(&region->v2d, cursor[0], cursor[1], &co[0], &co[1]);
1426
1427 /* Draw nice Anti Aliased cursor. */
1429
1430 /* Draw lines */
1431 float original_proj[4][4];
1432 GPU_matrix_projection_get(original_proj);
1434 ED_region_pixelspace(region);
1435 GPU_matrix_translate_2f(co[0] + 0.5f, co[1] + 0.5f);
1436 GPU_matrix_scale_2f(U.widget_unit, U.widget_unit);
1437
1438 float viewport[4];
1439 GPU_viewport_size_get_f(viewport);
1440
1441 GPUVertFormat *format = immVertexFormat();
1442 struct {
1443 uint pos, col;
1444 } attr_id{};
1445 attr_id.pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
1446 attr_id.col = GPU_vertformat_attr_add(format, "color", gpu::VertAttrType::SFLOAT_32_32_32);
1448 immUniform2fv("viewportSize", &viewport[2]);
1449 immUniform1f("lineWidth", U.pixelsize);
1450
1451 const float f5 = 0.25f;
1452 const float f10 = 0.5f;
1453 const float f20 = 1.0f;
1454
1455 const float red[3] = {1.0f, 0.0f, 0.0f};
1456 const float white[3] = {1.0f, 1.0f, 1.0f};
1457
1458 const int segments = 16;
1459 immBegin(GPU_PRIM_LINE_STRIP, segments + 1);
1460 for (int i = 0; i < segments + 1; i++) {
1461 float angle = float(2 * M_PI) * (float(i) / float(segments));
1462 float x = f10 * cosf(angle);
1463 float y = f10 * sinf(angle);
1464
1465 immAttr3fv(attr_id.col, (i % 2 == 0) ? red : white);
1466 immVertex2f(attr_id.pos, x, y);
1467 }
1468 immEnd();
1469
1470 float crosshair_color[3];
1471 ui::theme::get_color_3fv(TH_VIEW_OVERLAY, crosshair_color);
1472
1474 immAttr3fv(attr_id.col, crosshair_color);
1475 immVertex2f(attr_id.pos, -f20, 0);
1476 immAttr3fv(attr_id.col, crosshair_color);
1477 immVertex2f(attr_id.pos, -f5, 0);
1478
1479 immAttr3fv(attr_id.col, crosshair_color);
1480 immVertex2f(attr_id.pos, +f20, 0);
1481 immAttr3fv(attr_id.col, crosshair_color);
1482 immVertex2f(attr_id.pos, +f5, 0);
1483
1484 immAttr3fv(attr_id.col, crosshair_color);
1485 immVertex2f(attr_id.pos, 0, -f20);
1486 immAttr3fv(attr_id.col, crosshair_color);
1487 immVertex2f(attr_id.pos, 0, -f5);
1488
1489 immAttr3fv(attr_id.col, crosshair_color);
1490 immVertex2f(attr_id.pos, 0, +f20);
1491 immAttr3fv(attr_id.col, crosshair_color);
1492 immVertex2f(attr_id.pos, 0, +f5);
1493 immEnd();
1494
1496
1498
1500 GPU_matrix_projection_set(original_proj);
1501}
1502
1503/* Get offset in frame numbers of the reference frame relative to the current frame. */
1504static int get_reference_frame_offset(const Editing &editing, const RenderData &render_data)
1505{
1507 return editing.overlay_frame_abs - render_data.cfra;
1508 }
1509 return editing.overlay_frame_ofs;
1510}
1511
1512/* Create Texture from the given image buffer for drawing rendered sequencer frame on
1513 * the color render frame buffer.
1514 *
1515 * The texture format and color space matches the CPU-side buffer.
1516 *
1517 * If both float and byte buffers are missing nullptr is returned.
1518 * If channel configuration is incompatible with the texture nullptr is returned. */
1520{
1521 PRF_scope_with_name("SeqPreviewCreateTexture", ProfileCategory::Draw);
1522 const eGPUTextureUsage texture_usage = GPU_TEXTURE_USAGE_SHADER_READ |
1524
1525 gpu::Texture *texture = nullptr;
1526
1527 if (ibuf.float_data()) {
1528 gpu::TextureFormat texture_format;
1529 switch (ibuf.channels) {
1530 case 1:
1531 texture_format = gpu::TextureFormat::SFLOAT_32;
1532 break;
1533 case 3:
1534 texture_format = gpu::TextureFormat::SFLOAT_32_32_32;
1535 break;
1536 case 4:
1537 texture_format = gpu::TextureFormat::SFLOAT_32_32_32_32;
1538 break;
1539 default:
1540 BLI_assert_msg(0, "Incompatible number of channels for float buffer in sequencer");
1541 return nullptr;
1542 }
1543
1545 "seq_display_buf", ibuf.x, ibuf.y, 1, texture_format, texture_usage, nullptr);
1546 if (texture) {
1548 }
1549 }
1550 else if (ibuf.byte_data()) {
1551 texture = GPU_texture_create_2d("seq_display_buf",
1552 ibuf.x,
1553 ibuf.y,
1554 1,
1555 gpu::TextureFormat::UNORM_8_8_8_8,
1556 texture_usage,
1557 nullptr);
1558 if (texture) {
1560 }
1561 }
1562
1563 if (texture) {
1565 }
1566
1567 return texture;
1568}
1569
1570/* Get colorspace name of the image buffer used to create GPU texture.
1571 *
1572 * Needs to be kept in sync with create_texture() w.r.t which buffers are used to create the
1573 * texture. If the image buffer does not specify color space explicitly scene linear is returned if
1574 * there is a float buffer, and default byte space is returned if there is a byte buffer.
1575 *
1576 * If there are no buffers at all scene linear space is returned. */
1577static const char *get_texture_colorspace_name(const ImBuf &ibuf)
1578{
1579 if (ibuf.float_data()) {
1581 }
1582
1583 if (ibuf.byte_data()) {
1585 }
1586
1587 /* Fail-safe fallback. */
1589}
1590
1591/* Part of the sequencer preview region drawing which renders images to the viewport's color render
1592 * frame-buffer. */
1593static void sequencer_preview_draw_color_render(const SpaceSeq &space_sequencer,
1594 const Editing &editing,
1595 ARegion &region,
1596 const ImBuf *current_ibuf,
1597 gpu::Texture *current_texture,
1598 const ImBuf *reference_ibuf,
1599 gpu::Texture *reference_texture)
1600{
1602
1603 if (current_texture) {
1604 BLI_assert(current_ibuf);
1605 const rctf position = preview_get_full_position(region);
1606 const rctf texture_coord = preview_get_full_texture_coord();
1607 const char *texture_colorspace = get_texture_colorspace_name(*current_ibuf);
1608 const bool predivide = (current_ibuf->float_data() != nullptr);
1610 *current_texture, texture_colorspace, predivide, position, texture_coord);
1611 }
1612
1613 if (reference_texture) {
1614 BLI_assert(reference_ibuf);
1615 const rctf position = preview_get_reference_position(space_sequencer, editing, region);
1616 const rctf texture_coord = preview_get_reference_texture_coord(space_sequencer, editing);
1617 const char *texture_colorspace = get_texture_colorspace_name(*reference_ibuf);
1618 const bool predivide = (reference_ibuf->float_data() != nullptr);
1620 *reference_texture, texture_colorspace, predivide, position, texture_coord);
1621 }
1622}
1623
1624static void draw_registered_callbacks(const bContext *C, ARegion &region)
1625{
1627 BLI_assert(viewport);
1628
1630
1631 GPU_framebuffer_bind(overlay_fb);
1633 GPU_framebuffer_bind_no_srgb(overlay_fb);
1634}
1635
1637{
1638 return (sseq.mainb != SEQ_DRAW_IMG_HISTOGRAM) &&
1640}
1641
1642/* Part of the sequencer preview region drawing which renders information overlays to the
1643 * viewport's overlay frame-buffer. */
1645 const wmWindowManager &wm,
1646 Scene *scene,
1647 const SpaceSeq &space_sequencer,
1648 const Editing &editing,
1649 const ColorManagedViewSettings &view_settings,
1650 const ColorManagedDisplaySettings &display_settings,
1651 ARegion &region,
1652 gpu::Texture *current_texture,
1653 gpu::Texture *reference_texture,
1654 const ImBuf *input_ibuf,
1655 gpu::Texture *input_texture,
1656 const int timeline_frame)
1657{
1658 const bool is_playing = ED_screen_animation_playing(&wm);
1659 const bool show_preview_image = space_sequencer.mainb == SEQ_DRAW_IMG_IMBUF;
1660 const bool has_cpu_scope = input_ibuf && space_sequencer.mainb == SEQ_DRAW_IMG_HISTOGRAM;
1661 const bool has_gpu_scope = input_ibuf && input_texture &&
1662 ((space_sequencer.mainb == SEQ_DRAW_IMG_IMBUF &&
1663 space_sequencer.zebra != 0) ||
1664 ELEM(space_sequencer.mainb,
1668
1669 if (has_cpu_scope) {
1671 space_sequencer, view_settings, display_settings, *input_ibuf, timeline_frame);
1672 }
1673 if (has_gpu_scope) {
1674 update_gpu_scopes(input_ibuf,
1675 input_texture,
1676 view_settings,
1677 display_settings,
1678 space_sequencer,
1679 scene,
1680 timeline_frame);
1681 }
1682
1684
1685 if (has_cpu_scope || has_gpu_scope) {
1686 /* Draw scope. */
1688 space_sequencer,
1689 view_settings,
1690 display_settings,
1691 region,
1692 timeline_frame,
1693 input_ibuf->x,
1694 input_ibuf->y,
1695 input_ibuf->float_data() != nullptr);
1696 }
1697 else if (space_sequencer.flag & SEQ_USE_ALPHA) {
1698 /* Draw checked-board. */
1699 const View2D &v2d = region.v2d;
1700 imm_draw_box_checker_2d(v2d.tot.xmin, v2d.tot.ymin, v2d.tot.xmax, v2d.tot.ymax, true);
1701
1702 /* Draw current and preview textures in a special way to pierce a hole in the overlay to make
1703 * the actual image visible. */
1705 if (current_texture) {
1706 const rctf position = preview_get_full_position(region);
1707 const rctf texture_coord = preview_get_full_texture_coord();
1708 preview_draw_texture_simple(*current_texture, position, texture_coord);
1709 }
1710 if (reference_texture) {
1711 const rctf position = preview_get_reference_position(space_sequencer, editing, region);
1712 const rctf texture_coord = preview_get_reference_texture_coord(space_sequencer, editing);
1713 preview_draw_texture_simple(*reference_texture, position, texture_coord);
1714 }
1716 }
1717 else {
1718 /* The overlay framebuffer is fully cleared. Need to draw a full-frame transparent rectangle in
1719 * it to make sequencer result visible. */
1720
1721 const rctf position = preview_get_full_position(region);
1722
1723 GPUVertFormat *imm_format = immVertexFormat();
1724 const uint pos = GPU_vertformat_attr_add(imm_format, "pos", gpu::VertAttrType::SFLOAT_32_32);
1725
1727
1729 immUniformColor3f(1.0f, 1.0f, 1.0f);
1730 immRectf(pos, position.xmin, position.ymin, position.xmax, position.ymax);
1732
1734 }
1735
1736 /* Draw metadata. */
1737 if (show_preview_image && input_ibuf) {
1738 if ((space_sequencer.preview_overlay.flag & SEQ_PREVIEW_SHOW_METADATA) &&
1739 (space_sequencer.flag & SEQ_SHOW_OVERLAY))
1740 {
1741 const View2D &v2d = region.v2d;
1742 ED_region_image_metadata_draw(0.0, 0.0, input_ibuf, &v2d.tot, 1.0, 1.0);
1743 }
1744 }
1745
1746 if (show_preview_image && (space_sequencer.flag & SEQ_SHOW_OVERLAY)) {
1747 sequencer_draw_borders_overlay(space_sequencer, region.v2d, scene);
1748
1749 /* Various overlays like strip selection and text editing. */
1750 preview_draw_all_image_overlays(C, scene, editing, timeline_frame);
1751
1752 if ((space_sequencer.preview_overlay.flag & SEQ_PREVIEW_SHOW_GPENCIL) && space_sequencer.gpd) {
1754 }
1755 }
1756
1758
1760
1761 /* No need to show the cursor for scopes. */
1762 if ((is_playing == false) && show_preview_image && is_cursor_visible(space_sequencer)) {
1763 GPU_color_mask(true, true, true, true);
1764 GPU_depth_mask(false);
1766
1767 const float2 cursor_pixel = seq::image_preview_unit_to_px(scene, space_sequencer.cursor);
1768 draw_cursor_2d(&region, cursor_pixel);
1769 }
1770
1771 /* Gizmos. */
1772 if ((is_playing == false) && (space_sequencer.gizmo_flag & SEQ_GIZMO_HIDE) == 0) {
1774 }
1775
1776 /* FPS counter. */
1777 if ((U.uiflag & USER_SHOW_FPS) && (space_sequencer.flag & SEQ_SHOW_OVERLAY) &&
1779 {
1780 const rcti *rect = ED_region_visible_rect(&region);
1781 int xoffset = rect->xmin + U.widget_unit;
1782 int yoffset = rect->ymax;
1783
1784 /* #ED_scene_draw_fps does not set text/shadow colors, except when frame-rate is too low, then
1785 * it sets text color to red. Make sure the "normal case" also has legible colors. */
1786 const int font_id = BLF_default();
1787 float text_color[4] = {1, 1, 1, 1}, shadow_color[4] = {0, 0, 0, 0.8f};
1788 BLF_color4fv(font_id, text_color);
1789 BLF_enable(font_id, BLF_SHADOW);
1790 BLF_shadow_offset(font_id, 0, 0);
1791 BLF_shadow(font_id, FontShadowType::Outline, shadow_color);
1792
1793 ED_scene_draw_fps(scene, xoffset, &yoffset);
1794
1795 BLF_disable(font_id, BLF_SHADOW);
1796 }
1797}
1798
1800{
1802 const ScrArea *area = CTX_wm_area(C);
1803 const SpaceSeq &space_sequencer = *area->spacedata.first_as<SpaceSeq>();
1805
1806 /* Check if preview needs to be drawn at all. Note: do not draw preview region when
1807 * there is ongoing offline rendering, to avoid threading conflicts. */
1808 if (G.is_rendering || !scene || !scene->ed ||
1809 space_sequencer.render_size == SEQ_RENDER_SIZE_NONE)
1810 {
1812 return;
1813 }
1814
1815 PRF_scope_with_name("SeqPreviewDraw", ProfileCategory::Draw);
1816
1817 const Editing &editing = *scene->ed;
1818 const RenderData &render_data = scene->r;
1819
1821 render_data,
1822 scene->view_settings,
1823 scene->display_settings,
1824 *region,
1825 eSpaceSeq_RegionType(space_sequencer.mainb));
1826
1827 const bool show_imbuf = check_show_imbuf(space_sequencer);
1828 const bool use_gpu_texture = show_imbuf || check_scope_needs_input_texture(space_sequencer);
1829
1830 const bool draw_overlay = (space_sequencer.flag & SEQ_SHOW_OVERLAY);
1831 const bool draw_frame_overlay = (editing.overlay_frame_flag & SEQ_EDIT_OVERLAY_FRAME_SHOW) &&
1832 draw_overlay;
1833 const bool need_current_frame = !(draw_frame_overlay && (space_sequencer.overlay_frame_type ==
1835 const bool need_reference_frame = draw_frame_overlay && space_sequencer.overlay_frame_type !=
1837
1838 const bool show_edit_point = (space_sequencer.draw_flag & SEQ_DRAW_EDIT_POINT_PREVIEW) &&
1840 const int timeline_frame = show_edit_point ? editing.edit_point().value_or(render_data.cfra) :
1841 render_data.cfra;
1842
1843 /* GPU textures for the current and reference frames.
1844 *
1845 * When non-nullptr they are to be drawn (in other words, when they are non-nullptr the
1846 * corresponding draw_current_frame and draw_reference_frame is true). */
1847 gpu::Texture *current_texture = nullptr;
1848 gpu::Texture *reference_texture = nullptr;
1849
1850 /* Get image buffers before setting up GPU state for drawing. This is because
1851 * sequencer_ibuf_get() might not properly restore the state.
1852 * Additionally, some image buffers might be needed for both color render and overlay drawing. */
1853 ImBuf *current_ibuf = nullptr;
1854 ImBuf *reference_ibuf = nullptr;
1855 const char *view_names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME};
1856 if (need_reference_frame) {
1857 const int offset = get_reference_frame_offset(editing, render_data);
1858 reference_ibuf = sequencer_ibuf_get(
1859 C, timeline_frame + offset, view_names[space_sequencer.multiview_eye]);
1860 if (use_gpu_texture && reference_ibuf) {
1861 reference_texture = create_texture(*reference_ibuf);
1862 }
1863 }
1864 if (need_current_frame) {
1865 current_ibuf = sequencer_ibuf_get(
1866 C, timeline_frame, view_names[space_sequencer.multiview_eye]);
1867 if (use_gpu_texture && current_ibuf) {
1868 current_texture = seq::preview_cache_get_gpu_texture(scene,
1869 timeline_frame,
1870 space_sequencer.multiview_eye,
1871 space_sequencer.chanshown,
1872 current_ibuf->x,
1873 current_ibuf->y);
1874 if (current_texture == nullptr) {
1875 current_texture = create_texture(*current_ibuf);
1877 timeline_frame,
1878 space_sequencer.multiview_eye,
1879 space_sequencer.chanshown,
1880 current_texture);
1881 }
1882 }
1883 }
1884
1885 /* Image buffer and texture used for overlays: scopes, metadata etc. */
1886 ImBuf *overlay_ibuf = need_current_frame ? current_ibuf : reference_ibuf;
1887 gpu::Texture *overlay_texture = need_current_frame ? current_texture : reference_texture;
1888
1889 /* Draw parts of the preview region to the corresponding frame buffers. */
1891 editing,
1892 *region,
1893 current_ibuf,
1894 show_imbuf ? current_texture : nullptr,
1895 reference_ibuf,
1896 show_imbuf ? reference_texture : nullptr);
1898 *CTX_wm_manager(C),
1899 scene,
1900 space_sequencer,
1901 editing,
1902 scene->view_settings,
1903 scene->display_settings,
1904 *region,
1905 current_texture,
1906 reference_texture,
1907 overlay_ibuf,
1908 overlay_texture,
1909 timeline_frame);
1910
1911#if 0
1912 sequencer_draw_maskedit(C, scene, region, sseq);
1913#endif
1914
1915 /* Free GPU textures. Note that the #current_texture is kept around via #preview_set_gpu_texture,
1916 * for other preview areas or frames if nothing changes between them. */
1917 if (reference_texture) {
1918 GPU_texture_free(reference_texture);
1919 }
1920
1921 /* Free CPU side resources. */
1922 IMB_freeImBuf(current_ibuf);
1923 IMB_freeImBuf(reference_ibuf);
1924
1926}
1927
1929{
1930 const Scene *scene = CTX_data_sequencer_scene(C);
1931 const SpaceSeq *sseq = CTX_wm_space_seq(C);
1932
1933 const int fps = round_db_to_int(scene->frames_per_second());
1934 ED_time_scrub_draw(region, scene, !(sseq->flag & SEQ_DRAWFRAMES), true, fps);
1935 ED_time_scrub_draw_current_frame(region, scene, !(sseq->flag & SEQ_DRAWFRAMES), false, true);
1936}
1937
1938} // namespace blender::ed::vse
#define DEG2RADF(_deg)
#define M_PI
#define STEREO_LEFT_NAME
#define STEREO_RIGHT_NAME
#define UI_SCALE_FAC
#define REGION_DRAW_POST_VIEW
#define GPU_batch_uniform_1f(batch, name, x)
Definition GPU_batch.hh:267
#define GPU_batch_uniform_1i(batch, name, x)
Definition GPU_batch.hh:265
#define GPU_FRAMEBUFFER_FREE_SAFE(fb)
#define GPU_ATTACHMENT_TEXTURE(_texture)
#define GPU_ATTACHMENT_NONE
#define GPU_framebuffer_ensure_config(_fb,...)
#define PRF_scope_with_name(ui_name, category)
#define C
Definition RandGen.cpp:29
#define ND_SEQUENCER_PREFETCH
Definition WM_types.hh:517
#define NC_SCENE
Definition WM_types.hh:391
#define ELEM(...)
#define BLI_assert_msg(a, msg)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
constexpr int64_t first() const
constexpr int64_t last(const int64_t n=0) const
constexpr IndexRange()=default
void add_quad(float x1, float y1, float x2, float y2, const uchar color[4])
void add_line(float x1, float y1, float x2, float y2, const uchar color[4])
void add_wire_quad(float x1, float y1, float x2, float y2, const uchar color[4])
#define roundf(x)
#define FLT_MAX
#define point_size
#define position
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
const int state
IndexRange strip_text_selection_range_get(const TextVars *data)
static void draw_histogram(ARegion &region, const ScopeHistogram &hist, SeqQuadsBatch &quads, const rctf &area, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings)
static void sequencer_preview_draw_color_render(const SpaceSeq &space_sequencer, const Editing &editing, ARegion &region, const ImBuf *current_ibuf, gpu::Texture *current_texture, const ImBuf *reference_ibuf, gpu::Texture *reference_texture)
static Strip * special_seq_update
static gpu::Texture * create_texture(const ImBuf &ibuf)
static void preview_draw_end(const bContext *C)
static void preview_draw_texture_simple(gpu::Texture &texture, const rctf &position, const rctf &texture_coord)
static void preview_draw_color_render_begin(ARegion &region)
static float2 rgb_to_cbcr(const float3x3 &yuv_matrix, const float3 &rgb)
static void text_selection_draw(const bContext *C, const Strip *strip, uint pos)
static void sequencer_preview_clear()
bool sequencer_text_editing_active_poll(bContext *C)
static void preview_draw_overlay_begin(ARegion &region)
static void sequencer_draw_scopes(Scene *scene, const SpaceSeq &space_sequencer, const ColorManagedViewSettings &view_settings, const ColorManagedDisplaySettings &display_settings, ARegion &region, int timeline_frame, int image_width, int image_height, bool premultiplied)
static void sequencer_preview_draw_overlays(const bContext *C, const wmWindowManager &wm, Scene *scene, const SpaceSeq &space_sequencer, const Editing &editing, const ColorManagedViewSettings &view_settings, const ColorManagedDisplaySettings &display_settings, ARegion &region, gpu::Texture *current_texture, gpu::Texture *reference_texture, const ImBuf *input_ibuf, gpu::Texture *input_texture, const int timeline_frame)
static float2 coords_region_view_align(const View2D *v2d, const float2 coords)
static rctf preview_get_reference_position(const SpaceSeq &space_sequencer, const Editing &editing, const ARegion &region)
static void text_edit_draw(const bContext *C)
static void draw_registered_callbacks(const bContext *C, ARegion &region)
static rctf preview_get_full_position(const ARegion &region)
static void sequencer_preview_draw_empty(ARegion &region)
static void preview_draw_texture_to_linear(gpu::Texture &texture, const char *texture_colorspace_name, const bool predivide, const rctf &position, const rctf &texture_coord)
static const char * get_scope_debug_name(eSpaceSeq_RegionType type)
static bool check_scope_needs_input_texture(const SpaceSeq &sseq)
static rctf preview_get_full_texture_coord()
void sequencer_preview_region_draw(const bContext *C, ARegion *region)
static void update_cpu_scopes(const SpaceSeq &space_sequencer, const ColorManagedViewSettings &view_settings, const ColorManagedDisplaySettings &display_settings, const ImBuf &ibuf, const int timeline_frame)
static void sequencer_stop_running_jobs(const bContext *C, Scene *scene)
int2 strip_text_cursor_offset_to_position(const seq::TextVarsRuntime *runtime, int cursor_offset)
static void preview_draw_all_image_overlays(const bContext *C, const Scene *scene, const Editing &editing, const int timeline_frame)
static void draw_waveform_graticule(ARegion *region, SeqQuadsBatch &quads, const rctf &area, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings)
static rctf preview_get_reference_texture_coord(const SpaceSeq &space_sequencer, const Editing &editing)
static void text_edit_draw_cursor(const bContext *C, const Strip *strip, uint pos)
Strip * strip_under_mouse_get(const Scene *scene, const View2D *v2d, const int mval[2])
bool sequencer_view_preview_only_poll(const bContext *C)
void sequencer_special_update_set(Strip *strip)
void special_preview_set(bContext *C, const int mval[2])
static void sequencer_draw_borders_overlay(const SpaceSeq &sseq, const View2D &v2d, const Scene *scene)
static void draw_cursor_2d(const ARegion *region, const float2 &cursor)
static void seq_prefetch_wm_notify(const bContext *C, Scene *scene)
bool check_show_imbuf(const SpaceSeq &sseq)
static void sequencer_draw_gpencil_overlay(const bContext *C)
static int get_reference_frame_offset(const Editing &editing, const RenderData &render_data)
void sequencer_scrubbing_region_draw(const bContext *C, ARegion *region)
ImBuf * sequencer_ibuf_get(const bContext *C, int timeline_frame, const char *viewname)
static void strip_draw_image_origin_and_outline(const bContext *C, Strip *strip, bool is_active_seq)
static void update_gpu_scopes(const ImBuf *input_ibuf, gpu::Texture *input_texture, const ColorManagedViewSettings &view_settings, const ColorManagedDisplaySettings &display_settings, const SpaceSeq &space_sequencer, Scene *scene, int timeline_frame)
static void draw_vectorscope_graticule(ARegion *region, SeqQuadsBatch &quads, const rctf &area, const ocio::ScopeInfo &scope_info)
static const char * get_texture_colorspace_name(const ImBuf &ibuf)
static void sequencer_display_size(const RenderData &render_data, float r_viewrect[2])
static void preview_draw_begin(const bContext *C, const RenderData &render_data, const ColorManagedViewSettings &view_settings, const ColorManagedDisplaySettings &display_settings, ARegion &region, eSpaceSeq_RegionType preview_type)
static bool is_cursor_visible(const SpaceSeq &sseq)
T clamp(const T &a, const T &min, const T &max)
VecBase< T, Size > divide_ceil(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
CartesianBasis invert(const CartesianBasis &basis)
T interpolate(const T &a, const T &b, const FactorT &t)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
float2 image_preview_unit_to_px(const Scene *scene, const float2 co_src)
gpu::Texture * preview_cache_get_gpu_texture(Scene *scene, int timeline_frame, int view_id, int display_channel, int width, int height)
ImBuf * render_give_ibuf(const RenderData *context, float timeline_frame, int chanshown)
Definition render.cc:2139
bool prefetch_need_redraw(const bContext *C, Scene *scene)
Definition prefetch.cc:711
std::recursive_mutex & text_runtime_mutex_get()
void preview_cache_set_gpu_texture(Scene *scene, int timeline_frame, int view_id, int display_channel, gpu::Texture *texture)
Array< float2 > image_transform_quad_get(const Scene *scene, const Strip *strip)
Editing * editing_get(const Scene *scene)
Definition sequencer.cc:304
float get_render_scale_factor(eSpaceSeq_Proxy_RenderSize render_size, short scene_render_scale)
Definition render.cc:2249
float3x3 image_transform_matrix_get(const Scene *scene, const Strip *strip)
Strip * select_active_get(const Scene *scene)
void preview_cache_set_gpu_scope_texture(Scene *scene, int timeline_frame, int view_id, int display_channel, gpu::Texture *texture)
float2 image_transform_origin_preview_offset_get(const Scene *scene, const Strip *strip)
void render_new_render_data(Main *bmain, Depsgraph *depsgraph, Scene *scene, int rectx, int recty, eSpaceSeq_Proxy_RenderSize preview_render_size, Render *render, RenderData *r_context)
Definition render.cc:194
bool effects_can_render_text(const Strip *strip)
gpu::Texture * preview_cache_get_gpu_scope_texture(Scene *scene, int timeline_frame, int view_id, int display_channel, int width, int height)
ListBaseT< SeqTimelineChannel > * channels_displayed_get(const Editing *ed)
Definition channels.cc:26
VectorSet< Strip * > query_rendered_strips(const Scene *scene, ListBaseT< SeqTimelineChannel > *channels, ListBaseT< Strip > *seqbase, const int timeline_frame, const int displayed_channel)
Definition iterator.cc:239
ImBuf * render_give_ibuf_direct(const RenderData *context, float timeline_frame, Strip *strip)
Definition render.cc:2224
void get_color_3fv(int colorid, float col[3])
void frame_buffer_clear(int colorid)
char char char char void view2d_text_cache_add(View2D *v2d, float x, float y, const char *str, size_t str_len, const unsigned char col[4])
Definition view2d.cc:2079
void view2d_view_ortho(const View2D *v2d)
Definition view2d.cc:1080
void view2d_totRect_set(View2D *v2d, int width, int height)
Definition view2d.cc:1021
void view2d_curRect_validate(View2D *v2d)
Definition view2d.cc:810
void view2d_view_restore(const bContext *C)
Definition view2d.cc:1147
void draw_safe_areas(uint pos, const rctf *rect, const float title_aspect[2], const float action_aspect[2])
void view2d_text_cache_draw(ARegion *region)
Definition view2d.cc:2139
void view2d_view_to_region(const View2D *v2d, float x, float y, int *r_region_x, int *r_region_y) ATTR_NONNULL()
Definition view2d.cc:1705
void view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1651
void view2d_pixel_size_get(const View2D *v2d, float *r_x, float *r_y)
Definition view2d.cc:1911
View2D * view2d_fromcontext(const bContext *C)
Definition view2d.cc:1836
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
VecBase< uint8_t, 4 > uchar4
void ED_time_scrub_draw_current_frame(const ARegion *region, const Scene *scene, bool display_seconds, bool display_stalk, bool clamp_playhead)
int GPU_shader_get_sampler_binding(gpu::Shader *shader, const char *name)
gpu::FrameBuffer * GPU_framebuffer_active_get()
ScrArea * CTX_wm_area(const bContext *C)
void ED_time_scrub_draw(const ARegion *region, const Scene *scene, bool display_seconds, bool discrete_frames, const int base)
void ED_region_draw_cb_draw(const bContext *C, ARegion *region, int type)
void immUniformThemeColorBlend(int color_id1, int color_id2, float fac)
gpu::Batch * GPU_batch_create_procedural(GPUPrimType primitive_type, int32_t vertex_count)
Definition gpu_batch.cc:85
void GPU_viewport_colorspace_set(GPUViewport *viewport, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, float dither)
void GPU_texture_update(gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
void BLF_shadow_offset(int fontid, int x, int y)
Definition blf.cc:979
void GPU_storagebuf_clear_to_zero(gpu::StorageBuf *ssbo)
Scene * CTX_data_sequencer_scene(const bContext *C)
void immEnd()
void GPU_framebuffer_restore()
void ED_draw_composition_guides(uint shdr_pos, eCompositionGuideFlags flag, const rctf *rect, const float color[4])
Definition ed_draw.cc:1196
void immUniformColor3f(float r, float g, float b)
void ED_annotation_draw_2dimage(const bContext *C)
@ SEQ_EDIT_OVERLAY_FRAME_SHOW
unsigned int uint
Definition BKE_text.h:55
void IMB_colormanagement_finish_glsl_draw()
int BKE_scene_multiview_view_id_get(const RenderData *rd, const char *viewname)
Definition scene.cc:3335
void BLF_shadow(int fontid, FontShadowType type, const float rgba[4]=nullptr)
Definition blf.cc:967
gpu::StorageBuf * GPU_storagebuf_create_ex(size_t size, const void *data, GPUUsageType usage, const char *name)
void immUniform2f(const char *name, float x, float y)
BLI_INLINE float fb(float length, float L)
void GPU_matrix_identity_set()
void imm_draw_box_checker_2d(float x1, float y1, float x2, float y2, bool clear_alpha=false)
GPUVertFormat * immVertexFormat()
@ WM_JOB_TYPE_COMPOSITE
Definition WM_api.hh:2010
@ WM_JOB_TYPE_RENDER_PREVIEW
Definition WM_api.hh:2012
void immBegin(GPUPrimType, uint vertex_len)
gpu::FrameBuffer * GPU_viewport_framebuffer_render_get(GPUViewport *viewport)
bool IMB_colormanagement_setup_glsl_draw_from_space(const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, const ColorSpace *from_colorspace, float dither, bool predivide, bool do_overlay_merge, ColorManagedDisplaySpace display_space=DISPLAY_SPACE_DRAW, float opacity=1.0f)
void GPU_line_smooth(bool enable)
Definition gpu_state.cc:80
void GPU_framebuffer_clear_color(gpu::FrameBuffer *fb, const double4 clear_col)
@ GPU_PRIM_LINE_STRIP
@ GPU_PRIM_LINE_LOOP
void GPU_depth_mask(bool depth)
Definition gpu_state.cc:107
void GPU_batch_discard(gpu::Batch *batch)
const char * IMB_colormanagement_get_byte_colorspace(const ImBuf *ibuf)
@ TH_SEQ_TEXT_CURSOR
@ TH_SEQ_SELECTED_TEXT
@ SEQ_VIEW_SEQUENCE_PREVIEW
void GPU_batch_set_shader(gpu::Batch *batch, gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
const rcti * ED_region_visible_rect(ARegion *region)
Definition area.cc:4791
void GPU_compute_dispatch(gpu::Shader *shader, uint groups_x_len, uint groups_y_len, uint groups_z_len, const gpu::shader::SpecializationConstants *constants_state=nullptr)
MINLINE void rgb_float_to_uchar(unsigned char r_col[3], const float col_f[3])
void BLF_disable(int fontid, FontFlags flag)
Definition blf.cc:331
void immUnbindProgram()
void GPU_shader_uniform_1b(gpu::Shader *sh, const char *name, bool value)
int GPU_shader_get_ssbo_binding(gpu::Shader *shader, const char *name)
void BKE_render_resolution(const RenderData *r, const bool use_crop, int *r_width, int *r_height)
Definition scene.cc:3168
SpaceSeq * CTX_wm_space_seq(const bContext *C)
void GPU_line_width(float width)
Definition gpu_state.cc:151
void GPU_matrix_scale_2f(float x, float y)
@ GPU_BLEND_OVERLAY_MASK_FROM_ALPHA
Definition GPU_state.hh:122
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
@ GPU_BLEND_ADDITIVE
Definition GPU_state.hh:92
Global G
Definition blender.cc:57
void immAttr3fv(uint attr_id, const float data[3])
void GPU_viewport_unbind(GPUViewport *viewport)
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
@ SEQ_OVERLAY_FRAME_TYPE_CURRENT
@ SEQ_OVERLAY_FRAME_TYPE_REFERENCE
@ SEQ_OVERLAY_FRAME_TYPE_RECT
int BLF_set_default()
void immUniformThemeColor(int color_id)
void IMB_freeImBuf(ImBuf *ibuf)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void immUniform1f(const char *name, float x)
@ GPU_DEPTH_NONE
Definition GPU_state.hh:132
void immVertex2f(uint attr_id, float x, float y)
unsigned char uchar
Definition BKE_text.h:58
void ED_scene_draw_fps(const Scene *scene, int xoffset, int *yoffset)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_ATTACHMENT
@ SEQ_DRAW_EDIT_POINT_PREVIEW
void GPU_memory_barrier(GPUBarrier barrier)
Definition gpu_state.cc:305
ocio::ScopeInfo IMB_colormanagement_get_scope_info(const ColorManagedDisplaySettings *display_settings, const ColorManagedViewSettings *view_settings)
void GPU_viewport_size_get_f(float coords[4])
Definition gpu_state.cc:258
const char * IMB_colormanagement_role_colorspace_name_get(int role)
BMesh const char void * data
void GPU_shader_unbind()
void GPU_shader_uniform_3fv(gpu::Shader *sh, const char *name, const float data[3])
int BLF_default()
@ GPU_SHADER_SEQUENCER_SCOPE_RASTER
@ GPU_SHADER_3D_POLYLINE_FLAT_COLOR
@ GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA
@ GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR
@ GPU_SHADER_SEQUENCER_SCOPE_RESOLVE
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
wmWindowManager * CTX_wm_manager(const bContext *C)
@ SEQ_PREVIEW_SHOW_SAFE_CENTER
@ SEQ_PREVIEW_SHOW_METADATA
@ SEQ_PREVIEW_SHOW_OUTLINE_SELECTED
@ SEQ_PREVIEW_SHOW_COMPOSITION_GUIDES
@ SEQ_PREVIEW_SHOW_GPENCIL
@ SEQ_PREVIEW_SHOW_2D_CURSOR
@ SEQ_PREVIEW_SHOW_SAFE_MARGINS
void GPU_texture_filter_mode(gpu::Texture *texture, bool use_filter)
void GPU_color_mask(bool r, bool g, bool b, bool a)
Definition gpu_state.cc:95
int GPU_texture_width(const gpu::Texture *texture)
void GPU_batch_draw(gpu::Batch *batch)
void GPU_program_point_size(bool enable)
Definition gpu_state.cc:165
void ED_region_image_metadata_draw(int x, int y, const ImBuf *ibuf, const rctf *frame, float zoomx, float zoomy)
Definition ed_draw.cc:1039
void GPU_shader_bind(gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_shader_uniform_1i(gpu::Shader *sh, const char *name, int value)
@ GPU_BARRIER_SHADER_STORAGE
Definition GPU_state.hh:51
void immRectf_with_texco(uint pos, uint tex_coord, const rctf &p, const rctf &uv)
void GPU_storagebuf_bind(gpu::StorageBuf *ssbo, int slot)
void GPU_framebuffer_bind_no_srgb(gpu::FrameBuffer *fb)
void GPU_viewport_bind(GPUViewport *viewport, int view, const rcti *rect)
void GPU_matrix_projection_set(const float m[4][4])
void GPU_matrix_translate_2f(float x, float y)
MatBase< float, 3, 3 > float3x3
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void GPU_storagebuf_unbind(gpu::StorageBuf *ssbo)
void GPU_debug_group_end()
Definition gpu_debug.cc:34
@ SEQ_DRAW_IMG_VECTORSCOPE
@ SEQ_DRAW_IMG_WAVEFORM
@ SEQ_DRAW_IMG_HISTOGRAM
@ SEQ_DRAW_IMG_RGBPARADE
gpu::Shader * GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
bScreen * ED_screen_animation_no_scrub(const wmWindowManager *wm)
void WM_jobs_kill_type(wmWindowManager *wm, const void *owner, int job_type)
Definition wm_jobs.cc:642
gpu::FrameBuffer * GPU_viewport_framebuffer_overlay_get(GPUViewport *viewport)
void ED_region_pixelspace(const ARegion *region)
Definition area.cc:96
void GPU_shader_uniform_1f(gpu::Shader *sh, const char *name, float value)
Depsgraph * CTX_data_expect_evaluated_depsgraph(const bContext *C)
void immUniform4f(const char *name, float x, float y, float z, float w)
Main * CTX_data_main(const bContext *C)
void GPU_matrix_pop_projection()
void imm_draw_box_wire_2d(uint pos, float x1, float y1, float x2, float y2)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
MINLINE float ratiof(float min, float max, float pos)
void GPU_texture_bind(gpu::Texture *texture, int unit)
int GPU_texture_height(const gpu::Texture *texture)
void GPU_texture_free(gpu::Texture *texture)
BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
Definition BLI_rect.hh:198
void WM_gizmomap_draw(wmGizmoMap *gzmap, const bContext *C, const eWM_GizmoFlagMapDrawStep drawstep)
void GPU_matrix_ortho_set(float left, float right, float bottom, float top, float near, float far)
bool IMB_colormanagement_setup_glsl_draw_to_scene_linear(const char *from_colorspace_name, bool predivide)
void GPU_viewport_size_get_i(int coords[4])
Definition gpu_state.cc:267
@ G_TRANSFORM_CURSOR
void GPU_texture_unbind(gpu::Texture *texture)
bScreen * CTX_wm_screen(const bContext *C)
void immUniform2fv(const char *name, const float data[2])
void ED_annotation_draw_view2d(const bContext *C, bool onlyv2d)
void immUniformColor3fv(const float rgb[3])
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
void immUniform1i(const char *name, int x)
VecBase< float, 3 > float3
const float(* GPU_matrix_projection_get(float m[4][4]))[4]
void GPU_storagebuf_free(gpu::StorageBuf *ssbo)
void BLF_width_and_height(int fontid, const char *str, size_t str_len, float *r_width, float *r_height) ATTR_NONNULL()
Definition blf.cc:822
void immUniformColor4ubv(const unsigned char rgba[4])
void GPU_matrix_pop()
void GPU_matrix_push_projection()
void GPU_shader_uniform_mat3(gpu::Shader *sh, const char *name, const float data[3][3])
void GPU_depth_test(GPUDepthTest test)
Definition gpu_state.cc:70
GPUViewport * WM_draw_region_get_bound_viewport(ARegion *region)
Definition wm_draw.cc:964
void immRectf(uint pos, float x1, float y1, float x2, float y2)
ARegion * CTX_wm_region(const bContext *C)
void ED_mask_draw_region(Depsgraph *depsgraph, Mask *mask, ARegion *region, bool show_overlays, MaskDrawFlag draw_flag, MaskDrawType draw_type, MaskOverlayMode overlay_mode, float blend_factor, int width_i, int height_i, float aspx, float aspy, bool do_scale_applied, bool do_draw_cb, float stabmat[4][4], const bContext *C)
Definition mask_draw.cc:642
VecBase< double, 4 > double4
BLI_INLINE float BLI_rctf_cent_x(const struct rctf *rct)
Definition BLI_rect.hh:194
const char * IMB_colormanagement_get_float_colorspace(const ImBuf *ibuf)
void BLF_enable(int fontid, FontFlags flag)
Definition blf.cc:322
bScreen * ED_screen_animation_playing(const wmWindowManager *wm)
@ BLF_SHADOW
Definition BLF_enums.hh:38
MINLINE int round_db_to_int(double a)
gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_matrix_push()
void BLF_color4fv(int fontid, const float rgba[4])
Definition blf.cc:507
ocio::ColorSpace ColorSpace
Definition BLF_api.hh:42
@ WM_GIZMOMAP_DRAWSTEP_2D
void GPU_debug_group_begin(const char *name)
Definition gpu_debug.cc:23
void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float ymax)
Definition rct.cc:418
#define sinf
#define cosf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bke::ARegionRuntime * runtime
eRegion_Type regiontype
eEditingOverlayFrameFlag overlay_frame_flag
const ColorSpace * colorspace
const ColorSpace * colorspace
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
const uint8_t * byte_data() const
const float * float_data() const
const c_style_mat & ptr() const
ColorManagedViewSettings view_settings
ColorManagedDisplaySettings display_settings
struct DisplaySafeAreas safe_areas
struct RenderData r
ListBaseT< SpaceLink > spacedata
eCompositionGuideFlags composition_guide_flags
eSpaceSeq_SequencerPreviewOverlay_Flag flag
eSpaceSeq_Flag flag
struct SequencerPreviewOverlay preview_overlay
eSpaceSeq_Proxy_RenderSize render_size
eSpaceSeq_Gizmo_Flag gizmo_flag
ed::vse::SpaceSeq_Runtime * runtime
eSpaceSeq_DrawFlag draw_flag
struct bGPdata * gpd
eSpaceSeq_OverlayFrameType overlay_frame_type
eSpaceSeq_RegionType mainb
eSpaceSeq_Displays view
eView2D_KeepZoom keepzoom
struct wmTimer * animtimer
void calc_from_ibuf(const ImBuf *ibuf, const ColorManagedViewSettings &view_settings, const ColorManagedDisplaySettings &display_settings)
blender::float3x3 yuv_matrix
Definition OCIO_scope.hh:45
blender::float3 luma_coefficients
Definition OCIO_scope.hh:43
blender::float3x3 scope_gamut_to_rec709
Definition OCIO_scope.hh:41
Vector< ScopeGraticule > graticules
Definition OCIO_scope.hh:27
Vector< CharInfo > characters