Subversion Repositories shark

Rev

Rev 72 | Details | Compare with Previous | Last modification | View Log | RSS feed

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