1 /* $Id: imports.c,v 1.14 2002/06/18 08:35:25 joukj Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 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 want to provide a specialed __GLimport object, but
35 * most Mesa drivers will be able to call _mesa_init_default_imports()
38 * A server-side GL renderer will likely not use these functions since
39 * the renderer should use the XFree86-wrapped system calls.
43 * XXX when we fully implement the __GLimports mechanism in Mesa, that
44 * should mean that we can remove <stdio.h>, <stdlib.h>, etc, from
45 * glheader.h. Strictly speaking, all system includes should be done
46 * from this file, and not glheader to ensure that core Mesa has no
47 * dependencies on external libraries. Someday...
59 _mesa_Malloc(__GLcontext
*gc
, size_t size
)
65 _mesa_Calloc(__GLcontext
*gc
, size_t numElem
, size_t elemSize
)
67 return CALLOC(numElem
* elemSize
);
71 _mesa_Realloc(__GLcontext
*gc
, void *oldAddr
, size_t newSize
)
73 return realloc(oldAddr
, newSize
);
77 _mesa_Free(__GLcontext
*gc
, void *addr
)
82 /* Must be before '#undef getenv' for inclusion in XFree86.
85 _mesa_getenv(__GLcontext
*gc
, const char *var
)
92 _mesa_warning(__GLcontext
*gc
, char *str
)
98 /* Whacko XFree86 macro:
103 if (gc
->imports
.getenv(gc
, "MESA_DEBUG")) {
111 fprintf(stderr
, "Mesa warning: %s\n", str
);
116 _mesa_fatal(__GLcontext
*gc
, char *str
)
118 fprintf(stderr
, "%s\n", str
);
123 _mesa_atoi(__GLcontext
*gc
, const char *str
)
130 _mesa_sprintf(__GLcontext
*gc
, char *str
, const char *fmt
, ...)
134 va_start( args
, fmt
);
135 r
= vsprintf( str
, fmt
, args
);
141 _mesa_fopen(__GLcontext
*gc
, const char *path
, const char *mode
)
143 return fopen(path
, mode
);
147 _mesa_fclose(__GLcontext
*gc
, void *stream
)
149 return fclose((FILE *) stream
);
153 _mesa_fprintf(__GLcontext
*gc
, void *stream
, const char *fmt
, ...)
157 va_start( args
, fmt
);
158 r
= vfprintf( (FILE *) stream
, fmt
, args
);
163 /* XXX this really is driver-specific and can't be here */
164 static __GLdrawablePrivate
*
165 _mesa_GetDrawablePrivate(__GLcontext
*gc
)
172 _mesa_init_default_imports(__GLimports
*imports
, void *driverCtx
)
174 imports
->malloc
= _mesa_Malloc
;
175 imports
->calloc
= _mesa_Calloc
;
176 imports
->realloc
= _mesa_Realloc
;
177 imports
->free
= _mesa_Free
;
178 imports
->warning
= _mesa_warning
;
179 imports
->fatal
= _mesa_fatal
;
180 imports
->getenv
= _mesa_getenv
;
181 imports
->atoi
= _mesa_atoi
;
182 imports
->sprintf
= _mesa_sprintf
;
183 imports
->fopen
= _mesa_fopen
;
184 imports
->fclose
= _mesa_fclose
;
185 imports
->fprintf
= _mesa_fprintf
;
186 imports
->getDrawablePrivate
= _mesa_GetDrawablePrivate
;
187 imports
->other
= driverCtx
;