Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_window.c
| Show First 20 Lines • Show All 371 Lines • ▼ Show 20 Lines | else if (win->ghostwin) { | ||||
| * in case of OS application terminate request (e.g. OS Shortcut Alt+F4, Cmd+Q, (...), or session end) */ | * in case of OS application terminate request (e.g. OS Shortcut Alt+F4, Cmd+Q, (...), or session end) */ | ||||
| GHOST_SetWindowModifiedState(win->ghostwin, (GHOST_TUns8) !wm->file_saved); | GHOST_SetWindowModifiedState(win->ghostwin, (GHOST_TUns8) !wm->file_saved); | ||||
| } | } | ||||
| } | } | ||||
| void WM_window_set_dpi(wmWindow *win) | void WM_window_set_dpi(wmWindow *win) | ||||
| { | { | ||||
| int auto_dpi = GHOST_GetDPIHint(win->ghostwin); | float auto_dpi = GHOST_GetDPIHint(win->ghostwin); | ||||
| /* Clamp auto DPI to 96, since our font/interface drawing does not work well | /* Clamp auto DPI to 96, since our font/interface drawing does not work well | ||||
| * with lower sizes. The main case we are interested in supporting is higher | * with lower sizes. The main case we are interested in supporting is higher | ||||
| * DPI. If a smaller UI is desired it is still possible to adjust UI scale. */ | * DPI. If a smaller UI is desired it is still possible to adjust UI scale. */ | ||||
| auto_dpi = MAX2(auto_dpi, 96); | auto_dpi = max_ff(auto_dpi, 96.0f); | ||||
| /* Lazily init UI scale size, preserving backwards compatibility by | /* Lazily init UI scale size, preserving backwards compatibility by | ||||
| * computing UI scale from ratio of previous DPI and auto DPI */ | * computing UI scale from ratio of previous DPI and auto DPI */ | ||||
| if (U.ui_scale == 0) { | if (U.ui_scale == 0) { | ||||
| int virtual_pixel = (U.virtual_pixel == VIRTUAL_PIXEL_NATIVE) ? 1 : 2; | int virtual_pixel = (U.virtual_pixel == VIRTUAL_PIXEL_NATIVE) ? 1 : 2; | ||||
| if (U.dpi == 0) { | if (U.dpi == 0) { | ||||
| U.ui_scale = virtual_pixel; | U.ui_scale = virtual_pixel; | ||||
| } | } | ||||
| else { | else { | ||||
| U.ui_scale = (virtual_pixel * U.dpi * 96.0f) / (auto_dpi * 72.0f); | U.ui_scale = (virtual_pixel * U.dpi * 96.0f) / (auto_dpi * 72.0f); | ||||
| } | } | ||||
| CLAMP(U.ui_scale, 0.25f, 4.0f); | CLAMP(U.ui_scale, 0.25f, 4.0f); | ||||
| } | } | ||||
| /* Blender's UI drawing assumes DPI 72 as a good default following macOS | /* Blender's UI drawing assumes DPI 72 as a good default following macOS | ||||
| * while Windows and Linux use DPI 96. GHOST assumes a default 96 so we | * while Windows and Linux use DPI 96. GHOST assumes a default 96 so we | ||||
| * remap the DPI to Blender's convention. */ | * remap the DPI to Blender's convention. */ | ||||
| auto_dpi *= GHOST_GetNativePixelSize(win->ghostwin); | |||||
| int dpi = auto_dpi * U.ui_scale * (72.0 / 96.0f); | int dpi = auto_dpi * U.ui_scale * (72.0 / 96.0f); | ||||
| /* Automatically set larger pixel size for high DPI. */ | /* Automatically set larger pixel size for high DPI. */ | ||||
| int pixelsize = MAX2(1, dpi / 54); | int pixelsize = max_ii(1, (int)(dpi / 64)); | ||||
| /* User adjustment for pixel size. */ | |||||
| pixelsize = max_ii(1, pixelsize + U.ui_line_width); | |||||
sergey: You can't and should not be doing this. `MAX2()` is a macro, which creates some temp variables… | |||||
| /* Set user preferences globals for drawing, and for forward compatibility. */ | /* Set user preferences globals for drawing, and for forward compatibility. */ | ||||
| U.pixelsize = GHOST_GetNativePixelSize(win->ghostwin) * pixelsize; | U.pixelsize = pixelsize; | ||||
| U.dpi = dpi / pixelsize; | U.dpi = dpi / pixelsize; | ||||
| U.virtual_pixel = (pixelsize == 1) ? VIRTUAL_PIXEL_NATIVE : VIRTUAL_PIXEL_DOUBLE; | U.virtual_pixel = (pixelsize == 1) ? VIRTUAL_PIXEL_NATIVE : VIRTUAL_PIXEL_DOUBLE; | ||||
| U.widget_unit = (U.pixelsize * U.dpi * 20 + 36) / 72; | U.widget_unit = (U.pixelsize * U.dpi * 20 + 36) / 72; | ||||
| /* update font drawing */ | /* update font drawing */ | ||||
| BLF_default_dpi(U.pixelsize * U.dpi); | BLF_default_dpi(U.pixelsize * U.dpi); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,362 Lines • Show Last 20 Lines | |||||
You can't and should not be doing this. MAX2() is a macro, which creates some temp variables to control types. This causes compilation error on Linux due to shadowing variables. And on all platforms you'll have right side of outer MAX2 evaluated twice and that is not a cheap calculation.
Just use max_ii here, will solve lots of issues.