Blender  V2.93
mask_draw.c
Go to the documentation of this file.
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) 2012 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "MEM_guardedalloc.h"
25 
26 #include "BLI_listbase.h"
27 #include "BLI_math.h"
28 #include "BLI_rect.h"
29 #include "BLI_utildefines.h"
30 
31 #include "BKE_context.h"
32 #include "BKE_mask.h"
33 
34 #include "DNA_mask_types.h"
35 #include "DNA_object_types.h" /* SELECT */
36 #include "DNA_screen_types.h"
37 #include "DNA_space_types.h"
38 
39 #include "ED_clip.h"
40 #include "ED_mask.h" /* own include */
41 #include "ED_screen.h"
42 #include "ED_space_api.h"
43 
44 #include "BIF_glutil.h"
45 
46 #include "GPU_immediate.h"
47 #include "GPU_matrix.h"
48 #include "GPU_shader.h"
49 #include "GPU_state.h"
50 
51 #include "UI_interface.h"
52 #include "UI_resources.h"
53 #include "UI_view2d.h"
54 
55 #include "DEG_depsgraph_query.h"
56 
57 static void mask_spline_color_get(MaskLayer *mask_layer,
58  MaskSpline *spline,
59  const bool is_sel,
60  uchar r_rgb[4])
61 {
62  if (is_sel) {
63  if (mask_layer->act_spline == spline) {
64  r_rgb[0] = r_rgb[1] = r_rgb[2] = 255;
65  }
66  else {
67  r_rgb[0] = 255;
68  r_rgb[1] = r_rgb[2] = 0;
69  }
70  }
71  else {
72  r_rgb[0] = 128;
73  r_rgb[1] = r_rgb[2] = 0;
74  }
75 
76  r_rgb[3] = 255;
77 }
78 
80  MaskSpline *UNUSED(spline),
81  const bool is_sel,
82  uchar r_rgb[4])
83 {
84  if (is_sel) {
85  r_rgb[1] = 255;
86  r_rgb[0] = r_rgb[2] = 0;
87  }
88  else {
89  r_rgb[1] = 128;
90  r_rgb[0] = r_rgb[2] = 0;
91  }
92 
93  r_rgb[3] = 255;
94 }
95 
96 static void mask_point_undistort_pos(SpaceClip *sc, float r_co[2], const float co[2])
97 {
98  BKE_mask_coord_to_movieclip(sc->clip, &sc->user, r_co, co);
99  ED_clip_point_undistorted_pos(sc, r_co, r_co);
100  BKE_mask_coord_from_movieclip(sc->clip, &sc->user, r_co, r_co);
101 }
102 
103 static void draw_single_handle(const MaskLayer *mask_layer,
104  const MaskSplinePoint *point,
105  const eMaskWhichHandle which_handle,
106  const int draw_type,
107  const float handle_size,
108  const float point_pos[2],
109  const float handle_pos[2])
110 {
111  const BezTriple *bezt = &point->bezt;
112  char handle_type;
113 
115  handle_type = bezt->h1;
116  }
117  else {
118  handle_type = bezt->h2;
119  }
120 
121  if (handle_type == HD_VECT) {
122  return;
123  }
124 
127  const uchar rgb_gray[4] = {0x60, 0x60, 0x60, 0xff};
128 
130  immUniformColor3ubv(rgb_gray);
131 
132  /* this could be split into its own loop */
133  if (draw_type == MASK_DT_OUTLINE) {
134  GPU_line_width(3.0f);
136  immVertex2fv(pos, point_pos);
137  immVertex2fv(pos, handle_pos);
138  immEnd();
139  }
140 
141  switch (handle_type) {
142  case HD_FREE:
144  break;
145  case HD_AUTO:
147  break;
148  case HD_ALIGN:
149  case HD_ALIGN_DOUBLESIDE:
151  break;
152  }
153 
154  GPU_line_width(1.0f);
156  immVertex2fv(pos, point_pos);
157  immVertex2fv(pos, handle_pos);
158  immEnd();
160 
161  /* draw handle points */
163  immUniform1f("size", handle_size);
164  immUniform1f("outlineWidth", 1.5f);
165 
166  float point_color[4] = {1.0f, 1.0f, 1.0f, 1.0f}; /* active color by default */
167  if (MASKPOINT_ISSEL_HANDLE(point, which_handle)) {
168  if (point != mask_layer->act_point) {
170  }
171  }
172  else {
174  }
175 
176  immUniform4fv("outlineColor", point_color);
177  immUniformColor3fvAlpha(point_color, 0.25f);
178 
180  immVertex2fv(pos, handle_pos);
181  immEnd();
182 
184 }
185 
186 /* return non-zero if spline is selected */
187 static void draw_spline_points(const bContext *C,
188  MaskLayer *mask_layer,
189  MaskSpline *spline,
190  const char draw_flag,
191  const char draw_type)
192 {
193  const bool is_spline_sel = (spline->flag & SELECT) &&
194  (mask_layer->restrictflag & MASK_RESTRICT_SELECT) == 0;
195  const bool is_smooth = (draw_flag & MASK_DRAWFLAG_SMOOTH) != 0;
196 
197  uchar rgb_spline[4];
198  MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline);
200  bool undistort = false;
201 
202  int tot_feather_point;
203  float(*feather_points)[2], (*fp)[2];
204  float min[2], max[2];
205 
206  if (!spline->tot_point) {
207  return;
208  }
209 
210  if (sc) {
211  undistort = sc->clip && (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT);
212  }
213 
214  /* TODO, add this to sequence editor */
215  float handle_size = 2.0f * UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE) * U.pixelsize;
216 
217  mask_spline_color_get(mask_layer, spline, is_spline_sel, rgb_spline);
218 
221 
223  immUniform1f("size", 0.7f * handle_size);
224 
225  /* feather points */
226  feather_points = fp = BKE_mask_spline_feather_points(spline, &tot_feather_point);
227  for (int i = 0; i < spline->tot_point; i++) {
228 
229  /* watch it! this is intentionally not the deform array, only check for sel */
230  MaskSplinePoint *point = &spline->points[i];
231 
232  for (int j = 0; j <= point->tot_uw; j++) {
233  float feather_point[2];
234  bool sel = false;
235 
236  copy_v2_v2(feather_point, *fp);
237 
238  if (undistort) {
239  mask_point_undistort_pos(sc, feather_point, feather_point);
240  }
241 
242  if (j == 0) {
243  sel = MASKPOINT_ISSEL_ANY(point);
244  }
245  else {
246  sel = (point->uw[j - 1].flag & SELECT) != 0;
247  }
248 
249  if (sel) {
250  if (point == mask_layer->act_point) {
251  immUniformColor3f(1.0f, 1.0f, 1.0f);
252  }
253  else {
255  }
256  }
257  else {
259  }
260 
262  immVertex2fv(pos, feather_point);
263  immEnd();
264 
265  fp++;
266  }
267  }
268  MEM_freeN(feather_points);
269 
271 
272  if (is_smooth) {
273  GPU_line_smooth(true);
274  }
275 
276  /* control points */
277  INIT_MINMAX2(min, max);
278  for (int i = 0; i < spline->tot_point; i++) {
279 
280  /* watch it! this is intentionally not the deform array, only check for sel */
281  MaskSplinePoint *point = &spline->points[i];
282  MaskSplinePoint *point_deform = &points_array[i];
283  BezTriple *bezt = &point_deform->bezt;
284 
285  float vert[2];
286 
287  copy_v2_v2(vert, bezt->vec[1]);
288 
289  if (undistort) {
290  mask_point_undistort_pos(sc, vert, vert);
291  }
292 
293  /* draw handle segment */
295  float handle[2];
296  BKE_mask_point_handle(point_deform, MASK_WHICH_HANDLE_STICK, handle);
297  if (undistort) {
298  mask_point_undistort_pos(sc, handle, handle);
299  }
301  mask_layer, point, MASK_WHICH_HANDLE_STICK, draw_type, handle_size, vert, handle);
302  }
303  else {
304  float handle_left[2], handle_right[2];
305  BKE_mask_point_handle(point_deform, MASK_WHICH_HANDLE_LEFT, handle_left);
306  BKE_mask_point_handle(point_deform, MASK_WHICH_HANDLE_RIGHT, handle_right);
307  if (undistort) {
308  mask_point_undistort_pos(sc, handle_left, handle_left);
309  mask_point_undistort_pos(sc, handle_left, handle_left);
310  }
312  mask_layer, point, MASK_WHICH_HANDLE_LEFT, draw_type, handle_size, vert, handle_left);
314  mask_layer, point, MASK_WHICH_HANDLE_RIGHT, draw_type, handle_size, vert, handle_right);
315  }
316 
317  /* bind program in loop so it does not interfere with draw_single_handle */
319 
320  /* draw CV point */
321  if (MASKPOINT_ISSEL_KNOT(point)) {
322  if (point == mask_layer->act_point) {
323  immUniformColor3f(1.0f, 1.0f, 1.0f);
324  }
325  else {
327  }
328  }
329  else {
331  }
332 
334  immVertex2fv(pos, vert);
335  immEnd();
336 
338 
339  minmax_v2v2_v2(min, max, vert);
340  }
341 
342  if (is_smooth) {
343  GPU_line_smooth(false);
344  }
345 
346  if (is_spline_sel) {
347  float x = (min[0] + max[0]) * 0.5f;
348  float y = (min[1] + max[1]) * 0.5f;
349 
351  immUniform1f("outlineWidth", 1.5f);
352 
353  if (mask_layer->act_spline == spline) {
354  immUniformColor3f(1.0f, 1.0f, 1.0f);
355  }
356  else {
357  immUniformColor3f(1.0f, 1.0f, 0.0f);
358  }
359 
360  immUniform4f("outlineColor", 0.0f, 0.0f, 0.0f, 1.0f);
361  immUniform1f("size", 12.0f);
362 
364  immVertex2f(pos, x, y);
365  immEnd();
366 
368  }
369 }
370 
371 static void mask_color_active_tint(uchar r_rgb[4], const uchar rgb[4], const bool is_active)
372 {
373  if (!is_active) {
374  r_rgb[0] = (uchar)((((int)(rgb[0])) + 128) / 2);
375  r_rgb[1] = (uchar)((((int)(rgb[1])) + 128) / 2);
376  r_rgb[2] = (uchar)((((int)(rgb[2])) + 128) / 2);
377  r_rgb[3] = rgb[3];
378  }
379  else {
380  *(uint *)r_rgb = *(const uint *)rgb;
381  }
382 }
383 
385  GPUPrimType prim_type,
386  const float (*points)[2],
387  uint vertex_len)
388 {
389  immBegin(prim_type, vertex_len);
390  for (uint i = 0; i < vertex_len; i++) {
391  immVertex2fv(pos, points[i]);
392  }
393  immEnd();
394 }
395 
396 static void mask_draw_curve_type(const bContext *C,
397  MaskSpline *spline,
398  float (*orig_points)[2],
399  int tot_point,
400  const bool is_feather,
401  const bool is_active,
402  const uchar rgb_spline[4],
403  const char draw_type)
404 {
405  const GPUPrimType draw_method = (spline->flag & MASK_SPLINE_CYCLIC) ? GPU_PRIM_LINE_LOOP :
407  const uchar rgb_black[4] = {0x00, 0x00, 0x00, 0xff};
408  uchar rgb_tmp[4];
410  float(*points)[2] = orig_points;
411 
412  if (sc) {
413  const bool undistort = sc->clip && (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT);
414 
415  if (undistort) {
416  points = MEM_callocN(2 * tot_point * sizeof(float), "undistorthed mask curve");
417 
418  for (int i = 0; i < tot_point; i++) {
419  mask_point_undistort_pos(sc, points[i], orig_points[i]);
420  }
421  }
422  }
423 
426 
427  switch (draw_type) {
428 
429  case MASK_DT_OUTLINE:
430  /* TODO(merwin): use fancy line shader here
431  * probably better with geometry shader (after core profile switch)
432  */
434 
435  GPU_line_width(3.0f);
436 
437  mask_color_active_tint(rgb_tmp, rgb_black, is_active);
438  immUniformColor4ubv(rgb_tmp);
439  mask_draw_array(pos, draw_method, points, tot_point);
440 
441  GPU_line_width(1.0f);
442 
443  mask_color_active_tint(rgb_tmp, rgb_spline, is_active);
444  immUniformColor4ubv(rgb_tmp);
445  mask_draw_array(pos, draw_method, points, tot_point);
446 
448  break;
449 
450  case MASK_DT_BLACK:
451  case MASK_DT_WHITE:
453  GPU_line_width(1.0f);
454 
455  if (draw_type == MASK_DT_BLACK) {
456  rgb_tmp[0] = rgb_tmp[1] = rgb_tmp[2] = 0;
457  }
458  else {
459  rgb_tmp[0] = rgb_tmp[1] = rgb_tmp[2] = 255;
460  }
461  /* alpha values seem too low but gl draws many points that compensate for it */
462  if (is_feather) {
463  rgb_tmp[3] = 64;
464  }
465  else {
466  rgb_tmp[3] = 128;
467  }
468 
469  if (is_feather) {
470  rgb_tmp[0] = (uchar)(((short)rgb_tmp[0] + (short)rgb_spline[0]) / 2);
471  rgb_tmp[1] = (uchar)(((short)rgb_tmp[1] + (short)rgb_spline[1]) / 2);
472  rgb_tmp[2] = (uchar)(((short)rgb_tmp[2] + (short)rgb_spline[2]) / 2);
473  }
474 
475  mask_color_active_tint(rgb_tmp, rgb_tmp, is_active);
476  immUniformColor4ubv(rgb_tmp);
477  mask_draw_array(pos, draw_method, points, tot_point);
478 
480  break;
481 
482  case MASK_DT_DASH: {
483  float colors[8];
484 
485  mask_color_active_tint(rgb_tmp, rgb_spline, is_active);
486  rgba_uchar_to_float(colors, rgb_tmp);
487  mask_color_active_tint(rgb_tmp, rgb_black, is_active);
488  rgba_uchar_to_float(colors + 4, rgb_tmp);
489 
491 
492  float viewport_size[4];
493  GPU_viewport_size_get_f(viewport_size);
494  immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
495 
496  immUniform1i("colors_len", 2); /* "advanced" mode */
497  immUniformArray4fv("colors", colors, 2);
498  immUniform1f("dash_width", 4.0f);
499  immUniform1f("dash_factor", 0.5f);
500  GPU_line_width(1.0f);
501 
502  mask_draw_array(pos, draw_method, points, tot_point);
503 
505  break;
506  }
507 
508  default:
509  BLI_assert(false);
510  }
511 
512  if (points != orig_points) {
513  MEM_freeN(points);
514  }
515 }
516 
517 static void draw_spline_curve(const bContext *C,
518  MaskLayer *mask_layer,
519  MaskSpline *spline,
520  const char draw_flag,
521  const char draw_type,
522  const bool is_active,
523  const int width,
524  const int height)
525 {
528 
529  uchar rgb_tmp[4];
530 
531  const bool is_spline_sel = (spline->flag & SELECT) &&
532  (mask_layer->restrictflag & MASK_RESTRICT_SELECT) == 0;
533  const bool is_smooth = (draw_flag & MASK_DRAWFLAG_SMOOTH) != 0;
534  const bool is_fill = (spline->flag & MASK_SPLINE_NOFILL) == 0;
535 
536  uint tot_diff_point;
537  float(*diff_points)[2];
538 
539  uint tot_feather_point;
540  float(*feather_points)[2];
541 
542  diff_points = BKE_mask_spline_differentiate_with_resolution(spline, resol, &tot_diff_point);
543 
544  if (!diff_points) {
545  return;
546  }
547 
548  if (is_smooth) {
549  GPU_line_smooth(true);
550  }
551 
553  spline, resol, (is_fill != false), &tot_feather_point);
554 
555  /* draw feather */
556  mask_spline_feather_color_get(mask_layer, spline, is_spline_sel, rgb_tmp);
558  C, spline, feather_points, tot_feather_point, true, is_active, rgb_tmp, draw_type);
559 
560  if (!is_fill) {
561  const float *fp = &diff_points[0][0];
562  float *fp_feather = &feather_points[0][0];
563 
564  BLI_assert(tot_diff_point == tot_feather_point);
565 
566  for (int i = 0; i < tot_diff_point; i++, fp += 2, fp_feather += 2) {
567  float tvec[2];
568  sub_v2_v2v2(tvec, fp, fp_feather);
569  add_v2_v2v2(fp_feather, fp, tvec);
570  }
571 
572  /* same as above */
574  C, spline, feather_points, tot_feather_point, true, is_active, rgb_tmp, draw_type);
575  }
576 
577  MEM_freeN(feather_points);
578 
579  /* draw main curve */
580  mask_spline_color_get(mask_layer, spline, is_spline_sel, rgb_tmp);
582  C, spline, diff_points, tot_diff_point, false, is_active, rgb_tmp, draw_type);
583  MEM_freeN(diff_points);
584 
585  if (is_smooth) {
586  GPU_line_smooth(false);
587  }
588 }
589 
590 static void draw_mask_layers(const bContext *C,
591  Mask *mask,
592  const char draw_flag,
593  const char draw_type,
594  const int width,
595  const int height)
596 {
599 
600  MaskLayer *mask_layer;
601  int i;
602 
603  for (mask_layer = mask->masklayers.first, i = 0; mask_layer != NULL;
604  mask_layer = mask_layer->next, i++) {
605  const bool is_active = (i == mask->masklay_act);
606 
607  if (mask_layer->restrictflag & MASK_RESTRICT_VIEW) {
608  continue;
609  }
610 
611  LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) {
612 
613  /* draw curve itself first... */
614  draw_spline_curve(C, mask_layer, spline, draw_flag, draw_type, is_active, width, height);
615 
616  if (!(mask_layer->restrictflag & MASK_RESTRICT_SELECT)) {
617  /* ...and then handles over the curve so they're nicely visible */
618  draw_spline_points(C, mask_layer, spline, draw_flag, draw_type);
619  }
620 
621  /* show undeform for testing */
622  if (0) {
623  void *back = spline->points_deform;
624 
625  spline->points_deform = NULL;
626  draw_spline_curve(C, mask_layer, spline, draw_flag, draw_type, is_active, width, height);
627  draw_spline_points(C, mask_layer, spline, draw_flag, draw_type);
628  spline->points_deform = back;
629  }
630  }
631  }
632 
633  GPU_program_point_size(false);
635 }
636 
637 void ED_mask_draw(const bContext *C, const char draw_flag, const char draw_type)
638 {
641  int width, height;
642 
643  if (!mask) {
644  return;
645  }
646 
648 
649  draw_mask_layers(C, mask, draw_flag, draw_type, width, height);
650 }
651 
652 static float *mask_rasterize(Mask *mask, const int width, const int height)
653 {
654  MaskRasterHandle *handle;
655  float *buffer = MEM_mallocN(sizeof(float) * height * width, "rasterized mask buffer");
656 
657  /* Initialize rasterization handle. */
658  handle = BKE_maskrasterize_handle_new();
659  BKE_maskrasterize_handle_init(handle, mask, width, height, true, true, true);
660 
662 
663  /* Free memory. */
665 
666  return buffer;
667 }
668 
669 /* sets up the opengl context.
670  * width, height are to match the values from ED_mask_get_size() */
673  Mask *mask_,
674  ARegion *region,
675  const char draw_flag,
676  const char draw_type,
677  const eMaskOverlayMode overlay_mode,
678  /* convert directly into aspect corrected vars */
679  const int width_i,
680  const int height_i,
681  const float aspx,
682  const float aspy,
683  const bool do_scale_applied,
684  const bool do_draw_cb,
685  /* optional - only used by clip */
686  float stabmat[4][4],
687  /* optional - only used when do_post_draw is set or called from clip editor */
688  const bContext *C)
689 {
690  struct View2D *v2d = &region->v2d;
691  Mask *mask_eval = (Mask *)DEG_get_evaluated_id(depsgraph, &mask_->id);
692 
693  /* aspect always scales vertically in movie and image spaces */
694  const float width = width_i, height = (float)height_i * (aspy / aspx);
695 
696  int x, y;
697  /* int w, h; */
698  float zoomx, zoomy;
699 
700  /* frame image */
701  float maxdim;
702  float xofs, yofs;
703 
704  /* find window pixel coordinates of origin */
705  UI_view2d_view_to_region(&region->v2d, 0.0f, 0.0f, &x, &y);
706 
707  /* w = BLI_rctf_size_x(&v2d->tot); */
708  /* h = BLI_rctf_size_y(&v2d->tot); */
709 
710  zoomx = (float)(BLI_rcti_size_x(&region->winrct) + 1) / BLI_rctf_size_x(&region->v2d.cur);
711  zoomy = (float)(BLI_rcti_size_y(&region->winrct) + 1) / BLI_rctf_size_y(&region->v2d.cur);
712 
713  if (do_scale_applied) {
714  zoomx /= width;
715  zoomy /= height;
716  }
717 
718  x += v2d->tot.xmin * zoomx;
719  y += v2d->tot.ymin * zoomy;
720 
721  /* frame the image */
722  maxdim = max_ff(width, height);
723  if (width == height) {
724  xofs = yofs = 0;
725  }
726  else if (width < height) {
727  xofs = ((height - width) / -2.0f) * zoomx;
728  yofs = 0.0f;
729  }
730  else { /* (width > height) */
731  xofs = 0.0f;
732  yofs = ((width - height) / -2.0f) * zoomy;
733  }
734 
735  if (draw_flag & MASK_DRAWFLAG_OVERLAY) {
736  const float red[4] = {1.0f, 0.0f, 0.0f, 0.0f};
737  float *buffer = mask_rasterize(mask_eval, width, height);
738 
739  if (overlay_mode != MASK_OVERLAY_ALPHACHANNEL) {
740  /* More blending types could be supported in the future. */
742  }
743 
744  GPU_matrix_push();
746  GPU_matrix_scale_2f(zoomx, zoomy);
747  if (stabmat) {
748  GPU_matrix_mul(stabmat);
749  }
752  state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, red);
753  immDrawPixelsTex(&state, 0.0f, 0.0f, width, height, GPU_R16F, false, buffer, 1.0f, 1.0f, NULL);
754 
755  GPU_matrix_pop();
756 
757  if (overlay_mode != MASK_OVERLAY_ALPHACHANNEL) {
759  }
760 
761  MEM_freeN(buffer);
762  }
763 
764  /* apply transformation so mask editing tools will assume drawing from the
765  * origin in normalized space */
766  GPU_matrix_push();
767  GPU_matrix_translate_2f(x + xofs, y + yofs);
768  GPU_matrix_scale_2f(zoomx, zoomy);
769  if (stabmat) {
770  GPU_matrix_mul(stabmat);
771  }
772  GPU_matrix_scale_2f(maxdim, maxdim);
773 
774  if (do_draw_cb) {
776  }
777 
778  /* draw! */
779  draw_mask_layers(C, mask_eval, draw_flag, draw_type, width, height);
780 
781  if (do_draw_cb) {
783  }
784 
785  GPU_matrix_pop();
786 }
787 
789  Mask *mask, ARegion *region, const int cfra, const int sfra, const int efra)
790 {
791  const float framelen = region->winx / (float)(efra - sfra + 1);
792 
793  MaskLayer *mask_layer = BKE_mask_layer_active(mask);
794  if (mask_layer == NULL) {
795  return;
796  }
797 
798  uint num_lines = BLI_listbase_count(&mask_layer->splines_shapes);
799  if (num_lines == 0) {
800  return;
801  }
802 
803  /* Local coordinate visible rect inside region, to accommodate overlapping ui. */
804  const rcti *rect_visible = ED_region_visible_rect(region);
805  const int region_bottom = rect_visible->ymin;
806 
809 
811  immUniformColor4ub(255, 175, 0, 255);
812 
813  immBegin(GPU_PRIM_LINES, 2 * num_lines);
814 
815  for (MaskLayerShape *mask_layer_shape = mask_layer->splines_shapes.first;
816  mask_layer_shape != NULL;
817  mask_layer_shape = mask_layer_shape->next) {
818  int frame = mask_layer_shape->frame;
819 
820  /* draw_keyframe(i, CFRA, sfra, framelen, 1); */
821  int height = (frame == cfra) ? 22 : 10;
822  int x = (frame - sfra) * framelen;
823  immVertex2i(pos, x, region_bottom);
824  immVertex2i(pos, x, region_bottom + height * UI_DPI_FAC);
825  }
826  immEnd();
828 }
typedef float(TangentPoint)[2]
void immDrawPixelsTex(IMMDrawPixelsTexState *state, float x, float y, int img_w, int img_h, eGPUTextureFormat gpu_format, bool use_filter, void *rect, float xzoom, float yzoom, const float color[4])
Definition: glutil.c:298
IMMDrawPixelsTexState immDrawPixelsTexSetup(int builtin)
Definition: glutil.c:66
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:714
struct SpaceClip * CTX_wm_space_clip(const bContext *C)
Definition: context.c:899
struct Mask * CTX_data_edit_mask(const bContext *C)
Definition: context.c:1316
@ MASK_HANDLE_MODE_STICK
Definition: BKE_mask.h:55
#define MASKPOINT_ISSEL_ANY(p)
Definition: BKE_mask.h:232
void BKE_maskrasterize_handle_free(MaskRasterHandle *mr_handle)
unsigned int BKE_mask_spline_feather_resolution(struct MaskSpline *spline, int width, int height)
Definition: mask_evaluate.c:82
eMaskWhichHandle
Definition: BKE_mask.h:46
@ MASK_WHICH_HANDLE_RIGHT
Definition: BKE_mask.h:50
@ MASK_WHICH_HANDLE_LEFT
Definition: BKE_mask.h:49
@ MASK_WHICH_HANDLE_STICK
Definition: BKE_mask.h:48
void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle, struct Mask *mask, const int width, const int height, const bool do_aspect_correct, const bool do_mask_aa, const bool do_feather)
void BKE_maskrasterize_buffer(MaskRasterHandle *mr_handle, const unsigned int width, const unsigned int height, float *buffer)
Rasterize a buffer from a single mask (threaded execution).
struct MaskLayer * BKE_mask_layer_active(struct Mask *mask)
Definition: mask.c:376
float(* BKE_mask_spline_differentiate_with_resolution(struct MaskSpline *spline, const unsigned int resol, unsigned int *r_tot_diff_point))[2]
#define MASKPOINT_ISSEL_KNOT(p)
Definition: BKE_mask.h:233
float(* BKE_mask_spline_feather_differentiated_points_with_resolution(struct MaskSpline *spline, const unsigned int resol, const bool do_feather_isect, unsigned int *r_tot_feather_point))[2]
void BKE_mask_coord_to_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2])
Definition: mask.c:1266
void BKE_mask_point_handle(const struct MaskSplinePoint *point, eMaskWhichHandle which_handle, float r_handle[2])
#define MASKPOINT_ISSEL_HANDLE(point, which_handle)
Definition: BKE_mask.h:235
float(* BKE_mask_spline_feather_points(struct MaskSpline *spline, int *tot_feather_point))[2]
eMaskhandleMode BKE_mask_point_handles_mode_get(const struct MaskSplinePoint *point)
struct MaskSplinePoint * BKE_mask_spline_point_array(struct MaskSpline *spline)
Definition: mask.c:328
void BKE_mask_coord_from_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2])
Definition: mask.c:1219
MaskRasterHandle * BKE_maskrasterize_handle_new(void)
unsigned int BKE_mask_spline_resolution(struct MaskSpline *spline, int width, int height)
Definition: mask_evaluate.c:43
#define BLI_assert(a)
Definition: BLI_assert.h:58
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE float max_ff(float a, float b)
MINLINE int max_ii(int a, int b)
void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
Definition: math_color.c:414
MINLINE void copy_v2_v2(float r[2], const float a[2])
void minmax_v2v2_v2(float min[2], float max[2], const float vec[2])
Definition: math_vector.c:1043
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition: BLI_rect.h:157
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition: BLI_rect.h:153
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition: BLI_rect.h:161
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition: BLI_rect.h:165
unsigned char uchar
Definition: BLI_sys_types.h:86
unsigned int uint
Definition: BLI_sys_types.h:83
#define INIT_MINMAX2(min, max)
#define UNUSED(x)
#define ELEM(...)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
struct ID * DEG_get_evaluated_id(const struct Depsgraph *depsgraph, struct ID *id)
@ HD_VECT
@ HD_FREE
@ HD_AUTO
@ HD_ALIGN_DOUBLESIDE
@ HD_ALIGN
@ MASK_DT_BLACK
@ MASK_DT_WHITE
@ MASK_DT_DASH
@ MASK_DT_OUTLINE
#define MASK_RESTRICT_SELECT
#define MASK_RESTRICT_VIEW
eMaskOverlayMode
@ MASK_OVERLAY_ALPHACHANNEL
#define MASK_DRAWFLAG_SMOOTH
#define MASK_DRAWFLAG_OVERLAY
@ MASK_SPLINE_CYCLIC
@ MASK_SPLINE_NOFILL
@ MCLIP_PROXY_RENDER_UNDISTORT
Object is a sort of wrapper for general info.
void ED_clip_point_undistorted_pos(struct SpaceClip *sc, const float co[2], float r_co[2])
Definition: clip_editor.c:459
void ED_mask_get_size(struct ScrArea *area, int *width, int *height)
Definition: mask_query.c:691
const rcti * ED_region_visible_rect(ARegion *region)
Definition: area.c:3682
#define REGION_DRAW_POST_VIEW
Definition: ED_space_api.h:66
void ED_region_draw_cb_draw(const struct bContext *, struct ARegion *, int)
#define REGION_DRAW_PRE_VIEW
Definition: ED_space_api.h:68
void immUniformColor4ubv(const unsigned char rgba[4])
void immUniform4f(const char *name, float x, float y, float z, float w)
void immUniform2f(const char *name, float x, float y)
void immUniformThemeColorShadeAlpha(int color_id, int color_offset, int alpha_offset)
void immUnbindProgram(void)
void immVertex2f(uint attr_id, float x, float y)
void immUniformThemeColor(int color_id)
void immBindBuiltinProgram(eGPUBuiltinShader shader_id)
void immVertex2fv(uint attr_id, const float data[2])
void immUniformColor3ubv(const unsigned char rgb[3])
void immUniform1i(const char *name, int x)
void immVertex2i(uint attr_id, int x, int y)
void immUniform1f(const char *name, float x)
void immUniformArray4fv(const char *bare_name, const float *data, int count)
void immUniformColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
GPUVertFormat * immVertexFormat(void)
void immUniformColor3f(float r, float g, float b)
void immUniform4fv(const char *name, const float data[4])
void immBegin(GPUPrimType, uint vertex_len)
void immUniformColor3fvAlpha(const float rgb[3], float a)
void immEnd(void)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
void GPU_matrix_pop(void)
Definition: gpu_matrix.cc:142
void GPU_matrix_scale_2f(float x, float y)
Definition: gpu_matrix.cc:232
#define GPU_matrix_mul(x)
Definition: GPU_matrix.h:223
void GPU_matrix_push(void)
Definition: gpu_matrix.cc:135
void GPU_matrix_translate_2f(float x, float y)
Definition: gpu_matrix.cc:190
GPUPrimType
Definition: GPU_primitive.h:34
@ GPU_PRIM_LINE_LOOP
Definition: GPU_primitive.h:39
@ GPU_PRIM_LINES
Definition: GPU_primitive.h:36
@ GPU_PRIM_POINTS
Definition: GPU_primitive.h:35
@ GPU_PRIM_LINE_STRIP
Definition: GPU_primitive.h:38
int GPU_shader_get_uniform(GPUShader *shader, const char *name)
Definition: gpu_shader.cc:551
void GPU_shader_uniform_vector(GPUShader *shader, int location, int length, int arraysize, const float *value)
Definition: gpu_shader.cc:617
@ GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR
Definition: GPU_shader.h:365
@ GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA
Definition: GPU_shader.h:278
@ GPU_SHADER_2D_UNIFORM_COLOR
Definition: GPU_shader.h:171
@ GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR
Definition: GPU_shader.h:251
@ GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA
Definition: GPU_shader.h:289
void GPU_program_point_size(bool enable)
Definition: gpu_state.cc:191
@ GPU_BLEND_MULTIPLY
Definition: GPU_state.h:61
@ GPU_BLEND_NONE
Definition: GPU_state.h:55
@ GPU_BLEND_ALPHA
Definition: GPU_state.h:57
void GPU_blend(eGPUBlend blend)
Definition: gpu_state.cc:55
void GPU_line_width(float width)
Definition: gpu_state.cc:173
void GPU_line_smooth(bool enable)
Definition: gpu_state.cc:85
void GPU_viewport_size_get_f(float coords[4])
Definition: gpu_state.cc:279
@ GPU_R16F
Definition: GPU_texture.h:114
@ GPU_FETCH_FLOAT
@ GPU_FETCH_INT_TO_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
@ GPU_COMP_I32
Read Guarded memory(de)allocation.
#define C
Definition: RandGen.cpp:39
#define UI_DPI_FAC
Definition: UI_interface.h:309
void UI_GetThemeColor3fv(int colorid, float col[3])
Definition: resources.c:1191
@ TH_HANDLE_ALIGN
Definition: UI_resources.h:128
@ TH_HANDLE_VERTEX_SIZE
Definition: UI_resources.h:222
@ TH_HANDLE_AUTO
Definition: UI_resources.h:126
@ TH_HANDLE_VERTEX_SELECT
Definition: UI_resources.h:221
@ TH_HANDLE_VERTEX
Definition: UI_resources.h:220
@ TH_HANDLE_FREE
Definition: UI_resources.h:125
float UI_GetThemeValuef(int colorid)
Definition: resources.c:1164
void UI_view2d_view_to_region(const struct View2D *v2d, float x, float y, int *r_region_x, int *r_region_y) ATTR_NONNULL()
unsigned int U
Definition: btGjkEpa3.h:78
#define SELECT
const Depsgraph * depsgraph
uint pos
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
format
Definition: logImageCore.h:47
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
void ED_mask_draw_frames(Mask *mask, ARegion *region, const int cfra, const int sfra, const int efra)
Definition: mask_draw.c:788
static void mask_spline_feather_color_get(MaskLayer *UNUSED(mask_layer), MaskSpline *UNUSED(spline), const bool is_sel, uchar r_rgb[4])
Definition: mask_draw.c:79
void ED_mask_draw(const bContext *C, const char draw_flag, const char draw_type)
Definition: mask_draw.c:637
static void mask_color_active_tint(uchar r_rgb[4], const uchar rgb[4], const bool is_active)
Definition: mask_draw.c:371
void ED_mask_draw_region(Depsgraph *depsgraph, Mask *mask_, ARegion *region, const char draw_flag, const char draw_type, const eMaskOverlayMode overlay_mode, const int width_i, const int height_i, const float aspx, const float aspy, const bool do_scale_applied, const bool do_draw_cb, float stabmat[4][4], const bContext *C)
Definition: mask_draw.c:671
static void mask_draw_array(uint pos, GPUPrimType prim_type, const float(*points)[2], uint vertex_len)
Definition: mask_draw.c:384
static void mask_point_undistort_pos(SpaceClip *sc, float r_co[2], const float co[2])
Definition: mask_draw.c:96
static float * mask_rasterize(Mask *mask, const int width, const int height)
Definition: mask_draw.c:652
static void mask_draw_curve_type(const bContext *C, MaskSpline *spline, float(*orig_points)[2], int tot_point, const bool is_feather, const bool is_active, const uchar rgb_spline[4], const char draw_type)
Definition: mask_draw.c:396
static void draw_mask_layers(const bContext *C, Mask *mask, const char draw_flag, const char draw_type, const int width, const int height)
Definition: mask_draw.c:590
static void draw_spline_curve(const bContext *C, MaskLayer *mask_layer, MaskSpline *spline, const char draw_flag, const char draw_type, const bool is_active, const int width, const int height)
Definition: mask_draw.c:517
static void draw_single_handle(const MaskLayer *mask_layer, const MaskSplinePoint *point, const eMaskWhichHandle which_handle, const int draw_type, const float handle_size, const float point_pos[2], const float handle_pos[2])
Definition: mask_draw.c:103
static void mask_spline_color_get(MaskLayer *mask_layer, MaskSpline *spline, const bool is_sel, uchar r_rgb[4])
Definition: mask_draw.c:57
static void draw_spline_points(const bContext *C, MaskLayer *mask_layer, MaskSpline *spline, const char draw_flag, const char draw_type)
Definition: mask_draw.c:187
static ulong state[N]
static void area(int d1, int d2, int e1, int e2, float weights[2])
#define min(a, b)
Definition: sort.c:51
float vec[3][3]
void * first
Definition: DNA_listBase.h:47
struct MaskLayer * next
ListBase splines_shapes
ListBase splines
struct MaskSplinePoint * act_point
char restrictflag
struct MaskSpline * act_spline
MaskSplinePointUW * uw
MaskSplinePoint * points_deform
MaskSplinePoint * points
struct MovieClipUser user
struct MovieClip * clip
float xmin
Definition: DNA_vec_types.h:85
float ymin
Definition: DNA_vec_types.h:86
int ymin
Definition: DNA_vec_types.h:80
float max
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)