Module: Mesa Branch: main Commit: c205641ccf4a53a70860f5151092b5d4799379a5 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=c205641ccf4a53a70860f5151092b5d4799379a5
Author: Jesse Natalie <[email protected]> Date: Thu Sep 16 13:31:04 2021 -0700 wgl: Split pbuffer creation into two functions One creates a window and framebuffer, the other deals with wgl-specific attribute parsing and GDI interactions. Acked-by: Daniel Stone <[email protected]> Acked-by: Mike Blumenkrantz <[email protected]> Acked-by: Sidney Just <[email protected]> Acked-by: Jason Ekstrand <[email protected]> Tested-by: Yonggang Luo <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12964> --- src/gallium/frontends/wgl/stw_ext_pbuffer.c | 168 ++++++++++++++-------------- src/gallium/frontends/wgl/stw_framebuffer.h | 3 + src/gallium/targets/wgl/gallium_wgl.def.in | 1 + 3 files changed, 88 insertions(+), 84 deletions(-) diff --git a/src/gallium/frontends/wgl/stw_ext_pbuffer.c b/src/gallium/frontends/wgl/stw_ext_pbuffer.c index 9e0e564dbf1..824ce000ce8 100644 --- a/src/gallium/frontends/wgl/stw_ext_pbuffer.c +++ b/src/gallium/frontends/wgl/stw_ext_pbuffer.c @@ -65,6 +65,87 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return DefWindowProc(hWnd, uMsg, wParam, lParam); } +struct stw_framebuffer * +stw_pbuffer_create(int iPixelFormat, int iWidth, int iHeight) +{ + static boolean first = TRUE; + + /* + * Implement pbuffers through invisible windows + */ + + if (first) { + WNDCLASS wc; + memset(&wc, 0, sizeof wc); + wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); + wc.lpfnWndProc = WndProc; + wc.lpszClassName = "wglpbuffer"; + wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; + RegisterClass(&wc); + first = FALSE; + } + + DWORD dwExStyle = 0; + DWORD dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN; + + if (0) { + /* + * Don't hide the window -- useful for debugging what the application is + * drawing + */ + + dwStyle |= WS_VISIBLE | WS_OVERLAPPEDWINDOW; + } else { + dwStyle |= WS_POPUPWINDOW; + } + + RECT rect = { 0, 0, iWidth, iHeight }; + + /* + * The CreateWindowEx parameters are the total (outside) dimensions of the + * window, which can vary with Windows version and user settings. Use + * AdjustWindowRect to get the required total area for the given client area. + * + * AdjustWindowRectEx does not accept WS_OVERLAPPED style (which is defined + * as 0), which means we need to use some other style instead, e.g., + * WS_OVERLAPPEDWINDOW or WS_POPUPWINDOW as above. + */ + + AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle); + + HWND hWnd = CreateWindowEx(dwExStyle, + "wglpbuffer", /* wc.lpszClassName */ + NULL, + dwStyle, + CW_USEDEFAULT, /* x */ + CW_USEDEFAULT, /* y */ + rect.right - rect.left, /* width */ + rect.bottom - rect.top, /* height */ + NULL, + NULL, + NULL, + NULL); + if (!hWnd) { + return 0; + } + +#ifdef DEBUG + /* + * Verify the client area size matches the specified size. + */ + + GetClientRect(hWnd, &rect); + assert(rect.left == 0); + assert(rect.top == 0); + assert(rect.right - rect.left == iWidth); + assert(rect.bottom - rect.top == iHeight); +#endif + + return stw_framebuffer_create(hWnd, iPixelFormat, STW_FRAMEBUFFER_PBUFFER); +} + HPBUFFERARB WINAPI wglCreatePbufferARB(HDC hCurrentDC, @@ -73,14 +154,9 @@ wglCreatePbufferARB(HDC hCurrentDC, int iHeight, const int *piAttribList) { - static boolean first = TRUE; const int *piAttrib; int useLargest = 0; - const struct stw_pixelformat_info *info; struct stw_framebuffer *fb; - DWORD dwExStyle; - DWORD dwStyle; - RECT rect; HWND hWnd; int iDisplayablePixelFormat; PIXELFORMATDESCRIPTOR pfd; @@ -89,8 +165,7 @@ wglCreatePbufferARB(HDC hCurrentDC, int textureTarget = WGL_NO_TEXTURE_ARB; BOOL textureMipmap = FALSE; - info = stw_pixelformat_get_info(iPixelFormat); - if (!info) { + if (!stw_pixelformat_get_info(iPixelFormat)) { SetLastError(ERROR_INVALID_PIXEL_FORMAT); return 0; } @@ -162,87 +237,11 @@ wglCreatePbufferARB(HDC hCurrentDC, } } - /* - * Implement pbuffers through invisible windows - */ - - if (first) { - WNDCLASS wc; - memset(&wc, 0, sizeof wc); - wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); - wc.lpfnWndProc = WndProc; - wc.lpszClassName = "wglpbuffer"; - wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; - RegisterClass(&wc); - first = FALSE; - } - - dwExStyle = 0; - dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN; - - if (0) { - /* - * Don't hide the window -- useful for debugging what the application is - * drawing - */ - - dwStyle |= WS_VISIBLE | WS_OVERLAPPEDWINDOW; - } else { - dwStyle |= WS_POPUPWINDOW; - } - - rect.left = 0; - rect.top = 0; - rect.right = rect.left + iWidth; - rect.bottom = rect.top + iHeight; - - /* - * The CreateWindowEx parameters are the total (outside) dimensions of the - * window, which can vary with Windows version and user settings. Use - * AdjustWindowRect to get the required total area for the given client area. - * - * AdjustWindowRectEx does not accept WS_OVERLAPPED style (which is defined - * as 0), which means we need to use some other style instead, e.g., - * WS_OVERLAPPEDWINDOW or WS_POPUPWINDOW as above. - */ - - AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle); - - hWnd = CreateWindowEx(dwExStyle, - "wglpbuffer", /* wc.lpszClassName */ - NULL, - dwStyle, - CW_USEDEFAULT, /* x */ - CW_USEDEFAULT, /* y */ - rect.right - rect.left, /* width */ - rect.bottom - rect.top, /* height */ - NULL, - NULL, - NULL, - NULL); - if (!hWnd) { - return 0; - } - -#ifdef DEBUG - /* - * Verify the client area size matches the specified size. - */ - - GetClientRect(hWnd, &rect); - assert(rect.left == 0); - assert(rect.top == 0); - assert(rect.right - rect.left == iWidth); - assert(rect.bottom - rect.top == iHeight); -#endif - /* * 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(hWnd, iPixelFormat, STW_FRAMEBUFFER_PBUFFER); + fb = stw_pbuffer_create(iPixelFormat, iWidth, iHeight); if (!fb) { SetLastError(ERROR_NO_SYSTEM_RESOURCES); return NULL; @@ -254,6 +253,7 @@ wglCreatePbufferARB(HDC hCurrentDC, fb->textureMipmap = textureMipmap; iDisplayablePixelFormat = fb->iDisplayablePixelFormat; + hWnd = fb->hWnd; stw_framebuffer_unlock(fb); diff --git a/src/gallium/frontends/wgl/stw_framebuffer.h b/src/gallium/frontends/wgl/stw_framebuffer.h index 932c8e0925f..db8a82a6851 100644 --- a/src/gallium/frontends/wgl/stw_framebuffer.h +++ b/src/gallium/frontends/wgl/stw_framebuffer.h @@ -154,6 +154,9 @@ struct stw_framebuffer struct stw_framebuffer * stw_framebuffer_create(HWND hwnd, int iPixelFormat, enum stw_framebuffer_owner owner); +struct stw_framebuffer * +stw_pbuffer_create(int iPixelFormat, int iWidth, int iHeight); + /** * Increase fb reference count. The referenced framebuffer should be locked. diff --git a/src/gallium/targets/wgl/gallium_wgl.def.in b/src/gallium/targets/wgl/gallium_wgl.def.in index 860389d48cc..109016b4cc7 100644 --- a/src/gallium/targets/wgl/gallium_wgl.def.in +++ b/src/gallium/targets/wgl/gallium_wgl.def.in @@ -37,3 +37,4 @@ stw_framebuffer_create stw_framebuffer_release_locked stw_framebuffer_unlock stw_framebuffer_swap_locked +stw_pbuffer_create
