[Bf-blender-cvs] [427c75e4c20] master: Cleanup: avoid some floating point divisions in drawing code

Brecht Van Lommel noreply at git.blender.org
Thu May 9 19:55:58 CEST 2019


Commit: 427c75e4c20b38611d213ca26681a5691be5d6a6
Author: Brecht Van Lommel
Date:   Thu May 9 19:37:31 2019 +0200
Branches: master
https://developer.blender.org/rB427c75e4c20b38611d213ca26681a5691be5d6a6

Cleanup: avoid some floating point divisions in drawing code

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

M	source/blender/editors/interface/interface_icons.c
M	source/blender/editors/interface/interface_panel.c
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/screen/area.c
M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/windowmanager/intern/wm_dragdrop.c
M	source/blender/windowmanager/intern/wm_window.c

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

diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index baa782dcb35..6bdbd3c4f1c 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -2240,12 +2240,12 @@ int UI_idcode_icon_get(const int idcode)
 /* draws icon with dpi scale factor */
 void UI_icon_draw(float x, float y, int icon_id)
 {
-  UI_icon_draw_ex(x, y, icon_id, 1.0f / UI_DPI_FAC, 1.0f, 0.0f, NULL, false);
+  UI_icon_draw_ex(x, y, icon_id, U.inv_dpi_fac, 1.0f, 0.0f, NULL, false);
 }
 
 void UI_icon_draw_alpha(float x, float y, int icon_id, float alpha)
 {
-  UI_icon_draw_ex(x, y, icon_id, 1.0f / UI_DPI_FAC, alpha, 0.0f, NULL, false);
+  UI_icon_draw_ex(x, y, icon_id, U.inv_dpi_fac, alpha, 0.0f, NULL, false);
 }
 
 void UI_icon_draw_preview(float x, float y, int icon_id, float aspect, float alpha, int size)
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index 724d5aa8cd2..cb2c55a26df 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -768,7 +768,7 @@ void ui_draw_aligned_panel(uiStyle *style,
     UI_icon_draw_ex(headrect.xmax - ((PNL_ICON * 2.2f) / block->aspect),
                     headrect.ymin + (5.0f / block->aspect),
                     (panel->flag & PNL_PIN) ? ICON_PINNED : ICON_UNPINNED,
-                    (block->aspect / UI_DPI_FAC),
+                    (block->aspect * U.inv_dpi_fac),
                     1.0f,
                     0.0f,
                     (const char *)col_title,
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 43efa758492..8724de41e8e 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -1450,7 +1450,7 @@ static void widget_draw_icon(
     return;
   }
 
-  aspect = but->block->aspect / UI_DPI_FAC;
+  aspect = but->block->aspect * U.inv_dpi_fac;
   height = ICON_DEFAULT_HEIGHT / aspect;
 
   /* calculate blend color */
@@ -1537,7 +1537,7 @@ static void widget_draw_submenu_tria(const uiBut *but,
                                      const rcti *rect,
                                      const uiWidgetColors *wcol)
 {
-  const float aspect = but->block->aspect / UI_DPI_FAC;
+  const float aspect = but->block->aspect * U.inv_dpi_fac;
   const int tria_height = (int)(ICON_DEFAULT_HEIGHT / aspect);
   const int tria_width = (int)(ICON_DEFAULT_WIDTH / aspect) - 2 * U.pixelsize;
   const int xs = rect->xmax - tria_width;
@@ -2357,7 +2357,7 @@ static void widget_draw_text_icon(const uiFontStyle *fstyle,
 
     const BIFIconID icon = widget_icon_id(but);
     int icon_size_init = is_tool ? ICON_DEFAULT_HEIGHT_TOOLBAR : ICON_DEFAULT_HEIGHT;
-    const float icon_size = icon_size_init / (but->block->aspect / UI_DPI_FAC);
+    const float icon_size = icon_size_init / (but->block->aspect * U.inv_dpi_fac);
     const float icon_padding = 2 * UI_DPI_FAC;
 
 #ifdef USE_UI_TOOLBAR_HACK
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 322b798057e..b359a4c4440 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -203,7 +203,7 @@ static void area_draw_azone_fullscreen(short x1, short y1, short x2, short y2, f
 
   alpha = min_ff(alpha, 0.75f);
 
-  UI_icon_draw_ex(x, y, ICON_FULLSCREEN_EXIT, 0.7f / UI_DPI_FAC, 0.0f, alpha, NULL, false);
+  UI_icon_draw_ex(x, y, ICON_FULLSCREEN_EXIT, 0.7f * U.inv_dpi_fac, 0.0f, alpha, NULL, false);
 
   /* debug drawing :
    * The click_rect is the same as defined in fullscreen_click_rcti_init
diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c
index 042cbfdaf8d..10b248de21d 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -1803,10 +1803,10 @@ static void tselem_draw_icon(uiBlock *block,
      * doesn't work for buttons */
     char color[4];
     if (UI_icon_get_theme_color(data.icon, (uchar *)color)) {
-      UI_icon_draw_ex(x, y, data.icon, 1.0f / UI_DPI_FAC, alpha, 0.0f, color, true);
+      UI_icon_draw_ex(x, y, data.icon, U.inv_dpi_fac, alpha, 0.0f, color, true);
     }
     else {
-      UI_icon_draw_ex(x, y, data.icon, 1.0f / UI_DPI_FAC, alpha, 0.0f, NULL, false);
+      UI_icon_draw_ex(x, y, data.icon, U.inv_dpi_fac, alpha, 0.0f, NULL, false);
     }
   }
   else {
diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h
index 639e912a9ab..3ceba714c37 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -602,6 +602,7 @@ typedef struct UserDef {
   int dpi;
   /** Runtime, multiplier to scale UI elements based on DPI. */
   float dpi_fac;
+  float inv_dpi_fac;
   /** Runtime, line width and point size based on DPI. */
   float pixelsize;
   /** Deprecated, for forward compatibility. */
@@ -611,7 +612,7 @@ typedef struct UserDef {
   int scrollback;
   /** Node insert offset (aka auto-offset) margin, but might be useful for later stuff as well. */
   char node_margin;
-  char _pad2[5];
+  char _pad2[1];
   /** #eUserpref_Translation_Flags. */
   short transopts;
   short menuthreshold1, menuthreshold2;
diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c
index 6ca30a19f4b..e4ecf7e6e94 100644
--- a/source/blender/windowmanager/intern/wm_dragdrop.c
+++ b/source/blender/windowmanager/intern/wm_dragdrop.c
@@ -442,7 +442,7 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect)
         drag_rect_minmax(rect, x, y, x + iconsize, y + iconsize);
       }
       else {
-        UI_icon_draw_ex(x, y, drag->icon, 1.0f / UI_DPI_FAC, 0.8, 0.0f, text_col, false);
+        UI_icon_draw_ex(x, y, drag->icon, U.inv_dpi_fac, 0.8, 0.0f, text_col, false);
       }
     }
 
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index e98067d78cc..db3a67231c6 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -672,6 +672,7 @@ void WM_window_set_dpi(wmWindow *win)
   U.dpi = dpi / pixelsize;
   U.virtual_pixel = (pixelsize == 1) ? VIRTUAL_PIXEL_NATIVE : VIRTUAL_PIXEL_DOUBLE;
   U.dpi_fac = ((U.pixelsize * (float)U.dpi) / 72.0f);
+  U.inv_dpi_fac = 1.0f / U.dpi_fac;
 
   /* Set user preferences globals for drawing, and for forward compatibility. */
   U.widget_unit = (U.pixelsize * U.dpi * 20 + 36) / 72;



More information about the Bf-blender-cvs mailing list