**************************************************************************/
+#include "pipe/p_config.h"
+
#include <stdarg.h>
-#ifdef WIN32
+#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
#include <windows.h>
#include <winddi.h>
#else
#include "pipe/p_compiler.h"
#include "pipe/p_util.h"
#include "pipe/p_debug.h"
+#include "pipe/p_format.h"
+#include "util/u_string.h"
-#ifdef WIN32
+#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
static INLINE void
-rpl_EngDebugPrint(const char *format, ...)
+_EngDebugPrint(const char *format, ...)
{
va_list ap;
va_start(ap, format);
EngDebugPrint("", (PCHAR)format, ap);
va_end(ap);
}
-
-int rpl_vsnprintf(char *, size_t, const char *, va_list);
-int rpl_snprintf(char *str, size_t size, const char *format, ...);
-#define vsnprintf rpl_vsnprintf
-#define snprintf rpl_snprintf
#endif
void _debug_vprintf(const char *format, va_list ap)
{
-#ifdef WIN32
+#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
#ifndef WINCE
/* EngDebugPrint does not handle float point arguments, so we need to use
- * our own vsnprintf implementation */
- char buf[512 + 1];
- rpl_vsnprintf(buf, sizeof(buf), format, ap);
- rpl_EngDebugPrint("%s", buf);
+ * our own vsnprintf implementation. It is also very slow, so buffer until
+ * we find a newline. */
+ static char buf[512 + 1] = {'\0'};
+ size_t len = strlen(buf);
+ int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap);
+ if(ret > (int)(sizeof(buf) - len - 1) || strchr(buf + len, '\n')) {
+ _EngDebugPrint("%s", buf);
+ buf[0] = '\0';
+ }
#else
/* TODO: Implement debug print for WINCE */
#endif
__asm("int3");
#elif (defined(__i386__) || defined(__386__)) && defined(__MSC__)
_asm {int 3};
-#elif defined(WIN32) && !defined(WINCE)
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
EngDebugBreak();
#else
abort();
}
-#ifdef WIN32
+#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
static const char *
find(const char *start, const char *end, char c)
{
debug_get_option(const char *name, const char *dfault)
{
const char *result;
-#ifdef WIN32
+#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
ULONG_PTR iFile = 0;
const void *pMap = NULL;
const char *sol, *eol, *sep;
static char output[1024];
+ result = dfault;
+ /* XXX: this creates the file if it does not exists, so it must either be
+ * disabled on release versions, or put in a less conspicuous place.
+ */
pMap = EngMapFile(L"\\??\\c:\\gallium.cfg", 0, &iFile);
- if(!pMap)
- result = dfault;
- else {
+ if(pMap) {
sol = (const char *)pMap;
while(1) {
/* TODO: handle LF line endings */
result = dfault;
#endif
- if(result)
- debug_printf("%s: %s = %s\n", __FUNCTION__, name, result);
- else
- debug_printf("%s: %s = (null)\n", __FUNCTION__, name);
+ debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? result : "(null)");
return result;
}
if(str == NULL)
result = dfault;
+ else if(!strcmp(str, "n"))
+ result = FALSE;
else if(!strcmp(str, "no"))
result = FALSE;
else if(!strcmp(str, "0"))
}
-#if defined(WIN32)
-ULONG_PTR debug_config_file = 0;
-void *mapped_config_file = 0;
-
-enum {
- eAssertAbortEn = 0x1,
-};
-
-/* Check for aborts enabled. */
-static unsigned abort_en(void)
-{
- if (!mapped_config_file)
- {
- /* Open an 8 byte file for configuration data. */
- mapped_config_file = EngMapFile(L"\\??\\c:\\gaDebug.cfg", 8, &debug_config_file);
- }
-
- /* A value of "0" (ascii) in the configuration file will clear the
- * first 8 bits in the test byte.
- *
- * A value of "1" (ascii) in the configuration file will set the
- * first bit in the test byte.
- *
- * A value of "2" (ascii) in the configuration file will set the
- * second bit in the test byte.
- *
- * Currently the only interesting values are 0 and 1, which clear
- * and set abort-on-assert behaviour respectively.
- */
- return ((((char *)mapped_config_file)[0]) - 0x30) & eAssertAbortEn;
-}
-#else /* WIN32 */
-static unsigned abort_en(void)
-{
- return !GETENV("GALLIUM_ABORT_ON_ASSERT");
-}
-#endif
-
void _debug_assert_fail(const char *expr,
const char *file,
unsigned line,
const char *function)
{
_debug_printf("%s:%u:%s: Assertion `%s' failed.\n", file, line, function, expr);
- if (abort_en())
- {
+ if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", TRUE))
debug_break();
- } else
- {
+ else
_debug_printf("continuing...\n");
- }
}
++names;
}
- snprintf(rest, sizeof(rest), "0x%08lx", value);
+ util_snprintf(rest, sizeof(rest), "0x%08lx", value);
return rest;
}
else
first = 0;
- snprintf(rest, sizeof(rest), "0x%08lx", value);
+ util_snprintf(rest, sizeof(rest), "0x%08lx", value);
strncat(output, rest, sizeof(output));
}
}
+
+
+
+
+char *pf_sprint_name( char *str, enum pipe_format format )
+{
+ strcpy( str, "PIPE_FORMAT_" );
+ switch (pf_layout( format )) {
+ case PIPE_FORMAT_LAYOUT_RGBAZS:
+ {
+ pipe_format_rgbazs_t rgbazs = (pipe_format_rgbazs_t) format;
+ uint i;
+ uint scale = 1 << (pf_exp8( rgbazs ) * 3);
+
+ for (i = 0; i < 4; i++) {
+ uint size = pf_size_xyzw( rgbazs, i );
+
+ if (size == 0) {
+ break;
+ }
+ switch (pf_swizzle_xyzw( rgbazs, i )) {
+ case PIPE_FORMAT_COMP_R:
+ strcat( str, "R" );
+ break;
+ case PIPE_FORMAT_COMP_G:
+ strcat( str, "G" );
+ break;
+ case PIPE_FORMAT_COMP_B:
+ strcat( str, "B" );
+ break;
+ case PIPE_FORMAT_COMP_A:
+ strcat( str, "A" );
+ break;
+ case PIPE_FORMAT_COMP_0:
+ strcat( str, "0" );
+ break;
+ case PIPE_FORMAT_COMP_1:
+ strcat( str, "1" );
+ break;
+ case PIPE_FORMAT_COMP_Z:
+ strcat( str, "Z" );
+ break;
+ case PIPE_FORMAT_COMP_S:
+ strcat( str, "S" );
+ break;
+ }
+ util_snprintf( &str[strlen( str )], 32, "%u", size * scale );
+ }
+ if (i != 0) {
+ strcat( str, "_" );
+ }
+ switch (pf_type( rgbazs )) {
+ case PIPE_FORMAT_TYPE_UNKNOWN:
+ strcat( str, "NONE" );
+ break;
+ case PIPE_FORMAT_TYPE_FLOAT:
+ strcat( str, "FLOAT" );
+ break;
+ case PIPE_FORMAT_TYPE_UNORM:
+ strcat( str, "UNORM" );
+ break;
+ case PIPE_FORMAT_TYPE_SNORM:
+ strcat( str, "SNORM" );
+ break;
+ case PIPE_FORMAT_TYPE_USCALED:
+ strcat( str, "USCALED" );
+ break;
+ case PIPE_FORMAT_TYPE_SSCALED:
+ strcat( str, "SSCALED" );
+ break;
+ }
+ }
+ break;
+ case PIPE_FORMAT_LAYOUT_YCBCR:
+ {
+ pipe_format_ycbcr_t ycbcr = (pipe_format_ycbcr_t) format;
+
+ strcat( str, "YCBCR" );
+ if (pf_rev( ycbcr )) {
+ strcat( str, "_REV" );
+ }
+ }
+ break;
+ }
+ return str;
+}
+
+
+#ifdef DEBUG
+void debug_print_format(const char *msg, unsigned fmt )
+{
+ char fmtstr[80];
+
+ pf_sprint_name(fmtstr, (enum pipe_format)fmt);
+
+ debug_printf("%s: %s\n", msg, fmtstr);
+}
+#endif