From bb706ca93a6b6f4f829e3e596a6cbbace8911295 Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Sat, 4 Sep 2021 08:06:48 -0700 Subject: [PATCH] wgl: Use HWND instead of HDC as primary framebuffer handle EGL's native window is an HWND, so this removes the need to GetDC from the creation path there. Reviewed-by: Charmaine Lee Reviewed By: Bill Kristiansen Acked-by: Roland Scheidegger Part-of: --- src/gallium/frontends/wgl/stw_context.c | 2 +- src/gallium/frontends/wgl/stw_ext_pbuffer.c | 10 ++-------- src/gallium/frontends/wgl/stw_framebuffer.c | 12 +++--------- src/gallium/frontends/wgl/stw_framebuffer.h | 2 +- src/gallium/frontends/wgl/stw_winsys.h | 2 +- src/gallium/targets/libgl-d3d12/libgl_d3d12.c | 4 ++-- src/gallium/targets/wgl/wgl.c | 4 ++-- .../winsys/d3d12/wgl/d3d12_wgl_framebuffer.cpp | 4 ++-- src/gallium/winsys/d3d12/wgl/d3d12_wgl_public.h | 2 +- 9 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/gallium/frontends/wgl/stw_context.c b/src/gallium/frontends/wgl/stw_context.c index a7e57c107b7..7c789f18b60 100644 --- a/src/gallium/frontends/wgl/stw_context.c +++ b/src/gallium/frontends/wgl/stw_context.c @@ -571,7 +571,7 @@ get_unlocked_refd_framebuffer_from_dc(HDC hDC) */ int iPixelFormat = get_matching_pixel_format(hDC); if (iPixelFormat) - fb = stw_framebuffer_create(hDC, iPixelFormat, STW_FRAMEBUFFER_WGL_WINDOW); + fb = stw_framebuffer_create(WindowFromDC(hDC), iPixelFormat, STW_FRAMEBUFFER_WGL_WINDOW); if (!fb) return NULL; } diff --git a/src/gallium/frontends/wgl/stw_ext_pbuffer.c b/src/gallium/frontends/wgl/stw_ext_pbuffer.c index 28c97b8f9a6..9e0e564dbf1 100644 --- a/src/gallium/frontends/wgl/stw_ext_pbuffer.c +++ b/src/gallium/frontends/wgl/stw_ext_pbuffer.c @@ -82,7 +82,6 @@ wglCreatePbufferARB(HDC hCurrentDC, DWORD dwStyle; RECT rect; HWND hWnd; - HDC hDC; int iDisplayablePixelFormat; PIXELFORMATDESCRIPTOR pfd; BOOL bRet; @@ -239,16 +238,11 @@ wglCreatePbufferARB(HDC hCurrentDC, assert(rect.bottom - rect.top == iHeight); #endif - hDC = GetDC(hWnd); - if (!hDC) { - return 0; - } - /* * We can't pass non-displayable pixel formats to GDI, which is why we * create the framebuffer object before calling SetPixelFormat(). */ - fb = stw_framebuffer_create(hDC, iPixelFormat, STW_FRAMEBUFFER_PBUFFER); + fb = stw_framebuffer_create(hWnd, iPixelFormat, STW_FRAMEBUFFER_PBUFFER); if (!fb) { SetLastError(ERROR_NO_SYSTEM_RESOURCES); return NULL; @@ -267,7 +261,7 @@ wglCreatePbufferARB(HDC hCurrentDC, * We need to set a displayable pixel format on the hidden window DC * so that wglCreateContext and wglMakeCurrent are not overruled by GDI. */ - bRet = SetPixelFormat(hDC, iDisplayablePixelFormat, &pfd); + bRet = SetPixelFormat(GetDC(hWnd), iDisplayablePixelFormat, &pfd); assert(bRet); return (HPBUFFERARB)fb; diff --git a/src/gallium/frontends/wgl/stw_framebuffer.c b/src/gallium/frontends/wgl/stw_framebuffer.c index 4a487462466..58488efcd6f 100644 --- a/src/gallium/frontends/wgl/stw_framebuffer.c +++ b/src/gallium/frontends/wgl/stw_framebuffer.c @@ -261,17 +261,11 @@ stw_call_window_proc(int nCode, WPARAM wParam, LPARAM lParam) * with its mutex locked. */ struct stw_framebuffer * -stw_framebuffer_create(HDC hdc, int iPixelFormat, enum stw_framebuffer_owner owner) +stw_framebuffer_create(HWND hWnd, int iPixelFormat, enum stw_framebuffer_owner owner) { - HWND hWnd; struct stw_framebuffer *fb; const struct stw_pixelformat_info *pfi; - /* We only support drawing to a window. */ - hWnd = WindowFromDC( hdc ); - if (!hWnd) - return NULL; - fb = CALLOC_STRUCT( stw_framebuffer ); if (fb == NULL) return NULL; @@ -281,7 +275,7 @@ stw_framebuffer_create(HDC hdc, int iPixelFormat, enum stw_framebuffer_owner own if (stw_dev->stw_winsys->create_framebuffer) fb->winsys_framebuffer = - stw_dev->stw_winsys->create_framebuffer(stw_dev->screen, hdc, iPixelFormat); + stw_dev->stw_winsys->create_framebuffer(stw_dev->screen, hWnd, iPixelFormat); /* * We often need a displayable pixel format to make GDI happy. Set it @@ -493,7 +487,7 @@ DrvSetPixelFormat(HDC hdc, LONG iPixelFormat) return bPbuffer; } - fb = stw_framebuffer_create(hdc, iPixelFormat, STW_FRAMEBUFFER_WGL_WINDOW); + fb = stw_framebuffer_create(WindowFromDC(hdc), iPixelFormat, STW_FRAMEBUFFER_WGL_WINDOW); if (!fb) { return FALSE; } diff --git a/src/gallium/frontends/wgl/stw_framebuffer.h b/src/gallium/frontends/wgl/stw_framebuffer.h index be1b3371e9e..ee9faf5ef46 100644 --- a/src/gallium/frontends/wgl/stw_framebuffer.h +++ b/src/gallium/frontends/wgl/stw_framebuffer.h @@ -152,7 +152,7 @@ struct stw_framebuffer * must be called when done */ struct stw_framebuffer * -stw_framebuffer_create(HDC hdc, int iPixelFormat, enum stw_framebuffer_owner owner); +stw_framebuffer_create(HWND hwnd, int iPixelFormat, enum stw_framebuffer_owner owner); /** diff --git a/src/gallium/frontends/wgl/stw_winsys.h b/src/gallium/frontends/wgl/stw_winsys.h index 850560fa30d..66fb30eb8d4 100644 --- a/src/gallium/frontends/wgl/stw_winsys.h +++ b/src/gallium/frontends/wgl/stw_winsys.h @@ -131,7 +131,7 @@ struct stw_winsys */ struct stw_winsys_framebuffer * (*create_framebuffer)( struct pipe_screen *screen, - HDC hDC, + HWND hWnd, int iPixelFormat ); /** diff --git a/src/gallium/targets/libgl-d3d12/libgl_d3d12.c b/src/gallium/targets/libgl-d3d12/libgl_d3d12.c index e83dbb3a0f5..4bd5a2d474a 100644 --- a/src/gallium/targets/libgl-d3d12/libgl_d3d12.c +++ b/src/gallium/targets/libgl-d3d12/libgl_d3d12.c @@ -94,10 +94,10 @@ gdi_get_pfd_flags(struct pipe_screen *screen) static struct stw_winsys_framebuffer * gdi_create_framebuffer(struct pipe_screen *screen, - HDC hDC, + HWND hWnd, int iPixelFormat) { - return d3d12_wgl_create_framebuffer(screen, hDC, iPixelFormat); + return d3d12_wgl_create_framebuffer(screen, hWnd, iPixelFormat); } static const char * diff --git a/src/gallium/targets/wgl/wgl.c b/src/gallium/targets/wgl/wgl.c index 9d6dbeaf621..db8f59813b5 100644 --- a/src/gallium/targets/wgl/wgl.c +++ b/src/gallium/targets/wgl/wgl.c @@ -253,12 +253,12 @@ wgl_get_pfd_flags(struct pipe_screen *screen) static struct stw_winsys_framebuffer * wgl_create_framebuffer(struct pipe_screen *screen, - HDC hDC, + HWND hWnd, int iPixelFormat) { #ifdef GALLIUM_D3D12 if (use_d3d12) - return d3d12_wgl_create_framebuffer(screen, hDC, iPixelFormat); + return d3d12_wgl_create_framebuffer(screen, hWnd, iPixelFormat); #endif return NULL; } diff --git a/src/gallium/winsys/d3d12/wgl/d3d12_wgl_framebuffer.cpp b/src/gallium/winsys/d3d12/wgl/d3d12_wgl_framebuffer.cpp index b96dc52517f..e9a343b90e2 100644 --- a/src/gallium/winsys/d3d12/wgl/d3d12_wgl_framebuffer.cpp +++ b/src/gallium/winsys/d3d12/wgl/d3d12_wgl_framebuffer.cpp @@ -214,7 +214,7 @@ d3d12_wgl_framebuffer_get_resource(struct stw_winsys_framebuffer *pframebuffer, struct stw_winsys_framebuffer * d3d12_wgl_create_framebuffer(struct pipe_screen *screen, - HDC hDC, + HWND hWnd, int iPixelFormat) { const struct stw_pixelformat_info *pfi = @@ -229,7 +229,7 @@ d3d12_wgl_create_framebuffer(struct pipe_screen *screen, new (fb) struct d3d12_wgl_framebuffer(); - fb->window = WindowFromDC(hDC); + fb->window = hWnd; fb->screen = d3d12_screen(screen); fb->base.destroy = d3d12_wgl_framebuffer_destroy; fb->base.resize = d3d12_wgl_framebuffer_resize; diff --git a/src/gallium/winsys/d3d12/wgl/d3d12_wgl_public.h b/src/gallium/winsys/d3d12/wgl/d3d12_wgl_public.h index ac5f2c75476..a690ade7471 100644 --- a/src/gallium/winsys/d3d12/wgl/d3d12_wgl_public.h +++ b/src/gallium/winsys/d3d12/wgl/d3d12_wgl_public.h @@ -50,7 +50,7 @@ d3d12_wgl_get_pfd_flags(struct pipe_screen *screen); struct stw_winsys_framebuffer * d3d12_wgl_create_framebuffer(struct pipe_screen *screen, - HDC hDC, + HWND hWnd, int iPixelFormat); #ifdef __cplusplus