[Bf-blender-cvs] [2fdca5bd198] master: Refactoring: View2DScrollers memory allocation

Jeroen Bakker noreply at git.blender.org
Mon Jun 22 21:46:54 CEST 2020


Commit: 2fdca5bd1981cddad16715598b4892a2c6099e2f
Author: Jeroen Bakker
Date:   Mon Jun 22 21:44:18 2020 +0200
Branches: master
https://developer.blender.org/rB2fdca5bd1981cddad16715598b4892a2c6099e2f

Refactoring: View2DScrollers memory allocation

View2DScrollers used the memory manager to allocate memory. This isn't a
problem but in a upcoming change the scrollers will be drawn more often
than it used to (See {D8066}). To limit the number of allocations and
frees this patch will use the stack for allocation.

Reviewed By: Campbell Barton

Differential Revision: https://developer.blender.org/D8076

===================================================================

M	release/datafiles/locale
M	release/scripts/addons
M	release/scripts/addons_contrib
M	source/blender/editors/include/UI_view2d.h
M	source/blender/editors/interface/view2d.c
M	source/blender/editors/interface/view2d_ops.c
M	source/blender/editors/screen/area.c
M	source/blender/editors/space_action/space_action.c
M	source/blender/editors/space_clip/space_clip.c
M	source/blender/editors/space_console/space_console.c
M	source/blender/editors/space_file/space_file.c
M	source/blender/editors/space_graph/space_graph.c
M	source/blender/editors/space_info/space_info.c
M	source/blender/editors/space_nla/space_nla.c
M	source/blender/editors/space_node/node_draw.c
M	source/blender/editors/space_outliner/space_outliner.c
M	source/blender/editors/space_sequencer/sequencer_draw.c

===================================================================

diff --git a/release/datafiles/locale b/release/datafiles/locale
index 72e5040232a..caf68fed42f 160000
--- a/release/datafiles/locale
+++ b/release/datafiles/locale
@@ -1 +1 @@
-Subproject commit 72e5040232a544b293dca05dac5707bd4e4bffaf
+Subproject commit caf68fed42f55e606b14c7105f5df694957ce036
diff --git a/release/scripts/addons b/release/scripts/addons
index 8397b98b8cb..bc1262f4d61 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 8397b98b8cb6510869d28a84592b8d7213c3b6c2
+Subproject commit bc1262f4d61feeba235bb75046e65e0e8411241f
diff --git a/release/scripts/addons_contrib b/release/scripts/addons_contrib
index 7c36b48507f..45aa940dabd 160000
--- a/release/scripts/addons_contrib
+++ b/release/scripts/addons_contrib
@@ -1 +1 @@
-Subproject commit 7c36b48507f79ca62f8c038bad0fb3468c4f48e2
+Subproject commit 45aa940dabda64f7877c6d5dd843998a86f0a836
diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h
index ffc06e94a90..0ddc45f4878 100644
--- a/source/blender/editors/include/UI_view2d.h
+++ b/source/blender/editors/include/UI_view2d.h
@@ -180,9 +180,10 @@ void UI_view2d_draw_scale_x__frames_or_seconds(const struct ARegion *region,
                                                int colorid);
 
 /* scrollbar drawing */
