xref: /aosp_15_r20/external/mesa3d/src/gallium/frontends/wgl/stw_getprocaddress.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /**************************************************************************
2  *
3  * Copyright 2008 VMware, Inc.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 
28 #include <windows.h>
29 
30 #define WGL_WGLEXT_PROTOTYPES
31 
32 #include <GL/gl.h>
33 #include <GL/wglext.h>
34 #include <GL/mesa_glinterop.h>
35 
36 #include "glapi/glapi.h"
37 #include "stw_device.h"
38 #include "stw_gdishim.h"
39 #include "gldrv.h"
40 #include "stw_nopfuncs.h"
41 
42 #include "util/u_debug.h"
43 
44 struct stw_extension_entry
45 {
46    const char *name;
47    PROC proc;
48 };
49 
50 #define STW_EXTENSION_ENTRY(P) { #P, (PROC) P }
51 
52 static const struct stw_extension_entry stw_extension_entries[] = {
53 
54    /* WGL_ARB_extensions_string */
55    STW_EXTENSION_ENTRY( wglGetExtensionsStringARB ),
56 
57    /* WGL_ARB_pbuffer */
58    STW_EXTENSION_ENTRY( wglCreatePbufferARB ),
59    STW_EXTENSION_ENTRY( wglGetPbufferDCARB ),
60    STW_EXTENSION_ENTRY( wglReleasePbufferDCARB ),
61    STW_EXTENSION_ENTRY( wglDestroyPbufferARB ),
62    STW_EXTENSION_ENTRY( wglQueryPbufferARB ),
63 
64    /* WGL_ARB_pixel_format */
65    STW_EXTENSION_ENTRY( wglChoosePixelFormatARB ),
66    STW_EXTENSION_ENTRY( wglGetPixelFormatAttribfvARB ),
67    STW_EXTENSION_ENTRY( wglGetPixelFormatAttribivARB ),
68 
69    /* WGL_EXT_extensions_string */
70    STW_EXTENSION_ENTRY( wglGetExtensionsStringEXT ),
71 
72    /* WGL_EXT_swap_control */
73    STW_EXTENSION_ENTRY( wglGetSwapIntervalEXT ),
74    STW_EXTENSION_ENTRY( wglSwapIntervalEXT ),
75 
76    /* WGL_ARB_create_context */
77    STW_EXTENSION_ENTRY( wglCreateContextAttribsARB ),
78 
79    /* WGL_ARB_render_texture */
80    STW_EXTENSION_ENTRY( wglBindTexImageARB ),
81    STW_EXTENSION_ENTRY( wglReleaseTexImageARB ),
82    STW_EXTENSION_ENTRY( wglSetPbufferAttribARB ),
83 
84    /*  WGL_ARB_make_current_read */
85    STW_EXTENSION_ENTRY( wglMakeContextCurrentARB ),
86    STW_EXTENSION_ENTRY( wglGetCurrentReadDCARB ),
87 
88    /* Unnamed */
89    STW_EXTENSION_ENTRY( wglMesaGLInteropQueryDeviceInfo ),
90    STW_EXTENSION_ENTRY( wglMesaGLInteropExportObject ),
91    STW_EXTENSION_ENTRY( wglMesaGLInteropFlushObjects ),
92    { NULL, NULL }
93 };
94 
95 PROC APIENTRY
DrvGetProcAddress(LPCSTR lpszProc)96 DrvGetProcAddress(
97    LPCSTR lpszProc )
98 {
99    const struct stw_extension_entry *entry;
100    PROC p;
101 
102    if (!stw_dev)
103       return NULL;
104 
105    if (lpszProc[0] == 'w' && lpszProc[1] == 'g' && lpszProc[2] == 'l')
106       for (entry = stw_extension_entries; entry->name; entry++)
107          if (strcmp( lpszProc, entry->name ) == 0)
108             return entry->proc;
109 
110    if (lpszProc[0] == 'g' && lpszProc[1] == 'l') {
111       p = (PROC) _glapi_get_proc_address(lpszProc);
112       if (p)
113          return p;
114    }
115 
116    /* If we get here, we'd normally just return NULL, but since some apps
117     * (like Viewperf12) crash when they try to use the null pointer, try
118     * returning a pointer to a no-op function instead.
119     */
120    p = stw_get_nop_function(lpszProc);
121    if (p) {
122       debug_printf("wglGetProcAddress(\"%s\") returning no-op function\n",
123                    lpszProc);
124       return p;
125    }
126 
127    debug_printf("wglGetProcAddress(\"%s\") returning NULL\n", lpszProc);
128    return NULL;
129 }
130