xref: /aosp_15_r20/external/mesa3d/src/mapi/glapi/glapi_dispatch.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Mesa 3-D graphics library
3  *
4  * Copyright (C) 1999-2004  Brian Paul   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 "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 
26 /**
27  * \file glapi_dispatch.c
28  *
29  * This file generates all the gl* function entrypoints.  This code is not
30  * used if optimized assembly stubs are available (e.g., using
31  * glapi/glapi_x86.S on IA32 or glapi/glapi_sparc.S on SPARC).
32  *
33  * \note
34  * This file is also used to build the client-side libGL that loads DRI-based
35  * device drivers.  At build-time it is symlinked to src/glx.
36  *
37  * \author Brian Paul <[email protected]>
38  */
39 
40 #include "glapi/glapi_priv.h"
41 #include "glapitable.h"
42 
43 
44 #if !(defined(USE_X86_ASM) || defined(USE_X86_64_ASM) || defined(USE_SPARC_ASM))
45 
46 #if defined(_WIN32)
47 #define KEYWORD1 GLAPI
48 #else
49 #define KEYWORD1 PUBLIC
50 #endif
51 
52 #define KEYWORD2 GLAPIENTRY
53 
54 #define NAME(func)  gl##func
55 
56 #if 0  /* Use this to log GL calls to stdout (for debug only!) */
57 
58 #define F stdout
59 #define DISPATCH(FUNC, ARGS, MESSAGE)		\
60    fprintf MESSAGE;				\
61    GET_DISPATCH()->FUNC ARGS
62 
63 #define RETURN_DISPATCH(FUNC, ARGS, MESSAGE) 	\
64    fprintf MESSAGE;				\
65    return GET_DISPATCH()->FUNC ARGS
66 
67 #else
68 
69 #define DISPATCH(FUNC, ARGS, MESSAGE)		\
70    GET_DISPATCH()->FUNC ARGS
71 
72 #define RETURN_DISPATCH(FUNC, ARGS, MESSAGE) 	\
73    return GET_DISPATCH()->FUNC ARGS
74 
75 #endif /* logging */
76 
77 /* Enable frame pointer elimination on Windows, otherwise forgetting to add
78  * GLAPIENTRY to _mesa_* entrypoints will not cause crashes on debug builds, as
79  * the initial ESP value is saved in the EBP in the function prologue, then
80  * restored on the epilogue, clobbering any corruption in the ESP pointer due
81  * to mismatch in the callee calling convention.
82  *
83  * On MSVC it's not sufficient to enable /Oy -- other optimizations must be
84  * enabled or frame pointer will be used regardless.
85  *
86  * We don't do this when NDEBUG is defined since, frame pointer omission
87  * optimization compiler flag are already specified on release builds, and
88  * because on profile builds we must have frame pointers or certain profilers
89  * might fail to unwind the stack.
90  */
91 #if defined(_WIN32) && !defined(NDEBUG)
92 #  if defined(_MSC_VER)
93 #    pragma optimize( "gty", on )
94 #  elif defined(__GNUC__)
95 #    pragma GCC optimize ("omit-frame-pointer")
96 #  endif
97 #endif
98 
99 #include "glapitemp.h"
100 
101 #endif /* USE_X86_ASM */
102