[Bf-blender-cvs] [e490dc4346d] master: UI: Skip unnecessary cursor setting

Konrad Puklicki noreply at git.blender.org
Wed May 27 12:06:42 CEST 2020


Commit: e490dc4346dba5f29dada59ef421dfff499d65a9
Author: Konrad Puklicki
Date:   Wed May 27 12:04:14 2020 +0200
Branches: master
https://developer.blender.org/rBe490dc4346dba5f29dada59ef421dfff499d65a9

UI: Skip unnecessary cursor setting

Currently, in sculpting, weight paint and vertex paint modes every cursor
movement triggers redraw of a brush. During that redraw, native cursor is set.
Under the hood, setting the cursor causes freeing of previous cursor and
allocating a new one. In most cases, in previously mentioned modes, recreating
cursor is unnecessary since cursor stays the same.

This patch adds a check which skips cursor change if requested cursor is
already set. The check could be added in pain_cursor.c, but I felt adding it
inside WM_cursor_set function would hopefully skip more unnecessary cursor
reallocations.

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

Reviewed by: Julian Eisel

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

M	source/blender/windowmanager/intern/wm_cursors.c

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

diff --git a/source/blender/windowmanager/intern/wm_cursors.c b/source/blender/windowmanager/intern/wm_cursors.c
index 58ca3bf1b95..07d7ccf31db 100644
--- a/source/blender/windowmanager/intern/wm_cursors.c
+++ b/source/blender/windowmanager/intern/wm_cursors.c
@@ -145,6 +145,16 @@ void WM_cursor_set(wmWindow *win, int curs)
     return; /* Can't set custom cursor before Window init */
   }
 
+  if (curs == WM_CURSOR_DEFAULT && win->modalcursor) {
+    curs = win->modalcursor;
+  }
+
+  if (win->cursor == curs) {
+      return; /* Cursor is already set */
+  }
+
+  win->cursor = curs;
+
   if (curs == WM_CURSOR_NONE) {
     GHOST_SetCursorVisibility(win->ghostwin, 0);
     return;
@@ -152,12 +162,6 @@ void WM_cursor_set(wmWindow *win, int curs)
 
   GHOST_SetCursorVisibility(win->ghostwin, 1);
 
-  if (curs == WM_CURSOR_DEFAULT && win->modalcursor) {
-    curs = win->modalcursor;
-  }
-
-  win->cursor = curs;
-
   if (curs < 0 || curs >= WM_CURSOR_NUM) {
     BLI_assert(!"Invalid cursor number");
     return;



More information about the Bf-blender-cvs mailing list