summaryrefslogtreecommitdiff
path: root/src/mesa/main/imports.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main/imports.c')
-rw-r--r--src/mesa/main/imports.c264
1 files changed, 71 insertions, 193 deletions
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index 9c7ebf9287..e2d44fa07c 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -24,9 +24,6 @@
* - scanf
* - qsort
* - rand and RAND_MAX
- *
- * \note When compiled into a XFree86 module these functions wrap around
- * XFree86 own wrappers.
*/
/*
@@ -71,50 +68,29 @@ extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
#endif
#endif
-/* If we don't actually want to use the libcwrapper junk (even though we're
- * building an Xorg server module), then just undef IN_MODULE to signal that to
- * the following code. It's left around for now to allow compiling of newish
- * Mesa with older servers, but this whole mess should go away at some point.
- */
-#ifdef NO_LIBCWRAPPER
-#undef IN_MODULE
-#endif
-
/**********************************************************************/
/** \name Memory */
/*@{*/
-/** Wrapper around either malloc() or xf86malloc() */
+/** Wrapper around malloc() */
void *
_mesa_malloc(size_t bytes)
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86malloc(bytes);
-#else
return malloc(bytes);
-#endif
}
-/** Wrapper around either calloc() or xf86calloc() */
+/** Wrapper around calloc() */
void *
_mesa_calloc(size_t bytes)
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86calloc(1, bytes);
-#else
return calloc(1, bytes);
-#endif
}
-/** Wrapper around either free() or xf86free() */
+/** Wrapper around free() */
void
_mesa_free(void *ptr)
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- xf86free(ptr);
-#else
free(ptr);
-#endif
}
/**
@@ -131,7 +107,7 @@ _mesa_free(void *ptr)
void *
_mesa_align_malloc(size_t bytes, unsigned long alignment)
{
-#if defined(HAVE_POSIX_MEMALIGN) && !(defined(XFree86LOADER) && defined(IN_MODULE))
+#if defined(HAVE_POSIX_MEMALIGN)
void *mem;
(void) posix_memalign(& mem, alignment, bytes);
@@ -157,7 +133,7 @@ _mesa_align_malloc(size_t bytes, unsigned long alignment)
#endif
return (void *) buf;
-#endif /* defined(HAVE_POSIX_MEMALIGN) && !(defined(XFree86LOADER) && defined(IN_MODULE)) */
+#endif /* defined(HAVE_POSIX_MEMALIGN) */
}
/**
@@ -167,7 +143,7 @@ _mesa_align_malloc(size_t bytes, unsigned long alignment)
void *
_mesa_align_calloc(size_t bytes, unsigned long alignment)
{
-#if defined(HAVE_POSIX_MEMALIGN) && !(defined(XFree86LOADER) && defined(IN_MODULE))
+#if defined(HAVE_POSIX_MEMALIGN)
void *mem;
mem = _mesa_align_malloc(bytes, alignment);
@@ -197,7 +173,7 @@ _mesa_align_calloc(size_t bytes, unsigned long alignment)
#endif
return (void *)buf;
-#endif /* defined(HAVE_POSIX_MEMALIGN) && !(defined(XFree86LOADER) && defined(IN_MODULE)) */
+#endif /* defined(HAVE_POSIX_MEMALIGN) */
}
/**
@@ -210,13 +186,13 @@ _mesa_align_calloc(size_t bytes, unsigned long alignment)
void
_mesa_align_free(void *ptr)
{
-#if defined(HAVE_POSIX_MEMALIGN) && !(defined(XFree86LOADER) && defined(IN_MODULE))
+#if defined(HAVE_POSIX_MEMALIGN)
free(ptr);
#else
void **cubbyHole = (void **) ((char *) ptr - sizeof(void *));
void *realAddr = *cubbyHole;
_mesa_free(realAddr);
-#endif /* defined(HAVE_POSIX_MEMALIGN) && !(defined(XFree86LOADER) && defined(IN_MODULE)) */
+#endif /* defined(HAVE_POSIX_MEMALIGN) */
}
/**
@@ -255,22 +231,18 @@ _mesa_realloc(void *oldBuffer, size_t oldSize, size_t newSize)
void *
_mesa_memcpy(void *dest, const void *src, size_t n)
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86memcpy(dest, src, n);
-#elif defined(SUNOS4)
+#if defined(SUNOS4)
return memcpy((char *) dest, (char *) src, (int) n);
#else
return memcpy(dest, src, n);
#endif
}
-/** Wrapper around either memset() or xf86memset() */
+/** Wrapper around memset() */
void
_mesa_memset( void *dst, int val, size_t n )
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- xf86memset( dst, val, n );
-#elif defined(SUNOS4)
+#if defined(SUNOS4)
memset( (char *) dst, (int) val, (int) n );
#else
memset(dst, val, n);
@@ -290,26 +262,22 @@ _mesa_memset16( unsigned short *dst, unsigned short val, size_t n )
*dst++ = val;
}
-/** Wrapper around either memcpy() or xf86memcpy() or bzero() */
+/** Wrapper around either memcpy() or bzero() */
void
_mesa_bzero( void *dst, size_t n )
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- xf86memset( dst, 0, n );
-#elif defined(__FreeBSD__)
+#if defined(__FreeBSD__)
bzero( dst, n );
#else
memset( dst, 0, n );
#endif
}
-/** Wrapper around either memcmp() or xf86memcmp() */
+/** Wrapper around memcmp() */
int
_mesa_memcmp( const void *s1, const void *s2, size_t n )
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86memcmp( s1, s2, n );
-#elif defined(SUNOS4)
+#if defined(SUNOS4)
return memcmp( (char *) s1, (char *) s2, (int) n );
#else
return memcmp(s1, s2, n);
@@ -323,70 +291,46 @@ _mesa_memcmp( const void *s1, const void *s2, size_t n )
/** \name Math */
/*@{*/
-/** Wrapper around either sin() or xf86sin() */
+/** Wrapper around sin() */
double
_mesa_sin(double a)
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86sin(a);
-#else
return sin(a);
-#endif
}
-/** Single precision wrapper around either sin() or xf86sin() */
+/** Single precision wrapper around sin() */
float
_mesa_sinf(float a)
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return (float) xf86sin((double) a);
-#else
return (float) sin((double) a);
-#endif
}
-/** Wrapper around either cos() or xf86cos() */
+/** Wrapper around cos() */
double
_mesa_cos(double a)
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86cos(a);
-#else
return cos(a);
-#endif
}
-/** Single precision wrapper around either asin() or xf86asin() */
+/** Single precision wrapper around asin() */
float
_mesa_asinf(float x)
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return (float) xf86asin((double) x);
-#else
return (float) asin((double) x);
-#endif
}
-/** Single precision wrapper around either atan() or xf86atan() */
+/** Single precision wrapper around atan() */
float
_mesa_atanf(float x)
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return (float) xf86atan((double) x);
-#else
return (float) atan((double) x);
-#endif
}
-/** Wrapper around either sqrt() or xf86sqrt() */
+/** Wrapper around sqrt() */
double
_mesa_sqrtd(double x)
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86sqrt(x);
-#else
return sqrt(x);
-#endif
}
@@ -584,25 +528,17 @@ _mesa_inv_sqrtf(float n)
return x3 * r3;
#endif
-#elif defined(XFree86LOADER) && defined(IN_MODULE)
- return 1.0F / xf86sqrt(n);
#else
return (float) (1.0 / sqrt(n));
#endif
}
-/**
- * Wrapper around either pow() or xf86pow().
- */
+/** Wrapper around pow() */
double
_mesa_pow(double x, double y)
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86pow(x, y);
-#else
return pow(x, y);
-#endif
}
@@ -633,8 +569,6 @@ _mesa_ffs(int i)
}
}
return bit;
-#elif defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86ffs(i);
#else
return ffs(i);
#endif
@@ -642,6 +576,35 @@ _mesa_ffs(int i)
/**
+ * Find position of first bit set in given value.
+ * XXX Warning: this function can only be used on 64-bit systems!
+ * \return position of least-significant bit set, starting at 1, return zero
+ * if no bits set.
+ */
+int
+_mesa_ffsll(long long val)
+{
+#ifdef ffsll
+ return ffsll(val);
+#else
+ int bit;
+
+ assert(sizeof(val) == 8);
+
+ bit = ffs(val);
+ if (bit != 0)
+ return bit;
+
+ bit = ffs(val >> 32);
+ if (bit != 0)
+ return 32 + bit;
+
+ return 0;
+#endif
+}
+
+
+/**
* Return number of bits set in given GLuint.
*/
unsigned int
@@ -807,11 +770,7 @@ void *
_mesa_bsearch( const void *key, const void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *) )
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86bsearch(key, base, nmemb, size, compar);
-#else
return bsearch(key, base, nmemb, size, compar);
-#endif
}
/*@}*/
@@ -827,9 +786,7 @@ _mesa_bsearch( const void *key, const void *base, size_t nmemb, size_t size,
char *
_mesa_getenv( const char *var )
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86getenv(var);
-#elif defined(_XBOX)
+#if defined(_XBOX)
return NULL;
#else
return getenv(var);
@@ -843,81 +800,53 @@ _mesa_getenv( const char *var )
/** \name String */
/*@{*/
-/** Wrapper around either strstr() or xf86strstr() */
+/** Wrapper around strstr() */
char *
_mesa_strstr( const char *haystack, const char *needle )
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86strstr(haystack, needle);
-#else
return strstr(haystack, needle);
-#endif
}
-/** Wrapper around either strncat() or xf86strncat() */
+/** Wrapper around strncat() */
char *
_mesa_strncat( char *dest, const char *src, size_t n )
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86strncat(dest, src, n);
-#else
return strncat(dest, src, n);
-#endif
}
-/** Wrapper around either strcpy() or xf86strcpy() */
+/** Wrapper around strcpy() */
char *
_mesa_strcpy( char *dest, const char *src )
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86strcpy(dest, src);
-#else
return strcpy(dest, src);
-#endif
}
-/** Wrapper around either strncpy() or xf86strncpy() */
+/** Wrapper around strncpy() */
char *
_mesa_strncpy( char *dest, const char *src, size_t n )
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86strncpy(dest, src, n);
-#else
return strncpy(dest, src, n);
-#endif
}
-/** Wrapper around either strlen() or xf86strlen() */
+/** Wrapper around strlen() */
size_t
_mesa_strlen( const char *s )
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86strlen(s);
-#else
return strlen(s);
-#endif
}
-/** Wrapper around either strcmp() or xf86strcmp() */
+/** Wrapper around strcmp() */
int
_mesa_strcmp( const char *s1, const char *s2 )
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86strcmp(s1, s2);
-#else
return strcmp(s1, s2);
-#endif
}
-/** Wrapper around either strncmp() or xf86strncmp() */
+/** Wrapper around strncmp() */
int
_mesa_strncmp( const char *s1, const char *s2, size_t n )
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86strncmp(s1, s2, n);
-#else
return strncmp(s1, s2, n);
-#endif
}
/**
@@ -939,26 +868,18 @@ _mesa_strdup( const char *s )
}
}
-/** Wrapper around either atoi() or xf86atoi() */
+/** Wrapper around atoi() */
int
_mesa_atoi(const char *s)
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86atoi(s);
-#else
return atoi(s);
-#endif
}
-/** Wrapper around either strtod() or xf86strtod() */
+/** Wrapper around strtod() */
double
_mesa_strtod( const char *s, char **end )
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86strtod(s, end);
-#else
return strtod(s, end);
-#endif
}
/*@}*/
@@ -968,24 +889,19 @@ _mesa_strtod( const char *s, char **end )
/** \name I/O */
/*@{*/
-/** Wrapper around either vsprintf() or xf86vsprintf() */
+/** Wrapper around vsprintf() */
int
_mesa_sprintf( char *str, const char *fmt, ... )
{
int r;
va_list args;
va_start( args, fmt );
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- r = xf86vsprintf( str, fmt, args );
-#else
r = vsprintf( str, fmt, args );
-#endif
va_end( args );
return r;
}
-/** Wrapper around either printf() or xf86printf(), using vsprintf() for
- * the formatting. */
+/** Wrapper around printf(), using vsprintf() for the formatting. */
void
_mesa_printf( const char *fmtString, ... )
{
@@ -994,22 +910,14 @@ _mesa_printf( const char *fmtString, ... )
va_start( args, fmtString );
vsnprintf(s, MAXSTRING, fmtString, args);
va_end( args );
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- xf86printf("%s", s);
-#else
fprintf(stderr,"%s", s);
-#endif
}
-/** Wrapper around either vsprintf() or xf86vsprintf() */
+/** Wrapper around vsprintf() */
int
_mesa_vsprintf( char *str, const char *fmt, va_list args )
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86vsprintf( str, fmt, args );
-#else
return vsprintf( str, fmt, args );
-#endif
}
/*@}*/
@@ -1027,7 +935,7 @@ _mesa_vsprintf( char *str, const char *fmt, va_list args )
*
* If debugging is enabled (either at compile-time via the DEBUG macro, or
* run-time via the MESA_DEBUG environment variable), prints the warning to
- * stderr, either via fprintf() or xf86printf().
+ * stderr via fprintf().
*/
void
_mesa_warning( GLcontext *ctx, const char *fmtString, ... )
@@ -1045,11 +953,7 @@ _mesa_warning( GLcontext *ctx, const char *fmtString, ... )
debug = _mesa_getenv("MESA_DEBUG") ? GL_TRUE : GL_FALSE;
#endif
if (debug) {
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- xf86fprintf(stderr, "Mesa warning: %s\n", str);
-#else
fprintf(stderr, "Mesa warning: %s\n", str);
-#endif
}
}
@@ -1060,7 +964,7 @@ _mesa_warning( GLcontext *ctx, const char *fmtString, ... )
* \param ctx GL context.
* \param s problem description string.
*
- * Prints the message to stderr, either via fprintf() or xf86fprintf().
+ * Prints the message to stderr via fprintf().
*/
void
_mesa_problem( const GLcontext *ctx, const char *fmtString, ... )
@@ -1073,13 +977,8 @@ _mesa_problem( const GLcontext *ctx, const char *fmtString, ... )
vsnprintf( str, MAXSTRING, fmtString, args );
va_end( args );
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- xf86fprintf(stderr, "Mesa %s implementation error: %s\n", MESA_VERSION_STRING, str);
- xf86fprintf(stderr, "Please report at bugzilla.freedesktop.org\n");
-#else
fprintf(stderr, "Mesa %s implementation error: %s\n", MESA_VERSION_STRING, str);
fprintf(stderr, "Please report at bugzilla.freedesktop.org\n");
-#endif
}
/**
@@ -1169,7 +1068,7 @@ _mesa_error( GLcontext *ctx, GLenum error, const char *fmtString, ... )
* \param ctx GL context.
* \param fmtString printf() alike format string.
*
- * Prints the message to stderr, either via fprintf() or xf86printf().
+ * Prints the message to stderr via fprintf().
*/
void
_mesa_debug( const GLcontext *ctx, const char *fmtString, ... )
@@ -1180,11 +1079,7 @@ _mesa_debug( const GLcontext *ctx, const char *fmtString, ... )
va_start(args, fmtString);
vsnprintf(s, MAXSTRING, fmtString, args);
va_end(args);
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- xf86fprintf(stderr, "Mesa: %s", s);
-#else
fprintf(stderr, "Mesa: %s", s);
-#endif
#endif /* DEBUG */
(void) ctx;
(void) fmtString;
@@ -1203,11 +1098,7 @@ _mesa_debug( const GLcontext *ctx, const char *fmtString, ... )
void
_mesa_exit( int status )
{
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- xf86exit(status);
-#else
exit(status);
-#endif
}
/*@}*/
@@ -1233,16 +1124,12 @@ default_calloc(__GLcontext *gc, size_t numElem, size_t elemSize)
return _mesa_calloc(numElem * elemSize);
}
-/** Wrapper around either realloc() or xf86realloc() */
+/** Wrapper around realloc() */
static void *
default_realloc(__GLcontext *gc, void *oldAddr, size_t newSize)
{
(void) gc;
-#if defined(XFree86LOADER) && defined(IN_MODULE)
- return xf86realloc(oldAddr, newSize);
-#else
return realloc(oldAddr, newSize);
-#endif
}
/** Wrapper around _mesa_free() */
@@ -1326,16 +1213,6 @@ default_fprintf(__GLcontext *gc, void *stream, const char *fmt, ...)
return r;
}
-/**
- * \todo this really is driver-specific and can't be here
- */
-static __GLdrawablePrivate *
-default_GetDrawablePrivate(__GLcontext *gc)
-{
- (void) gc;
- return NULL;
-}
-
/*@}*/
@@ -1372,6 +1249,7 @@ _mesa_init_default_imports(__GLimports *imports, void *driverCtx)
imports->fopen = default_fopen;
imports->fclose = default_fclose;
imports->fprintf = default_fprintf;
- imports->getDrawablePrivate = default_GetDrawablePrivate;
+ imports->getDrawablePrivate = NULL; /* driver-specific */
+ imports->getReadablePrivate = NULL; /* driver-specific */
imports->other = driverCtx;
}