From 83f99bbb4f023bc30aec273630bf266891538acb Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Thu, 4 Feb 2021 07:58:06 -0800 Subject: [PATCH] wgl: Refactor screen creation to a function Fixes: 8955980f ("gallium/targets/libgl-gdi: prefer d3d12 driver") Reviewed-by: Jose Fonseca Tested-by: Prodea Alexandru-Liviu Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/4022 Part-of: (cherry picked from commit e6cf34d611cbb6432e50570b239971da140c101f) --- .pick_status.json | 2 +- src/gallium/targets/libgl-gdi/libgl_gdi.c | 89 ++++++++++++----------- 2 files changed, 47 insertions(+), 44 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 00a96fef97d..dc3a932a8a4 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -3289,7 +3289,7 @@ "description": "wgl: Refactor screen creation to a function", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "master_sha": null, "because_sha": "8955980f17f902d24c50962502a20285dcd11642" }, diff --git a/src/gallium/targets/libgl-gdi/libgl_gdi.c b/src/gallium/targets/libgl-gdi/libgl_gdi.c index ee55da0558f..85063d0d5cb 100644 --- a/src/gallium/targets/libgl-gdi/libgl_gdi.c +++ b/src/gallium/targets/libgl-gdi/libgl_gdi.c @@ -78,6 +78,48 @@ static boolean use_d3d12 = FALSE; static boolean use_zink = FALSE; #endif +static struct pipe_screen * +gdi_screen_create_by_name(HDC hDC, const char* driver, struct sw_winsys *winsys) +{ + struct pipe_screen* screen = NULL; + +#ifdef GALLIUM_LLVMPIPE + if (strcmp(driver, "llvmpipe") == 0) { + screen = llvmpipe_create_screen(winsys); + if (screen) + use_llvmpipe = TRUE; + } +#endif +#ifdef GALLIUM_SWR + if (strcmp(driver, "swr") == 0) { + screen = swr_create_screen(winsys); + if (screen) + use_swr = TRUE; + } +#endif +#ifdef GALLIUM_D3D12 + if (strcmp(driver, "d3d12") == 0) { + screen = d3d12_wgl_create_screen(winsys, hDC); + if (screen) + use_d3d12 = TRUE; + } +#endif +#ifdef GALLIUM_ZINK + if (strcmp(driver, "zink") == 0) { + screen = zink_create_screen(winsys); + if (screen) + use_zink = TRUE; + } +#endif +#ifdef GALLIUM_SOFTPIPE + if (strcmp(driver, "softpipe") == 0) { + screen = softpipe_create_screen(winsys); + } +#endif + + return screen; +} + static struct pipe_screen * gdi_screen_create(HDC hDC) { @@ -87,8 +129,8 @@ gdi_screen_create(HDC hDC) struct sw_winsys *winsys; winsys = gdi_create_sw_winsys(); - if(!winsys) - goto no_winsys; + if (!winsys) + return screen; #ifdef GALLIUM_D3D12 default_driver = "d3d12"; @@ -103,50 +145,11 @@ gdi_screen_create(HDC hDC) #endif driver = debug_get_option("GALLIUM_DRIVER", default_driver); - -#ifdef GALLIUM_LLVMPIPE - if (strcmp(driver, "llvmpipe") == 0) { - screen = llvmpipe_create_screen( winsys ); - if (screen) - use_llvmpipe = TRUE; - } -#endif -#ifdef GALLIUM_SWR - if (strcmp(driver, "swr") == 0) { - screen = swr_create_screen( winsys ); - if (screen) - use_swr = TRUE; - } -#endif -#ifdef GALLIUM_D3D12 - if (strcmp(driver, "d3d12") == 0) { - screen = d3d12_wgl_create_screen( winsys, hDC ); - if (screen) - use_d3d12 = TRUE; - } -#endif -#ifdef GALLIUM_ZINK - if (strcmp(driver, "zink") == 0) { - screen = zink_create_screen( winsys ); - if (screen) - use_zink = TRUE; - } -#endif - (void) driver; - -#ifdef GALLIUM_SOFTPIPE - if (screen == NULL) - screen = softpipe_create_screen( winsys ); -#endif + screen = gdi_screen_create_by_name(hDC, driver, winsys); if (!screen) - goto no_screen; + winsys->destroy(winsys); return screen; - -no_screen: - winsys->destroy(winsys); -no_winsys: - return NULL; }