bug fixes, added missing state query cases
[mesa.git] / src / mesa / main / imports.c
1 /* $Id: imports.c,v 1.9 2001/03/27 19:18:02 gareth Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28 /*
29 * Imports are functions which the device driver or window system or
30 * operating system provides to the core renderer. The core renderer (Mesa)
31 * will call these functions in order to do memory allocation, simple I/O,
32 * etc.
33 *
34 * Some drivers will need to implement these functions themselves but
35 * many (most?) Mesa drivers will be fine using these.
36 *
37 * A server-side GL renderer will likely not use these functions since
38 * the renderer should use the XFree86-wrapped system calls.
39 */
40
41
42 #include "glheader.h"
43 #include "imports.h"
44 #include "mem.h"
45 #include "mtypes.h"
46
47
48 static void *
49 _mesa_Malloc(__GLcontext *gc, size_t size)
50 {
51 return MALLOC(size);
52 }
53
54 static void *
55 _mesa_Calloc(__GLcontext *gc, size_t numElem, size_t elemSize)
56 {
57 return CALLOC(numElem * elemSize);
58 }
59
60 static void *
61 _mesa_Realloc(__GLcontext *gc, void *oldAddr, size_t newSize)
62 {
63 return realloc(oldAddr, newSize);
64 }
65
66 static void
67 _mesa_Free(__GLcontext *gc, void *addr)
68 {
69 FREE(addr);
70 }
71
72 /* Must be before '#undef getenv' for inclusion in XFree86.
73 */
74 static char *
75 _mesa_getenv(__GLcontext *gc, const char *var)
76 {
77 (void) gc;
78 return getenv(var);
79 }
80
81 static void
82 _mesa_warning(__GLcontext *gc, char *str)
83 {
84 GLboolean debug;
85 #ifdef DEBUG
86 debug = GL_TRUE;
87 #else
88 /* Whacko XFree86 macro:
89 */
90 #ifdef getenv
91 #undef getenv
92 #endif
93 if (gc->imports.getenv(gc, "MESA_DEBUG")) {
94 debug = GL_TRUE;
95 }
96 else {
97 debug = GL_FALSE;
98 }
99 #endif
100 if (debug) {
101 fprintf(stderr, "Mesa warning: %s\n", str);
102 }
103 }
104
105 static void
106 _mesa_fatal(__GLcontext *gc, char *str)
107 {
108 fprintf(stderr, "%s\n", str);
109 abort();
110 }
111
112 static int
113 _mesa_atoi(__GLcontext *gc, const char *str)
114 {
115 (void) gc;
116 return atoi(str);
117 }
118
119 static int
120 _mesa_sprintf(__GLcontext *gc, char *str, const char *fmt, ...)
121 {
122 /* XXX fix this */
123 return sprintf(str, fmt);
124 }
125
126 static void *
127 _mesa_fopen(__GLcontext *gc, const char *path, const char *mode)
128 {
129 return fopen(path, mode);
130 }
131
132 static int
133 _mesa_fclose(__GLcontext *gc, void *stream)
134 {
135 return fclose((FILE *) stream);
136 }
137
138 static int
139 _mesa_fprintf(__GLcontext *gc, void *stream, const char *fmt, ...)
140 {
141 /* XXX fix this */
142 return fprintf((FILE *) stream, fmt);
143 }
144
145 /* XXX this really is driver-specific and can't be here */
146 static __GLdrawablePrivate *
147 _mesa_GetDrawablePrivate(__GLcontext *gc)
148 {
149 return NULL;
150 }
151
152
153 void
154 _mesa_InitDefaultImports(__GLimports *imports, void *driverCtx, void *other)
155 {
156 imports->malloc = _mesa_Malloc;
157 imports->calloc = _mesa_Calloc;
158 imports->realloc = _mesa_Realloc;
159 imports->free = _mesa_Free;
160 imports->warning = _mesa_warning;
161 imports->fatal = _mesa_fatal;
162 imports->getenv = _mesa_getenv;
163 imports->atoi = _mesa_atoi;
164 imports->sprintf = _mesa_sprintf;
165 imports->fopen = _mesa_fopen;
166 imports->fclose = _mesa_fclose;
167 imports->fprintf = _mesa_fprintf;
168 imports->getDrawablePrivate = _mesa_GetDrawablePrivate;
169 /* imports->wscx = driverCtx; */
170 imports->other = driverCtx;
171 }