X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fimports.c;h=2d592a68ecb81cd28156d9c0b1e7cc9d2c4797ec;hb=a83c1d61c2919485b1e8ad33fcf658c85b67ba3a;hp=cefbf4d8c98772c1543167e97f1523383bad4733;hpb=772b25e1f366edc857e77b8c1ccdc5297d82cc41;p=mesa.git diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c index cefbf4d8c98..2d592a68ecb 100644 --- a/src/mesa/main/imports.c +++ b/src/mesa/main/imports.c @@ -46,6 +46,7 @@ #include "imports.h" #include "context.h" +#include "mtypes.h" #include "version.h" #ifdef _GNU_SOURCE @@ -56,8 +57,6 @@ #endif -#define MAXSTRING 4000 /* for vsnprintf() */ - #ifdef WIN32 #define vsnprintf _vsnprintf #elif defined(__IBMC__) || defined(__IBMCPP__) || ( defined(__VMS) && __CRTL_VER < 70312000 ) @@ -452,13 +451,13 @@ _mesa_inv_sqrtf(float n) #endif } +#ifndef __GNUC__ /** * Find the first bit set in a word. */ int -_mesa_ffs(int32_t i) +ffs(int i) { -#if (defined(_WIN32) ) || defined(__IBMC__) || defined(__IBMCPP__) register int bit = 0; if (i != 0) { if ((i & 0xffff) == 0) { @@ -480,9 +479,6 @@ _mesa_ffs(int32_t i) bit++; } return bit; -#else - return ffs(i); -#endif } @@ -493,46 +489,54 @@ _mesa_ffs(int32_t i) * if no bits set. */ int -_mesa_ffsll(int64_t val) +ffsll(long long int val) { -#ifdef ffsll - return ffsll(val); -#else int bit; assert(sizeof(val) == 8); - bit = _mesa_ffs((int32_t)val); + bit = ffs((int) val); if (bit != 0) return bit; - bit = _mesa_ffs((int32_t)(val >> 32)); + bit = ffs((int) (val >> 32)); if (bit != 0) return 32 + bit; return 0; -#endif } +#endif /* __GNUC__ */ +#if !defined(__GNUC__) ||\ + ((__GNUC__ * 100 + __GNUC_MINOR__) < 304) /* Not gcc 3.4 or later */ /** * Return number of bits set in given GLuint. */ unsigned int _mesa_bitcount(unsigned int n) { -#if defined(__GNUC__) && \ - ((_GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4) - return __builtin_popcount(n); -#else unsigned int bits; for (bits = 0; n > 0; n = n >> 1) { bits += (n & 1); } return bits; -#endif } +/** + * Return number of bits set in given 64-bit uint. + */ +unsigned int +_mesa_bitcount_64(uint64_t n) +{ + unsigned int bits; + for (bits = 0; n > 0; n = n >> 1) { + bits += (n & 1); + } + return bits; +} +#endif + /** * Convert a 4-byte float to a 2-byte half float. @@ -757,7 +761,8 @@ _mesa_strdup( const char *s ) float _mesa_strtof( const char *s, char **end ) { -#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__) +#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__) && \ + !defined(ANDROID) && !defined(__HAIKU__) static locale_t loc = NULL; if (!loc) { loc = newlocale(LC_CTYPE_MASK, "C", NULL); @@ -787,6 +792,13 @@ _mesa_str_checksum(const char *str) /*@}*/ +/** Needed due to #ifdef's, above. */ +int +_mesa_vsnprintf(char *str, size_t size, const char *fmt, va_list args) +{ + return vsnprintf( str, size, fmt, args); +} + /** Wrapper around vsnprintf() */ int _mesa_snprintf( char *str, size_t size, const char *fmt, ... ) @@ -800,233 +812,3 @@ _mesa_snprintf( char *str, size_t size, const char *fmt, ... ) } -/**********************************************************************/ -/** \name Diagnostics */ -/*@{*/ - -static void -output_if_debug(const char *prefixString, const char *outputString, - GLboolean newline) -{ - static int debug = -1; - - /* Check the MESA_DEBUG environment variable if it hasn't - * been checked yet. We only have to check it once... - */ - if (debug == -1) { - char *env = _mesa_getenv("MESA_DEBUG"); - - /* In a debug build, we print warning messages *unless* - * MESA_DEBUG is 0. In a non-debug build, we don't - * print warning messages *unless* MESA_DEBUG is - * set *to any value*. - */ -#ifdef DEBUG - debug = (env != NULL && atoi(env) == 0) ? 0 : 1; -#else - debug = (env != NULL) ? 1 : 0; -#endif - } - - /* Now only print the string if we're required to do so. */ - if (debug) { - fprintf(stderr, "%s: %s", prefixString, outputString); - if (newline) - fprintf(stderr, "\n"); - -#if defined(_WIN32) && !defined(_WIN32_WCE) - /* stderr from windows applications without console is not usually - * visible, so communicate with the debugger instead */ - { - char buf[4096]; - _mesa_snprintf(buf, sizeof(buf), "%s: %s%s", prefixString, outputString, newline ? "\n" : ""); - OutputDebugStringA(buf); - } -#endif - } -} - - -/** - * Return string version of GL error code. - */ -static const char * -error_string( GLenum error ) -{ - switch (error) { - case GL_NO_ERROR: - return "GL_NO_ERROR"; - case GL_INVALID_VALUE: - return "GL_INVALID_VALUE"; - case GL_INVALID_ENUM: - return "GL_INVALID_ENUM"; - case GL_INVALID_OPERATION: - return "GL_INVALID_OPERATION"; - case GL_STACK_OVERFLOW: - return "GL_STACK_OVERFLOW"; - case GL_STACK_UNDERFLOW: - return "GL_STACK_UNDERFLOW"; - case GL_OUT_OF_MEMORY: - return "GL_OUT_OF_MEMORY"; - case GL_TABLE_TOO_LARGE: - return "GL_TABLE_TOO_LARGE"; - case GL_INVALID_FRAMEBUFFER_OPERATION_EXT: - return "GL_INVALID_FRAMEBUFFER_OPERATION"; - default: - return "unknown"; - } -} - - -/** - * When a new type of error is recorded, print a message describing - * previous errors which were accumulated. - */ -static void -flush_delayed_errors( struct gl_context *ctx ) -{ - char s[MAXSTRING]; - - if (ctx->ErrorDebugCount) { - _mesa_snprintf(s, MAXSTRING, "%d similar %s errors", - ctx->ErrorDebugCount, - error_string(ctx->ErrorValue)); - - output_if_debug("Mesa", s, GL_TRUE); - - ctx->ErrorDebugCount = 0; - } -} - - -/** - * Report a warning (a recoverable error condition) to stderr if - * either DEBUG is defined or the MESA_DEBUG env var is set. - * - * \param ctx GL context. - * \param fmtString printf()-like format string. - */ -void -_mesa_warning( struct gl_context *ctx, const char *fmtString, ... ) -{ - char str[MAXSTRING]; - va_list args; - va_start( args, fmtString ); - (void) vsnprintf( str, MAXSTRING, fmtString, args ); - va_end( args ); - - if (ctx) - flush_delayed_errors( ctx ); - - output_if_debug("Mesa warning", str, GL_TRUE); -} - - -/** - * Report an internal implementation problem. - * Prints the message to stderr via fprintf(). - * - * \param ctx GL context. - * \param fmtString problem description string. - */ -void -_mesa_problem( const struct gl_context *ctx, const char *fmtString, ... ) -{ - va_list args; - char str[MAXSTRING]; - (void) ctx; - - va_start( args, fmtString ); - vsnprintf( str, MAXSTRING, fmtString, args ); - va_end( args ); - - fprintf(stderr, "Mesa %s implementation error: %s\n", MESA_VERSION_STRING, str); - fprintf(stderr, "Please report at bugzilla.freedesktop.org\n"); -} - - -/** - * Record an OpenGL state error. These usually occur when the user - * passes invalid parameters to a GL function. - * - * If debugging is enabled (either at compile-time via the DEBUG macro, or - * run-time via the MESA_DEBUG environment variable), report the error with - * _mesa_debug(). - * - * \param ctx the GL context. - * \param error the error value. - * \param fmtString printf() style format string, followed by optional args - */ -void -_mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... ) -{ - static GLint debug = -1; - - /* Check debug environment variable only once: - */ - if (debug == -1) { - const char *debugEnv = _mesa_getenv("MESA_DEBUG"); - -#ifdef DEBUG - if (debugEnv && strstr(debugEnv, "silent")) - debug = GL_FALSE; - else - debug = GL_TRUE; -#else - if (debugEnv) - debug = GL_TRUE; - else - debug = GL_FALSE; -#endif - } - - if (debug) { - if (ctx->ErrorValue == error && - ctx->ErrorDebugFmtString == fmtString) { - ctx->ErrorDebugCount++; - } - else { - char s[MAXSTRING], s2[MAXSTRING]; - va_list args; - - flush_delayed_errors( ctx ); - - va_start(args, fmtString); - vsnprintf(s, MAXSTRING, fmtString, args); - va_end(args); - - _mesa_snprintf(s2, MAXSTRING, "%s in %s", error_string(error), s); - output_if_debug("Mesa: User error", s2, GL_TRUE); - - ctx->ErrorDebugFmtString = fmtString; - ctx->ErrorDebugCount = 0; - } - } - - _mesa_record_error(ctx, error); -} - - -/** - * Report debug information. Print error message to stderr via fprintf(). - * No-op if DEBUG mode not enabled. - * - * \param ctx GL context. - * \param fmtString printf()-style format string, followed by optional args. - */ -void -_mesa_debug( const struct gl_context *ctx, const char *fmtString, ... ) -{ -#ifdef DEBUG - char s[MAXSTRING]; - va_list args; - va_start(args, fmtString); - vsnprintf(s, MAXSTRING, fmtString, args); - va_end(args); - output_if_debug("Mesa", s, GL_FALSE); -#endif /* DEBUG */ - (void) ctx; - (void) fmtString; -} - -/*@}*/