1 /* $Id: imports.c,v 1.6 2001/03/02 16:01:22 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
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,
34 * Some drivers will need to implement these functions themselves but
35 * many (most?) Mesa drivers will be fine using these.
37 * A server-side GL renderer will likely not use these functions since
38 * the renderer should use the XFree86-wrapped system calls.
49 _mesa_Malloc(__GLcontext
*gc
, size_t size
)
55 _mesa_Calloc(__GLcontext
*gc
, size_t numElem
, size_t elemSize
)
57 return CALLOC(numElem
* elemSize
);
61 _mesa_Realloc(__GLcontext
*gc
, void *oldAddr
, size_t newSize
)
63 return realloc(oldAddr
, newSize
);
67 _mesa_Free(__GLcontext
*gc
, void *addr
)
73 _mesa_warning(__GLcontext
*gc
, char *str
)
79 /* Whacko XFree86 macro:
84 if (gc
->imports
.getenv(gc
, "MESA_DEBUG")) {
92 fprintf(stderr
, "Mesa warning: %s\n", str
);
97 _mesa_fatal(__GLcontext
*gc
, char *str
)
99 fprintf(stderr
, "%s\n", str
);
104 _mesa_getenv(__GLcontext
*gc
, const char *var
)
111 _mesa_atoi(__GLcontext
*gc
, const char *str
)
118 _mesa_sprintf(__GLcontext
*gc
, char *str
, const char *fmt
, ...)
121 return sprintf(str
, fmt
);
125 _mesa_fopen(__GLcontext
*gc
, const char *path
, const char *mode
)
127 return fopen(path
, mode
);
131 _mesa_fclose(__GLcontext
*gc
, void *stream
)
133 return fclose(stream
);
137 _mesa_fprintf(__GLcontext
*gc
, void *stream
, const char *fmt
, ...)
140 return fprintf(stream
, fmt
);
143 /* XXX this really is driver-specific and can't be here */
144 static __GLdrawablePrivate
*
145 _mesa_GetDrawablePrivate(__GLcontext
*gc
)
152 _mesa_InitDefaultImports(__GLimports
*imports
, void *driverCtx
, void *other
)
154 imports
->malloc
= _mesa_Malloc
;
155 imports
->calloc
= _mesa_Calloc
;
156 imports
->realloc
= _mesa_Realloc
;
157 imports
->free
= _mesa_Free
;
158 imports
->warning
= _mesa_warning
;
159 imports
->fatal
= _mesa_fatal
;
160 imports
->getenv
= _mesa_getenv
;
161 imports
->atoi
= _mesa_atoi
;
162 imports
->sprintf
= _mesa_sprintf
;
163 imports
->fopen
= _mesa_fopen
;
164 imports
->fclose
= _mesa_fclose
;
165 imports
->fprintf
= _mesa_fprintf
;
166 imports
->getDrawablePrivate
= _mesa_GetDrawablePrivate
;
167 /* imports->wscx = driverCtx; */
168 imports
->other
= driverCtx
;