From edfc7f0de0ac5eb8b2051bccfb567da981cf4957 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 28 Jun 2012 16:14:55 +0200 Subject: [PATCH] opengl32: Move wglGetProcAddress to the WGL driver. --- dlls/gdi32/gdi32.spec | 5 ----- dlls/gdi32/opengl.c | 40 --------------------------------------- dlls/opengl32/wgl.c | 25 ++++++------------------ dlls/wined3d/directx.c | 20 +++++++++----------- dlls/wined3d/wined3d_gl.h | 2 +- dlls/winex11.drv/opengl.c | 11 ++++------- include/wine/gdi_driver.h | 3 ++- 7 files changed, 22 insertions(+), 84 deletions(-) diff --git a/dlls/gdi32/gdi32.spec b/dlls/gdi32/gdi32.spec index 9dfa4dd0a4..1e30485b85 100644 --- a/dlls/gdi32/gdi32.spec +++ b/dlls/gdi32/gdi32.spec @@ -496,11 +496,6 @@ @ extern pfnSelectPalette @ stub pstackConnect -################################################################ -# Wine extensions: OpenGL support -# -@ stdcall -private wglGetProcAddress(str) - ################################################################ # Wine extensions: Win16 functions that are needed by other dlls # diff --git a/dlls/gdi32/opengl.c b/dlls/gdi32/opengl.c index 95db11dcf8..1db261e14b 100644 --- a/dlls/gdi32/opengl.c +++ b/dlls/gdi32/opengl.c @@ -46,46 +46,6 @@ static INT (WINAPI *wglGetPixelFormat)(HDC); static BOOL (WINAPI *wglSetPixelFormat)(HDC,INT,const PIXELFORMATDESCRIPTOR*); static BOOL (WINAPI *wglSwapBuffers)(HDC); -static HDC default_hdc = 0; - -/* We route all wgl functions from opengl32.dll through gdi32.dll to - * the display driver. Various wgl calls have a hDC as one of their parameters. - * Using get_dc_ptr we get access to the functions exported by the driver. - * Some functions don't receive a hDC. This function creates a global hdc and - * if there's already a global hdc, it returns it. - */ -static DC* OPENGL_GetDefaultDC(void) -{ - if(!default_hdc) - default_hdc = CreateDCA("DISPLAY", NULL, NULL, NULL); - - return get_dc_ptr(default_hdc); -} - -/*********************************************************************** - * Internal wglGetProcAddress for retrieving WGL extensions - */ -PROC WINAPI wglGetProcAddress(LPCSTR func) -{ - PROC ret = NULL; - DC *dc; - - if(!func) - return NULL; - - TRACE("func: '%s'\n", func); - - /* Retrieve the global hDC to get access to the driver. */ - dc = OPENGL_GetDefaultDC(); - if (dc) - { - PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglGetProcAddress ); - ret = physdev->funcs->pwglGetProcAddress(func); - release_dc_ptr( dc ); - } - return ret; -} - /*********************************************************************** * __wine_get_wgl_driver (GDI32.@) */ diff --git a/dlls/opengl32/wgl.c b/dlls/opengl32/wgl.c index 0a19506124..4d5510fdd6 100644 --- a/dlls/opengl32/wgl.c +++ b/dlls/opengl32/wgl.c @@ -48,8 +48,6 @@ WINE_DECLARE_DEBUG_CHANNEL(opengl); static struct { - PROC (WINAPI *p_wglGetProcAddress)(LPCSTR lpszProc); - /* internal WGL functions */ void (WINAPI *p_wglFinish)(void); void (WINAPI *p_wglFlush)(void); @@ -508,7 +506,7 @@ PROC WINAPI wglGetProcAddress(LPCSTR lpszProc) { /* If the function name starts with a 'w', it is a WGL extension */ if(lpszProc[0] == 'w') { - local_func = wine_wgl.p_wglGetProcAddress( lpszProc ); + local_func = wgl_driver->p_wglGetProcAddress( lpszProc ); if (local_func == (void *)1) /* special function that needs a wrapper */ { ext_ret = bsearch( &ext, wgl_extensions, sizeof(wgl_extensions)/sizeof(wgl_extensions[0]), @@ -531,7 +529,7 @@ PROC WINAPI wglGetProcAddress(LPCSTR lpszProc) { WARN("Extension '%s' required by function '%s' not supported!\n", ext_ret->extension, lpszProc); } - local_func = wine_wgl.p_wglGetProcAddress(ext_ret->name); + local_func = wgl_driver->p_wglGetProcAddress(ext_ret->name); /* After that, look at the extensions defined in the Linux OpenGL library */ if (local_func == NULL) { @@ -1113,27 +1111,16 @@ BOOL WINAPI DECLSPEC_HOTPATCH wglSwapBuffers( HDC hdc ) creating a rendering context.... */ static BOOL process_attach(void) { - HMODULE mod_gdi32; HDC hdc = GetDC( 0 ); wgl_driver = __wine_get_wgl_driver( hdc, WINE_GDI_DRIVER_VERSION ); ReleaseDC( 0, hdc ); - mod_gdi32 = GetModuleHandleA( "gdi32.dll" ); - - if (!mod_gdi32) - { - ERR("GDI32 not loaded. Cannot create default context.\n"); - return FALSE; - } - - wine_wgl.p_wglGetProcAddress = (void *)GetProcAddress(mod_gdi32, "wglGetProcAddress"); - /* internal WGL functions */ - wine_wgl.p_wglFinish = (void *)wine_wgl.p_wglGetProcAddress("wglFinish"); - wine_wgl.p_wglFlush = (void *)wine_wgl.p_wglGetProcAddress("wglFlush"); - wine_wgl.p_wglGetCurrentContext = (void *)wine_wgl.p_wglGetProcAddress("wglGetCurrentContext"); - wine_wgl.p_wglGetIntegerv = (void *)wine_wgl.p_wglGetProcAddress("wglGetIntegerv"); + wine_wgl.p_wglFinish = (void *)wgl_driver->p_wglGetProcAddress("wglFinish"); + wine_wgl.p_wglFlush = (void *)wgl_driver->p_wglGetProcAddress("wglFlush"); + wine_wgl.p_wglGetCurrentContext = (void *)wgl_driver->p_wglGetProcAddress("wglGetCurrentContext"); + wine_wgl.p_wglGetIntegerv = (void *)wgl_driver->p_wglGetProcAddress("wglGetIntegerv"); return TRUE; } diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index f576b3316b..1cce96b11a 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -27,6 +27,9 @@ #include #include "wined3d_private.h" +#ifndef USE_WIN32_OPENGL +#include "wine/gdi_driver.h" +#endif WINE_DEFAULT_DEBUG_CHANNEL(d3d); @@ -5386,15 +5389,15 @@ static BOOL InitAdapters(struct wined3d *wined3d) #define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, #pfn); #else /* To bypass the opengl32 thunks load wglGetProcAddress from gdi32 instead of opengl32 */ - pwglGetProcAddress = (void*)GetProcAddress(GetModuleHandleA("gdi32.dll"), "wglGetProcAddress"); + { + HDC hdc = GetDC( 0 ); + const struct wgl_funcs *wgl_driver = __wine_get_wgl_driver( hdc, WINE_GDI_DRIVER_VERSION ); + pwglGetProcAddress = wgl_driver->p_wglGetProcAddress; + ReleaseDC( 0, hdc ); + } #define USE_GL_FUNC(pfn) pfn = (void*)pwglGetProcAddress(#pfn); #endif - if(!pwglGetProcAddress) { - ERR("Unable to load wglGetProcAddress!\n"); - goto nogl_adapter; - } - /* Load WGL core functions from opengl32.dll */ #define USE_WGL_FUNC(pfn) p##pfn = (void*)GetProcAddress(mod_gl, #pfn); WGL_FUNCS_GEN; @@ -5407,13 +5410,8 @@ static BOOL InitAdapters(struct wined3d *wined3d) /* Load glFinish and glFlush from opengl32.dll even if we're not using WIN32 opengl * otherwise because we have to use winex11.drv's override */ -#ifdef USE_WIN32_OPENGL wglFinish = (void*)GetProcAddress(mod_gl, "glFinish"); wglFlush = (void*)GetProcAddress(mod_gl, "glFlush"); -#else - wglFinish = (void*)pwglGetProcAddress("wglFinish"); - wglFlush = (void*)pwglGetProcAddress("wglFlush"); -#endif glEnableWINE = glEnable; glDisableWINE = glDisable; diff --git a/dlls/wined3d/wined3d_gl.h b/dlls/wined3d/wined3d_gl.h index 51281e4a00..b8e2195112 100644 --- a/dlls/wined3d/wined3d_gl.h +++ b/dlls/wined3d/wined3d_gl.h @@ -1369,7 +1369,7 @@ HGLRC (WINAPI *pwglCreateContext)(HDC) DECLSPEC_HIDDEN; BOOL (WINAPI *pwglDeleteContext)(HGLRC) DECLSPEC_HIDDEN; HGLRC (WINAPI *pwglGetCurrentContext)(void) DECLSPEC_HIDDEN; HDC (WINAPI *pwglGetCurrentDC)(void) DECLSPEC_HIDDEN; -PROC (WINAPI *pwglGetProcAddress)(LPCSTR) DECLSPEC_HIDDEN; +PROC (WINE_GLAPI *pwglGetProcAddress)(LPCSTR) DECLSPEC_HIDDEN; BOOL (WINAPI *pwglMakeCurrent)(HDC, HGLRC) DECLSPEC_HIDDEN; BOOL (WINAPI *pwglShareLists)(HGLRC, HGLRC) DECLSPEC_HIDDEN; diff --git a/dlls/winex11.drv/opengl.c b/dlls/winex11.drv/opengl.c index 5f7c3d7c3c..10cd5ef805 100644 --- a/dlls/winex11.drv/opengl.c +++ b/dlls/winex11.drv/opengl.c @@ -1521,10 +1521,8 @@ static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void) return ret; } -/** - * glxdrv_wglGetProcAddress - * - * For OpenGL32 wglGetProcAddress. +/*********************************************************************** + * glxdrv_wglGetProcAddress */ static PROC glxdrv_wglGetProcAddress(LPCSTR lpszProc) { @@ -1535,8 +1533,6 @@ static PROC glxdrv_wglGetProcAddress(LPCSTR lpszProc) if (padding < 0) padding = 0; - if (!has_opengl()) return NULL; - /* Check the table of WGL extensions to see if we need to return a WGL extension * or a function pointer to a native OpenGL function. */ if(strncmp(lpszProc, "wgl", 3) != 0) { @@ -3596,7 +3592,7 @@ static const struct gdi_dc_funcs glxdrv_funcs = NULL, /* pWidenPath */ NULL, /* pwglCreateContext */ NULL, /* pwglCreateContextAttribsARB */ - glxdrv_wglGetProcAddress, /* pwglGetProcAddress */ + NULL, /* pwglGetProcAddress */ glxdrv_wine_get_wgl_driver, /* wine_get_wgl_driver */ GDI_PRIORITY_GRAPHICS_DRV + 20 /* priority */ }; @@ -3609,6 +3605,7 @@ static const struct wgl_funcs glxdrv_wgl_funcs = glxdrv_wglCreateContextAttribsARB, /* p_wglCreateContextAttribsARB */ glxdrv_wglDeleteContext, /* p_wglDeleteContext */ glxdrv_wglGetCurrentDC, /* p_wglGetCurrentDC */ + glxdrv_wglGetProcAddress, /* p_wglGetProcAddress */ glxdrv_wglMakeContextCurrentARB, /* p_wglMakeContextCurrentARB */ glxdrv_wglMakeCurrent, /* p_wglMakeCurrent */ glxdrv_wglShareLists, /* p_wglShareLists */ diff --git a/include/wine/gdi_driver.h b/include/wine/gdi_driver.h index 4f8d0f1ebc..1476bebf7e 100644 --- a/include/wine/gdi_driver.h +++ b/include/wine/gdi_driver.h @@ -203,7 +203,7 @@ struct gdi_dc_funcs }; /* increment this when you change the DC function table */ -#define WINE_GDI_DRIVER_VERSION 37 +#define WINE_GDI_DRIVER_VERSION 38 #define GDI_PRIORITY_NULL_DRV 0 /* null driver */ #define GDI_PRIORITY_FONT_DRV 100 /* any font driver */ @@ -239,6 +239,7 @@ struct wgl_funcs HGLRC (*p_wglCreateContextAttribsARB)(HDC,HGLRC,const int*); BOOL (*p_wglDeleteContext)(HGLRC); HDC (*p_wglGetCurrentDC)(void); + PROC (*p_wglGetProcAddress)(LPCSTR); BOOL (*p_wglMakeContextCurrentARB)(HDC,HDC,HGLRC); BOOL (*p_wglMakeCurrent)(HDC,HGLRC); BOOL (*p_wglShareLists)(HGLRC,HGLRC); -- 2.32.0.93.g670b81a890