new X86 CPU detection code (Petr Sebor)
[mesa.git] / src / mesa / main / imports.h
1 /* $Id: imports.h,v 1.11 2003/01/14 03:05:38 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 5.1
6 *
7 * Copyright (C) 1999-2002 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 * This file provides wrappers for all the standard C library functions
30 * like malloc, free, printf, getenv, etc.
31 */
32
33
34 #ifndef IMPORTS_H
35 #define IMPORTS_H
36
37
38 #define MALLOC(BYTES) _mesa_malloc(BYTES)
39 #define CALLOC(BYTES) _mesa_calloc(BYTES)
40 #define MALLOC_STRUCT(T) (struct T *) _mesa_malloc(sizeof(struct T))
41 #define CALLOC_STRUCT(T) (struct T *) _mesa_calloc(sizeof(struct T))
42 #define FREE(PTR) _mesa_free(PTR)
43
44 #define ALIGN_MALLOC(BYTES, N) _mesa_align_malloc(BYTES, N)
45 #define ALIGN_CALLOC(BYTES, N) _mesa_align_calloc(BYTES, N)
46 #define ALIGN_MALLOC_STRUCT(T, N) (struct T *) _mesa_align_malloc(sizeof(struct T), N)
47 #define ALIGN_CALLOC_STRUCT(T, N) (struct T *) _mesa_align_calloc(sizeof(struct T), N)
48 #define ALIGN_FREE(PTR) _mesa_align_free(PTR)
49
50 #define MEMCPY( DST, SRC, BYTES) _mesa_memcpy(DST, SRC, BYTES)
51 #define MEMSET( DST, VAL, N ) _mesa_memset(DST, VAL, N)
52 extern void _mesa_memset16( GLushort *dst, GLushort val, size_t n );
53
54 #define MEMSET16( DST, VAL, N ) \
55 _mesa_memset16( (GLushort *) (DST), (GLushort) (VAL), (size_t) (N) )
56
57
58 /* MACs and BeOS don't support static larger than 32kb, so... */
59 #if defined(macintosh) && !defined(__MRC__)
60 /*extern char *AGLAlloc(int size);*/
61 /*extern void AGLFree(char* ptr);*/
62 # define DEFARRAY(TYPE,NAME,SIZE) TYPE *NAME = (TYPE*)_mesa_alloc(sizeof(TYPE)*(SIZE))
63 # define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE (*NAME)[SIZE2] = (TYPE(*)[SIZE2])_mesa_alloc(sizeof(TYPE)*(SIZE1)*(SIZE2))
64 # define DEFMNARRAY(TYPE,NAME,SIZE1,SIZE2,SIZE3) TYPE (*NAME)[SIZE2][SIZE3] = (TYPE(*)[SIZE2][SIZE3])_mesa_alloc(sizeof(TYPE)*(SIZE1)*(SIZE2)*(SIZE3))
65
66 # define CHECKARRAY(NAME,CMD) do {if (!(NAME)) {CMD;}} while (0)
67 # define UNDEFARRAY(NAME) do {if ((NAME)) {_mesa_free((char*)NAME);} }while (0)
68 #elif defined(__BEOS__)
69 # define DEFARRAY(TYPE,NAME,SIZE) TYPE *NAME = (TYPE*)_mesa_malloc(sizeof(TYPE)*(SIZE))
70 # define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE (*NAME)[SIZE2] = (TYPE(*)[SIZE2])_mesa_malloc(sizeof(TYPE)*(SIZE1)*(SIZE2))
71 # define DEFMNARRAY(TYPE,NAME,SIZE1,SIZE2,SIZE3) TYPE (*NAME)[SIZE2][SIZE3] = (TYPE(*)[SIZE2][SIZE3])_mesa_malloc(sizeof(TYPE)*(SIZE1)*(SIZE2)*(SIZE3))
72 # define CHECKARRAY(NAME,CMD) do {if (!(NAME)) {CMD;}} while (0)
73 # define UNDEFARRAY(NAME) do {if ((NAME)) {_mesa_free((char*)NAME);} }while (0)
74 #else
75 # define DEFARRAY(TYPE,NAME,SIZE) TYPE NAME[SIZE]
76 # define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE NAME[SIZE1][SIZE2]
77 # define DEFMNARRAY(TYPE,NAME,SIZE1,SIZE2,SIZE3) TYPE NAME[SIZE1][SIZE2][SIZE3]
78 # define CHECKARRAY(NAME,CMD) do {} while(0)
79 # define UNDEFARRAY(NAME)
80 #endif
81
82
83 #ifdef MESA_EXTERNAL_BUFFERALLOC
84 /*
85 * If you want Mesa's depth/stencil/accum/etc buffers to be allocated
86 * with a specialized allocator you can define MESA_EXTERNAL_BUFFERALLOC
87 * and implement _ext_mesa_alloc/free_pixelbuffer() in your app.
88 * Contributed by Gerk Huisma (gerk@five-d.demon.nl).
89 */
90 extern void *_ext_mesa_alloc_pixelbuffer( unsigned int size );
91 extern void _ext_mesa_free_pixelbuffer( void *pb );
92
93 #define MESA_PBUFFER_ALLOC(BYTES) (void *) _ext_mesa_alloc_pixelbuffer(BYTES)
94 #define MESA_PBUFFER_FREE(PTR) _ext_mesa_free_pixelbuffer(PTR)
95 #else
96 /* Default buffer allocation uses the aligned allocation routines: */
97 #define MESA_PBUFFER_ALLOC(BYTES) (void *) _mesa_align_malloc(BYTES, 512)
98 #define MESA_PBUFFER_FREE(PTR) _mesa_align_free(PTR)
99 #endif
100
101
102 extern void *
103 _mesa_malloc( size_t bytes );
104
105 extern void *
106 _mesa_calloc( size_t bytes );
107
108 extern void
109 _mesa_free( void *ptr );
110
111 extern void *
112 _mesa_align_malloc( size_t bytes, unsigned long alignment );
113
114 extern void *
115 _mesa_align_calloc( size_t bytes, unsigned long alignment );
116
117 extern void
118 _mesa_align_free( void *ptr );
119
120 extern void *
121 _mesa_memcpy( void *dest, const void *src, size_t n );
122
123 extern void
124 _mesa_memset( void *dst, int val, size_t n );
125
126 extern void
127 _mesa_memset16( unsigned short *dst, unsigned short val, size_t n );
128
129 extern void
130 _mesa_bzero( void *dst, size_t n );
131
132
133 extern double
134 _mesa_sin(double a);
135
136 extern double
137 _mesa_cos(double a);
138
139 extern double
140 _mesa_sqrt(double x);
141
142 extern double
143 _mesa_pow(double x, double y);
144
145
146 extern char *
147 _mesa_getenv( const char *var );
148
149 extern char *
150 _mesa_strstr( const char *haystack, const char *needle );
151
152 extern char *
153 _mesa_strncat( char *dest, const char *src, size_t n );
154
155 extern char *
156 _mesa_strcpy( char *dest, const char *src );
157
158 extern char *
159 _mesa_strncpy( char *dest, const char *src, size_t n );
160
161 extern size_t
162 _mesa_strlen( const char *s );
163
164 extern int
165 _mesa_strcmp( const char *s1, const char *s2 );
166
167 extern int
168 _mesa_strncmp( const char *s1, const char *s2, size_t n );
169
170 extern char *
171 _mesa_strdup( const char *s );
172
173 extern int
174 _mesa_atoi( const char *s );
175
176 extern float
177 _mesa_strtof( const char *s, char **end );
178
179 extern int
180 _mesa_sprintf( char *str, const char *fmt, ... );
181
182 extern void
183 _mesa_printf( const char *fmtString, ... );
184
185
186 extern void
187 _mesa_warning( __GLcontext *gc, const char *fmtString, ... );
188
189 extern void
190 _mesa_problem( const __GLcontext *ctx, const char *fmtString, ... );
191
192 extern void
193 _mesa_error( __GLcontext *ctx, GLenum error, const char *fmtString, ... );
194
195 extern void
196 _mesa_debug( const __GLcontext *ctx, const char *fmtString, ... );
197
198
199 extern void
200 _mesa_init_default_imports( __GLimports *imports, void *driverCtx );
201
202
203 #endif /* IMPORTS_H */
204