diff options
author | Campbell Barton <campbell@blender.org> | 2022-08-18 07:45:47 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-08-18 07:45:47 +0300 |
commit | fcd72756abb7912669feb2dbcda9a647d1537d43 (patch) | |
tree | 5aed0a437001464c52bd6b84731be356491e0c68 /source/blender/windowmanager | |
parent | f5234474bde953356c72633bd05a1c6c9f747758 (diff) |
Cleanup: early return, reduce right-shift
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/intern/wm_splash_screen.c | 81 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_window.c | 86 |
2 files changed, 87 insertions, 80 deletions
diff --git a/source/blender/windowmanager/intern/wm_splash_screen.c b/source/blender/windowmanager/intern/wm_splash_screen.c index 2e04a629308..8fca3deef92 100644 --- a/source/blender/windowmanager/intern/wm_splash_screen.c +++ b/source/blender/windowmanager/intern/wm_splash_screen.c @@ -78,50 +78,51 @@ static void wm_block_splash_add_label(uiBlock *block, const char *label, int x, static void wm_block_splash_image_roundcorners_add(ImBuf *ibuf) { uchar *rct = (uchar *)ibuf->rect; + if (!rct) { + return; + } - if (rct) { - bTheme *btheme = UI_GetTheme(); - const float roundness = btheme->tui.wcol_menu_back.roundness * U.dpi_fac; - const int size = roundness * 20; - - if (size < ibuf->x && size < ibuf->y) { - /* Y-axis initial offset. */ - rct += 4 * (ibuf->y - size) * ibuf->x; - - for (int y = 0; y < size; y++) { - for (int x = 0; x < size; x++, rct += 4) { - const float pixel = 1.0 / size; - const float u = pixel * x; - const float v = pixel * y; - const float distance = sqrt(u * u + v * v); - - /* Pointer offset to the alpha value of pixel. */ - /* NOTE: the left corner is flipped in the X-axis. */ - const int offset_l = 4 * (size - x - x - 1) + 3; - const int offset_r = 4 * (ibuf->x - size) + 3; - - if (distance > 1.0) { - rct[offset_l] = 0; - rct[offset_r] = 0; - } - else { - /* Create a single pixel wide transition for anti-aliasing. - * Invert the distance and map its range [0, 1] to [0, pixel]. */ - const float fac = (1.0 - distance) * size; - - if (fac > 1.0) { - continue; - } - - const uchar alpha = unit_float_to_uchar_clamp(fac); - rct[offset_l] = alpha; - rct[offset_r] = alpha; - } + bTheme *btheme = UI_GetTheme(); + const float roundness = btheme->tui.wcol_menu_back.roundness * U.dpi_fac; + const int size = roundness * 20; + + if (size < ibuf->x && size < ibuf->y) { + /* Y-axis initial offset. */ + rct += 4 * (ibuf->y - size) * ibuf->x; + + for (int y = 0; y < size; y++) { + for (int x = 0; x < size; x++, rct += 4) { + const float pixel = 1.0 / size; + const float u = pixel * x; + const float v = pixel * y; + const float distance = sqrt(u * u + v * v); + + /* Pointer offset to the alpha value of pixel. */ + /* NOTE: the left corner is flipped in the X-axis. */ + const int offset_l = 4 * (size - x - x - 1) + 3; + const int offset_r = 4 * (ibuf->x - size) + 3; + + if (distance > 1.0) { + rct[offset_l] = 0; + rct[offset_r] = 0; } + else { + /* Create a single pixel wide transition for anti-aliasing. + * Invert the distance and map its range [0, 1] to [0, pixel]. */ + const float fac = (1.0 - distance) * size; - /* X-axis offset to the next row. */ - rct += 4 * (ibuf->x - size); + if (fac > 1.0) { + continue; + } + + const uchar alpha = unit_float_to_uchar_clamp(fac); + rct[offset_l] = alpha; + rct[offset_r] = alpha; + } } + + /* X-axis offset to the next row. */ + rct += 4 * (ibuf->x - size); } } } diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index 723b606251e..cb8a3670676 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -155,28 +155,30 @@ static void wm_window_check_size(rcti *rect) static void wm_ghostwindow_destroy(wmWindowManager *wm, wmWindow *win) { - if (win->ghostwin) { - /* Prevents non-drawable state of main windows (bugs T22967, - * T25071 and possibly T22477 too). Always clear it even if - * this window was not the drawable one, because we mess with - * drawing context to discard the GW context. */ - wm_window_clear_drawable(wm); + if (UNLIKELY(!win->ghostwin)) { + return; + } - if (win == wm->winactive) { - wm->winactive = NULL; - } + /* Prevents non-drawable state of main windows (bugs T22967, + * T25071 and possibly T22477 too). Always clear it even if + * this window was not the drawable one, because we mess with + * drawing context to discard the GW context. */ + wm_window_clear_drawable(wm); - /* We need this window's opengl context active to discard it. */ - GHOST_ActivateWindowDrawingContext(win->ghostwin); - GPU_context_active_set(win->gpuctx); + if (win == wm->winactive) { + wm->winactive = NULL; + } + + /* We need this window's opengl context active to discard it. */ + GHOST_ActivateWindowDrawingContext(win->ghostwin); + GPU_context_active_set(win->gpuctx); - /* Delete local GPU context. */ - GPU_context_discard(win->gpuctx); + /* Delete local GPU context. */ + GPU_context_discard(win->gpuctx); - GHOST_DisposeWindow(g_system, win->ghostwin); - win->ghostwin = NULL; - win->gpuctx = NULL; - } + GHOST_DisposeWindow(g_system, win->ghostwin); + win->ghostwin = NULL; + win->gpuctx = NULL; } void wm_window_free(bContext *C, wmWindowManager *wm, wmWindow *win) @@ -2035,36 +2037,40 @@ void WM_init_native_pixels(bool do_it) void WM_init_tablet_api(void) { - if (g_system) { - switch (U.tablet_api) { - case USER_TABLET_NATIVE: - GHOST_SetTabletAPI(g_system, GHOST_kTabletWinPointer); - break; - case USER_TABLET_WINTAB: - GHOST_SetTabletAPI(g_system, GHOST_kTabletWintab); - break; - case USER_TABLET_AUTOMATIC: - default: - GHOST_SetTabletAPI(g_system, GHOST_kTabletAutomatic); - break; - } + if (UNLIKELY(!g_system)) { + return; + } + + switch (U.tablet_api) { + case USER_TABLET_NATIVE: + GHOST_SetTabletAPI(g_system, GHOST_kTabletWinPointer); + break; + case USER_TABLET_WINTAB: + GHOST_SetTabletAPI(g_system, GHOST_kTabletWintab); + break; + case USER_TABLET_AUTOMATIC: + default: + GHOST_SetTabletAPI(g_system, GHOST_kTabletAutomatic); + break; } } void WM_cursor_warp(wmWindow *win, int x, int y) { - if (win && win->ghostwin) { - int oldx = x, oldy = y; + if (!(win && win->ghostwin)) { + return; + } - wm_cursor_position_to_ghost_client_coords(win, &x, &y); - GHOST_SetCursorPosition(g_system, win->ghostwin, x, y); + int oldx = x, oldy = y; - win->eventstate->prev_xy[0] = oldx; - win->eventstate->prev_xy[1] = oldy; + wm_cursor_position_to_ghost_client_coords(win, &x, &y); + GHOST_SetCursorPosition(g_system, win->ghostwin, x, y); - win->eventstate->xy[0] = oldx; - win->eventstate->xy[1] = oldy; - } + win->eventstate->prev_xy[0] = oldx; + win->eventstate->prev_xy[1] = oldy; + + win->eventstate->xy[0] = oldx; + win->eventstate->xy[1] = oldy; } /** \} */ |