[Bf-blender-cvs] [2b394e11082] blender-v3.0-release: UI: (Performance) Avoid drawing buttons out of view

Julian Eisel noreply at git.blender.org
Fri Nov 12 18:21:59 CET 2021


Commit: 2b394e1108281bcfe6602b08b3e9cd230003d22b
Author: Julian Eisel
Date:   Fri Nov 12 18:16:18 2021 +0100
Branches: blender-v3.0-release
https://developer.blender.org/rB2b394e1108281bcfe6602b08b3e9cd230003d22b

UI: (Performance) Avoid drawing buttons out of view

The UI was always drawing all buttons in a layout, no matter if they
were scrolled out of view (as in, outside of the visible part of the
region) or not. This means it's doing quite some work that can be
avoided.
UI drawing generally isn't a big bottleneck in Blender, so I don't
expect huge speedups from this. But while playing back animation, we do
redraw a fair bit of the UI, so in cases where there are many buttons
out of view, it may bring a little FPS boost. E.g. say in complex node
trees (the node editor is redrawn on animation playback in case there
are animated values that need updated UI feedback). This also mitigates
the issue in T92922 significantly.

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

Reviewed by: Brecht Van Lommel

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

M	source/blender/editors/interface/interface.c

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

diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index dc9eaed5731..9f9324505ad 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -2022,6 +2022,13 @@ static void ui_but_to_pixelrect(rcti *rect, const ARegion *region, uiBlock *bloc
   BLI_rcti_translate(rect, -region->winrct.xmin, -region->winrct.ymin);
 }
 
+static bool ui_but_pixelrect_in_view(const ARegion *region, const rcti *rect)
+{
+  rcti rect_winspace = *rect;
+  BLI_rcti_translate(&rect_winspace, region->winrct.xmin, region->winrct.ymin);
+  return BLI_rcti_isect(&region->winrct, &rect_winspace, NULL);
+}
+
 /* uses local copy of style, to scale things down, and allow widgets to change stuff */
 void UI_block_draw(const bContext *C, uiBlock *block)
 {
@@ -2095,14 +2102,20 @@ void UI_block_draw(const bContext *C, uiBlock *block)
 
   /* widgets */
   LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
-    if (!(but->flag & (UI_HIDDEN | UI_SCROLLED))) {
-      ui_but_to_pixelrect(&rect, region, block, but);
+    if (but->flag & (UI_HIDDEN | UI_SCROLLED)) {
+      continue;
+    }
 
-      /* XXX: figure out why invalid coordinates happen when closing render window */
-      /* and material preview is redrawn in main window (temp fix for bug T23848) */
-      if (rect.xmin < rect.xmax && rect.ymin < rect.ymax) {
-        ui_draw_but(C, region, &style, but, &rect);
-      }
+    ui_but_to_pixelrect(&rect, region, block, but);
+    /* Optimization: Don't draw buttons that are not visible (outside view bounds). */
+    if (!ui_but_pixelrect_in_view(region, &rect)) {
+      continue;
+    }
+
+    /* XXX: figure out why invalid coordinates happen when closing render window */
+    /* and material preview is redrawn in main window (temp fix for bug T23848) */
+    if (rect.xmin < rect.xmax && rect.ymin < rect.ymax) {
+      ui_draw_but(C, region, &style, but, &rect);
     }
   }



More information about the Bf-blender-cvs mailing list