UI: Skip expensive view button searching when drawing

Finding the active view item button should only happen when it's actually
necessary, since looping through all buttons and blocks is an expensive
operation. This patch limits the search a bit more, to left clicks (the only
case that is actually handled).

This improves drawing performance in the node editor slightly,
where this was a bottleneck.

Differential Revision: https://developer.blender.org/D16882
This commit is contained in:
Hans Goudey 2023-01-03 17:28:00 -05:00
parent 858fffc2df
commit 8b1edff6b5
Notes: blender-bot 2023-02-14 11:29:52 +01:00
Referenced by issue #103631, Blender 3.5.0 master crashes doing anything on MacBook Pro Intel Big Sur
2 changed files with 9 additions and 7 deletions

View File

@ -9684,11 +9684,15 @@ static int ui_handle_view_items_hover(const wmEvent *event, const ARegion *regio
static int ui_handle_view_item_event(bContext *C,
const wmEvent *event,
ARegion *region,
uiBut *view_but)
uiBut *active_but,
ARegion *region)
{
BLI_assert(view_but->type == UI_BTYPE_VIEW_ITEM);
if (event->type == LEFTMOUSE) {
/* Only bother finding the active view item button if the active button isn't already a view
* item. */
uiBut *view_but = active_but->type == UI_BTYPE_VIEW_ITEM ?
active_but :
ui_view_item_find_mouse_over(region, event->xy);
/* Will free active button if there already is one. */
ui_handle_button_activate(C, region, view_but, BUTTON_ACTIVATE_OVER);
return ui_do_button(C, view_but->block, view_but, event);
@ -11302,10 +11306,7 @@ static int ui_region_handler(bContext *C, const wmEvent *event, void * /*userdat
* nested in the item (it's an overlapping layout). */
ui_handle_view_items_hover(event, region);
if (retval == WM_UI_HANDLER_CONTINUE) {
uiBut *view_item = ui_view_item_find_mouse_over(region, event->xy);
if (view_item) {
retval = ui_handle_view_item_event(C, event, region, view_item);
}
retval = ui_handle_view_item_event(C, event, but, region);
}
/* delayed apply callbacks */

View File

@ -3199,6 +3199,7 @@ static void draw_background_color(const SpaceNode &snode)
void node_draw_space(const bContext &C, ARegion &region)
{
SCOPED_TIMER_AVERAGED(__func__);
wmWindow *win = CTX_wm_window(&C);
SpaceNode &snode = *CTX_wm_space_node(&C);
View2D &v2d = region.v2d;