-View2DScrollers *UI_view2d_scrollers_calc(struct View2D *v2d, const struct rcti *mask_custom);
-void UI_view2d_scrollers_draw(struct View2D *v2d, View2DScrollers *scrollers);
-void UI_view2d_scrollers_free(View2DScrollers *scrollers);
+void UI_view2d_scrollers_calc(struct View2D *v2d,
+                              const struct rcti *mask_custom,
+                              struct View2DScrollers *r_scrollers);
+void UI_view2d_scrollers_draw(struct View2D *v2d, const struct rcti *mask_custom);
 
 /* list view tools */
 void UI_view2d_listview_view_to_cell(float columnwidth,
diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c
index 8fee9df8706..1e1f4e1a55b 100644
--- a/source/blender/editors/interface/view2d.c
+++ b/source/blender/editors/interface/view2d.c
@@ -1413,17 +1413,15 @@ struct View2DScrollers {
 };
 
 /* Calculate relevant scroller properties */
-View2DScrollers *UI_view2d_scrollers_calc(View2D *v2d, const rcti *mask_custom)
+void UI_view2d_scrollers_calc(View2D *v2d,
+                              const rcti *mask_custom,
+                              struct View2DScrollers *r_scrollers)
 {
-  View2DScrollers *scrollers;
   rcti vert, hor;
   float fac1, fac2, totsize, scrollsize;
   int scroll = view2d_scroll_mapped(v2d->scroll);
   int smaller;
 
-  /* scrollers is allocated here... */
-  scrollers = MEM_callocN(sizeof(View2DScrollers), "View2DScrollers");
-
   /* Always update before drawing (for dynamically sized scrollers). */
   view2d_masks(v2d, mask_custom);
 
@@ -1456,8 +1454,8 @@ View2DScrollers *UI_view2d_scrollers_calc(View2D *v2d, const rcti *mask_custom)
   CLAMP(hor.xmin, hor.xmin, hor.xmax - V2D_SCROLL_HANDLE_SIZE_HOTSPOT);
 
   /* store in scrollers, used for drawing */
-  scrollers->vert = vert;
-  scrollers->hor = hor;
+  r_scrollers->vert = vert;
+  r_scrollers->hor = hor;
 
   /* scroller 'buttons':
    * - These should always remain within the visible region of the scrollbar
@@ -1475,30 +1473,30 @@ View2DScrollers *UI_view2d_scrollers_calc(View2D *v2d, const rcti *mask_custom)
 
     fac1 = (v2d->cur.xmin - v2d->tot.xmin) / totsize;
     if (fac1 <= 0.0f) {
-      scrollers->hor_min = hor.xmin;
+      r_scrollers->hor_min = hor.xmin;
     }
     else {
-      scrollers->hor_min = (int)(hor.xmin + (fac1 * scrollsize));
+      r_scrollers->hor_min = (int)(hor.xmin + (fac1 * scrollsize));
     }
 
     fac2 = (v2d->cur.xmax - v2d->tot.xmin) / totsize;
     if (fac2 >= 1.0f) {
-      scrollers->hor_max = hor.xmax;
+      r_scrollers->hor_max = hor.xmax;
     }
     else {
-      scrollers->hor_max = (int)(hor.xmin + (fac2 * scrollsize));
+      r_scrollers->hor_max = (int)(hor.xmin + (fac2 * scrollsize));
     }
 
     /* prevent inverted sliders */
-    if (scrollers->hor_min > scrollers->hor_max) {
-      scrollers->hor_min = scrollers->hor_max;
+    if (r_scrollers->hor_min > r_scrollers->hor_max) {
+      r_scrollers->hor_min = r_scrollers->hor_max;
     }
     /* prevent sliders from being too small to grab */
-    if ((scrollers->hor_max - scrollers->hor_min) < V2D_SCROLL_THUMB_SIZE_MIN) {
-      scrollers->hor_max = scrollers->hor_min + V2D_SCROLL_THUMB_SIZE_MIN;
+    if ((r_scrollers->hor_max - r_scrollers->hor_min) < V2D_SCROLL_THUMB_SIZE_MIN) {
+      r_scrollers->hor_max = r_scrollers->hor_min + V2D_SCROLL_THUMB_SIZE_MIN;
 
-      CLAMP(scrollers->hor_max, hor.xmin + V2D_SCROLL_THUMB_SIZE_MIN, hor.xmax);
-      CLAMP(scrollers->hor_min, hor.xmin, hor.xmax - V2D_SCROLL_THUMB_SIZE_MIN);
+      CLAMP(r_scrollers->hor_max, hor.xmin + V2D_SCROLL_THUMB_SIZE_MIN, hor.xmax);
+      CLAMP(r_scrollers->hor_min, hor.xmin, hor.xmax - V2D_SCROLL_THUMB_SIZE_MIN);
     }
   }
 
@@ -1513,39 +1511,39 @@ View2DScrollers *UI_view2d_scrollers_calc(View2D *v2d, const rcti *mask_custom)
 
     fac1 = (v2d->cur.ymin - v2d->tot.ymin) / totsize;
     if (fac1 <= 0.0f) {
-      scrollers->vert_min = vert.ymin;
+      r_scrollers->vert_min = vert.ymin;
     }
     else {
-      scrollers->vert_min = (int)(vert.ymin + (fac1 * scrollsize));
+      r_scrollers->vert_min = (int)(vert.ymin + (fac1 * scrollsize));
     }
 
     fac2 = (v2d->cur.ymax - v2d->tot.ymin) / totsize;
     if (fac2 >= 1.0f) {
-      scrollers->vert_max = vert.ymax;
+      r_scrollers->vert_max = vert.ymax;
     }
     else {
-      scrollers->vert_max = (int)(vert.ymin + (fac2 * scrollsize));
+      r_scrollers->vert_max = (int)(vert.ymin + (fac2 * scrollsize));
     }
 
     /* prevent inverted sliders */
-    if (scrollers->vert_min > scrollers->vert_max) {
-      scrollers->vert_min = scrollers->vert_max;
+    if (r_scrollers->vert_min > r_scrollers->vert_max) {
+      r_scrollers->vert_min = r_scrollers->vert_max;
     }
     /* prevent sliders from being too small to grab */
-    if ((scrollers->vert_max - scrollers->vert_min) < V2D_SCROLL_THUMB_SIZE_MIN) {
-      scrollers->vert_max = scrollers->vert_min + V2D_SCROLL_THUMB_SIZE_MIN;
+    if ((r_scrollers->vert_max - r_scrollers->vert_min) < V2D_SCROLL_THUMB_SIZE_MIN) {
+      r_scrollers->vert_max = r_scrollers->vert_min + V2D_SCROLL_THUMB_SIZE_MIN;
 
-      CLAMP(scrollers->vert_max, vert.ymin + V2D_SCROLL_THUMB_SIZE_MIN, vert.ymax);
-      CLAMP(scrollers->vert_min, vert.ymin, vert.ymax - V2D_SCROLL_THUMB_SIZE_MIN);
+      CLAMP(r_scrollers->vert_max, vert.ymin + V2D_SCROLL_THUMB_SIZE_MIN, vert.ymax);
+      CLAMP(r_scrollers->vert_min, vert.ymin, vert.ymax - V2D_SCROLL_THUMB_SIZE_MIN);
     }
   }
-
-  return scrollers;
 }
 
 /* Draw scrollbars in the given 2d-region */
-void UI_view2d_scrollers_draw(View2D *v2d, View2DScrollers *vs)
+void UI_view2d_scrollers_draw(View2D *v2d, const rcti *mask_custom)
 {
+  View2DScrollers scrollers;
+  UI_view2d_scrollers_calc(v2d, mask_custom, &scrollers);
   bTheme *btheme = UI_GetTheme();
   rcti vert, hor;
   const int scroll = view2d_scroll_mapped(v2d->scroll);
@@ -1556,8 +1554,8 @@ void UI_view2d_scrollers_draw(View2D *v2d, View2DScrollers *vs)
   UI_GetThemeColor4ubv(TH_BACK, scrollers_back_color);
 
   /* make copies of rects for less typing */
-  vert = vs->vert;
-  hor = vs->hor;
+  vert = scrollers.vert;
+  hor = scrollers.hor;
 
   /* horizontal scrollbar */
   if (scroll & V2D_SCROLL_HORIZONTAL) {
@@ -1566,8 +1564,8 @@ void UI_view2d_scrollers_draw(View2D *v2d, View2DScrollers *vs)
     rcti slider;
     int state;
 
-    slider.xmin = vs->hor_min;
-    slider.xmax = vs->hor_max;
+    slider.xmin = scrollers.hor_min;
+    slider.xmax = scrollers.hor_max;
     slider.ymin = hor.ymin;
     slider.ymax = hor.ymax;
 
@@ -1602,8 +1600,8 @@ void UI_view2d_scrollers_draw(View2D *v2d, View2DScrollers *vs)
 
     slider.xmin = vert.xmin;
     slider.xmax = vert.xmax;
-    slider.ymin = vs->vert_min;
-    slider.ymax = vs->vert_max;
+    slider.ymin = scrollers.vert_min;
+    slider.ymax = scrollers.vert_max;
 
     state = (v2d->scroll_ui & V2D_SCROLL_V_ACTIVE) ? UI_SCROLL_PRESSED : 0;
 
@@ -1631,12 +1629,6 @@ void UI_view2d_scrollers_draw(View2D *v2d, View2DScrollers *vs)
   btheme->tui.widget_emboss[3] = emboss_alpha;
 }
 
-/* free temporary memory used for drawing scrollers */
-void UI_view2d_scrollers_free(View2DScrollers *scrollers)
-{
-  MEM_freeN(scrollers);
-}
-
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c
index 34108853c61..0585f7cf7cd 100644
--- a/source/blender/editors/interface/view2d_ops.c
+++ b/source/blender/editors/interface/view2d_ops.c
@@ -2011,7 +2011,7 @@ static void scroller_activate_init(bContext *C,
                                    const char in_scroller)
 {
   v2dScrollerMove *vsm;
-  View2DScrollers *scrollers;
+  View2DScrollers scrollers;
   ARegion *region = CTX_wm_region(C);
   View2D *v2d = &region->v2d;
   rctf tot_cur_union;
@@ -2032,7 +2032,7 @@ static void scroller_activate_init(bContext *C,
   /* 'zone' depends on where mouse is relative to bubble
    * - zooming must be allowed on this axis, otherwise, default to pan
    */
-  scrollers = UI_view2d_scrollers_calc(v2d, NULL);
+  UI_view2d_scrollers_calc(v2d, NULL, &scrollers);
 
   /* Use a union of 'cur' & 'tot' in case the current view is far outside 'tot'. In this cases
    * moving the scroll bars has far too little effect and the view can get stuck T31476. */
@@ -2049,15 +2049,15 @@ static void scroller_activate_init(bContext *C,
 
     /* get 'zone' (i.e. which part of scroller is activated) */
     vsm->zone = mouse_in_scroller_handle(
-        event->mval[0], v2d->hor.xmin, v2d->hor.xmax, scrollers->hor_min, scrollers->hor_max);
+        event->mval[0], v2d->hor.xmin, v2d->hor.xmax, scrollers.hor_min, scrollers.hor_max);
 
     if ((v2d->keepzoom & V2D_LOCKZOOM_X) && ELEM(vsm->zone, SCROLLHANDLE_MIN, SCROLLHANDLE_MAX)) {
       /* default to scroll, as handles not u

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list