1 /* $Id: imports.h,v 1.6 2002/10/24 23:57:21 brianp 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 * This file provides wrappers for all the standard C library functions
30 * like malloc, free, printf, getenv, etc.
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)
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)
50 #define MEMCPY( DST, SRC, BYTES) _mesa_memcpy(DST, SRC, BYTES)
51 #define MEMSET( DST, VAL, N ) _mesa_memset(DST, VAL, N)
52 #define BZERO( ADDR, N ) _mesa_bzero(ADDR, N)
55 /* MACs and BeOS don't support static larger than 32kb, so... */
56 #if defined(macintosh) && !defined(__MRC__)
57 /*extern char *AGLAlloc(int size);*/
58 /*extern void AGLFree(char* ptr);*/
59 # define DEFARRAY(TYPE,NAME,SIZE) TYPE *NAME = (TYPE*)_mesa_alloc(sizeof(TYPE)*(SIZE))
60 # define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE (*NAME)[SIZE2] = (TYPE(*)[SIZE2])_mesa_alloc(sizeof(TYPE)*(SIZE1)*(SIZE2))
61 # define DEFMNARRAY(TYPE,NAME,SIZE1,SIZE2,SIZE3) TYPE (*NAME)[SIZE2][SIZE3] = (TYPE(*)[SIZE2][SIZE3])_mesa_alloc(sizeof(TYPE)*(SIZE1)*(SIZE2)*(SIZE3))
63 # define CHECKARRAY(NAME,CMD) do {if (!(NAME)) {CMD;}} while (0)
64 # define UNDEFARRAY(NAME) do {if ((NAME)) {_mesa_free((char*)NAME);} }while (0)
65 #elif defined(__BEOS__)
66 # define DEFARRAY(TYPE,NAME,SIZE) TYPE *NAME = (TYPE*)_mesa_malloc(sizeof(TYPE)*(SIZE))
67 # define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE (*NAME)[SIZE2] = (TYPE(*)[SIZE2])_mesa_malloc(sizeof(TYPE)*(SIZE1)*(SIZE2))
68 # define DEFMNARRAY(TYPE,NAME,SIZE1,SIZE2,SIZE3) TYPE (*NAME)[SIZE2][SIZE3] = (TYPE(*)[SIZE2][SIZE3])_mesa_malloc(sizeof(TYPE)*(SIZE1)*(SIZE2)*(SIZE3))
69 # define CHECKARRAY(NAME,CMD) do {if (!(NAME)) {CMD;}} while (0)
70 # define UNDEFARRAY(NAME) do {if ((NAME)) {_mesa_free((char*)NAME);} }while (0)
72 # define DEFARRAY(TYPE,NAME,SIZE) TYPE NAME[SIZE]
73 # define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE NAME[SIZE1][SIZE2]
74 # define DEFMNARRAY(TYPE,NAME,SIZE1,SIZE2,SIZE3) TYPE NAME[SIZE1][SIZE2][SIZE3]
75 # define CHECKARRAY(NAME,CMD) do {} while(0)
76 # define UNDEFARRAY(NAME)
80 #ifdef MESA_EXTERNAL_BUFFERALLOC
82 * If you want Mesa's depth/stencil/accum/etc buffers to be allocated
83 * with a specialized allocator you can define MESA_EXTERNAL_BUFFERALLOC
84 * and implement _ext_mesa_alloc/free_pixelbuffer() in your app.
85 * Contributed by Gerk Huisma (gerk@five-d.demon.nl).
87 extern void *_ext_mesa_alloc_pixelbuffer( unsigned int size
);
88 extern void _ext_mesa_free_pixelbuffer( void *pb
);
90 #define MESA_PBUFFER_ALLOC(BYTES) (void *) _ext_mesa_alloc_pixelbuffer(BYTES)
91 #define MESA_PBUFFER_FREE(PTR) _ext_mesa_free_pixelbuffer(PTR)
93 /* Default buffer allocation uses the aligned allocation routines: */
94 #define MESA_PBUFFER_ALLOC(BYTES) (void *) _mesa_align_malloc(BYTES, 512)
95 #define MESA_PBUFFER_FREE(PTR) _mesa_align_free(PTR)
100 _mesa_malloc( size_t bytes
);
103 _mesa_calloc( size_t bytes
);
106 _mesa_free( void *ptr
);
109 _mesa_align_malloc( size_t bytes
, unsigned long alignment
);
112 _mesa_align_calloc( size_t bytes
, unsigned long alignment
);
115 _mesa_align_free( void *ptr
);
118 _mesa_memcpy( void *dest
, const void *src
, size_t n
);
121 _mesa_memset( void *dst
, int val
, size_t n
);
124 _mesa_memset16( unsigned short *dst
, unsigned short val
, size_t n
);
127 _mesa_bzero( void *dst
, size_t n
);
131 _mesa_getenv( const char *var
);
134 _mesa_strstr( const char *haystack
, const char *needle
);
137 _mesa_atoi( const char *s
);
140 _mesa_sprintf( char *str
, const char *fmt
, ... );
143 _mesa_printf( const char *fmtString
, ... );
147 _mesa_warning( __GLcontext
*gc
, const char *fmtString
, ... );
150 _mesa_problem( const __GLcontext
*ctx
, const char *s
);
153 _mesa_error( __GLcontext
*ctx
, GLenum error
, const char *fmtString
, ... );
156 _mesa_debug( const __GLcontext
*ctx
, const char *fmtString
, ... );
160 _mesa_init_default_imports( __GLimports
*imports
, void *driverCtx
);
163 #endif /* IMPORTS_H */